Chromium Code Reviews| Index: pkg/docgen/lib/docgen.dart |
| diff --git a/pkg/docgen/lib/docgen.dart b/pkg/docgen/lib/docgen.dart |
| index 49d659bf06488434e3a0ea94ada16df71200d2c7..96f902790eabf74ec8b79a96510bb9619cf55629 100644 |
| --- a/pkg/docgen/lib/docgen.dart |
| +++ b/pkg/docgen/lib/docgen.dart |
| @@ -13,6 +13,7 @@ |
| * This creates files called `docs/<library_name>.yaml` in your current |
| * working directory. |
| */ |
| + |
|
Andrei Mouravski
2013/06/25 18:37:41
You don't need this newline.
janicejl
2013/06/25 19:47:49
Done.
|
| library docgen; |
| import 'dart:io'; |
| @@ -22,8 +23,10 @@ import 'dart:async'; |
| import 'package:args/args.dart'; |
| import 'package:logging/logging.dart'; |
| import 'package:markdown/markdown.dart' as markdown; |
| +import 'package:pathos/path.dart' as path; |
| import 'dart2yaml.dart'; |
| +import 'io.dart'; |
| import '../../../sdk/lib/_internal/compiler/compiler.dart' as api; |
| import '../../../sdk/lib/_internal/compiler/implementation/filenames.dart'; |
| import '../../../sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirror.dart' |
| @@ -41,40 +44,6 @@ int get nextID => _nextID++; |
| const String usage = "Usage: dart docgen.dart [OPTIONS] [fooDir/barFile]"; |
| -List<Path> listLibraries(List<String> args) { |
| - if (args.length != 1) { |
| - throw new UnsupportedError(usage); |
| - } |
| - var libraries = new List<Path>(); |
| - var type = FileSystemEntity.typeSync(args[0]); |
| - |
| - if (type == FileSystemEntityType.NOT_FOUND) { |
| - throw new UnsupportedError("File does not exist. $usage"); |
| - } else if (type == FileSystemEntityType.LINK) { |
| - libraries.addAll(listLibrariesFromDir(new Link(args[0]).targetSync())); |
| - } else if (type == FileSystemEntityType.FILE) { |
| - libraries.add(new Path(args[0])); |
| - logger.info("Added to libraries: ${libraries.last.toString()}"); |
| - } else if (type == FileSystemEntityType.DIRECTORY) { |
| - libraries.addAll(listLibrariesFromDir(args[0])); |
| - } |
| - return libraries; |
| -} |
| - |
| -List<Path> listLibrariesFromDir(String path) { |
| - var libraries = new List<Path>(); |
| - new Directory(path).listSync(recursive: true, |
| - followLinks: true).forEach((file) { |
| - if (new Path(file.path).extension == "dart") { |
| - if (!file.path.contains("/packages/")) { |
| - libraries.add(new Path(file.path)); |
| - logger.info("Added to libraries: ${libraries.last.toString()}"); |
| - } |
| - } |
| - }); |
| - return libraries; |
| -} |
| - |
| /** |
| * This class documents a list of libraries. |
| */ |
| @@ -82,7 +51,7 @@ class Docgen { |
| /// Libraries to be documented. |
| List<LibraryMirror> _libraries; |
| - |
| + |
| /// Current library being documented to be used for comment links. |
| LibraryMirror _currentLibrary; |
| @@ -95,6 +64,9 @@ class Docgen { |
| /// Resolves reference links |
| markdown.Resolver linkResolver; |
| + /// Package Directory of |
| + String packageDir; |
| + |
| bool outputToYaml; |
| bool outputToJson; |
| bool includePrivate; |
| @@ -125,30 +97,64 @@ class Docgen { |
| this.linkResolver = (name) => |
| fixReference(name, _currentLibrary, _currentClass, _currentMember); |
| + |
| + analyze(argResults.rest); |
| + } |
| + |
| + List<String> listLibraries(List<String> args) { |
| + if (args.length != 1) { |
| + throw new UnsupportedError(usage); |
| + } |
| + var libraries = new List<String>(); |
| + var type = FileSystemEntity.typeSync(args[0]); |
| + |
| + if (type == FileSystemEntityType.NOT_FOUND) { |
| + throw new UnsupportedError("File does not exist. $usage"); |
| + } else if (type == FileSystemEntityType.LINK) { |
| + var files = listDir(resolveLink(args[0]), recursive: true); |
| + libraries.addAll(files.where((f) => |
| + f.endsWith(".dart") && !f.contains("/packages"))); |
| + packageDir = files.firstWhere((f) => |
| + f.endsWith("/pubspec.yaml"), orElse: () => ""); |
| + packageDir = packageDir == "" ? |
| + "" : path.dirname(packageDir) + "/packages"; |
| + } else if (type == FileSystemEntityType.FILE) { |
| + libraries.add(path.absolute(args[0])); |
| + packageDir = ""; |
| + } else if (type == FileSystemEntityType.DIRECTORY) { |
| + var files = listDir(args[0], recursive: true); |
| + libraries.addAll(files.where((f) => |
| + f.endsWith(".dart") && !f.contains("/packages"))); |
| + packageDir = files.firstWhere((f) => |
| + f.endsWith("/pubspec.yaml"), orElse: () => ""); |
| + packageDir = packageDir == "" ? |
| + "" : path.dirname(packageDir) + "/packages"; |
| + } |
| + logger.info("Package Directory: $packageDir"); |
| + libraries.forEach((lib) => logger.info("Added to libraries: $lib")); |
| + return libraries; |
| } |
| /** |
| * Analyzes set of libraries by getting a mirror system and triggers the |
| * documentation of the libraries. |
| */ |
| - void analyze(List<Path> libraries) { |
| + void analyze(List<String> args) { |
| + var libraries = listLibraries(args); |
| + if (libraries.isEmpty) throw new UnsupportedError("No Libraries. "); |
| // DART_SDK should be set to the root of the SDK library. |
| var sdkRoot = Platform.environment["DART_SDK"]; |
| if (sdkRoot != null) { |
| logger.info("Using DART_SDK to find SDK at $sdkRoot"); |
| - sdkRoot = new Path(sdkRoot); |
| } else { |
| // If DART_SDK is not defined in the environment, |
| // assuming the dart executable is from the Dart SDK folder inside bin. |
| - sdkRoot = new Path(new Options().executable).directoryPath |
| - .directoryPath; |
| - logger.info("SDK Root: ${sdkRoot.toString()}"); |
| + sdkRoot = path.dirname(path.dirname(new Options().executable)); |
| + logger.info("SDK Root: ${sdkRoot}"); |
| } |
| - Path packageDir = libraries.last.directoryPath.append("packages"); |
| - logger.info("Package Root: ${packageDir.toString()}"); |
| - getMirrorSystem(libraries, sdkRoot, |
| - packageRoot: packageDir).then((MirrorSystem mirrorSystem) { |
| + getMirrorSystem(libraries, new Path(sdkRoot), |
| + packageRoot: new Path(packageDir)).then((MirrorSystem mirrorSystem) { |
| if (mirrorSystem.libraries.values.isEmpty) { |
| throw new UnsupportedError("No Library Mirrors."); |
| } |
| @@ -161,7 +167,7 @@ class Docgen { |
| * Analyzes set of libraries and provides a mirror system which can be used |
| * for static inspection of the source code. |
| */ |
| - Future<MirrorSystem> getMirrorSystem(List<Path> libraries, |
| + Future<MirrorSystem> getMirrorSystem(List<String> libraries, |
| Path libraryRoot, {Path packageRoot}) { |
| SourceFileProvider provider = new SourceFileProvider(); |
| api.DiagnosticHandler diagnosticHandler = |
| @@ -173,7 +179,7 @@ class Docgen { |
| } |
| List<Uri> librariesUri = <Uri>[]; |
| libraries.forEach((library) { |
| - librariesUri.add(currentDirectory.resolve(library.toString())); |
| + librariesUri.add(currentDirectory.resolve(library)); |
| }); |
| return dart2js.analyze(librariesUri, libraryUri, packageUri, |
| provider.readStringFromUri, diagnosticHandler, |
| @@ -200,12 +206,12 @@ class Docgen { |
| } |
| }); |
| } |
| - |
| + |
| /// Saves list of libraries for Docgen object. |
| void set libraries(value){ |
| _libraries = value; |
| } |
| - |
| + |
| /** |
| * Returns any documentation comments associated with a mirror with |
| * simple markdown converted to html. |