Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /// **docgen** is a tool for creating machine readable representations of Dart | 5 /// **docgen** is a tool for creating machine readable representations of Dart |
| 6 /// code metadata, including: classes, members, comments and annotations. | 6 /// code metadata, including: classes, members, comments and annotations. |
| 7 /// | 7 /// |
| 8 /// docgen is run on a `.dart` file or a directory containing `.dart` files. | 8 /// docgen is run on a `.dart` file or a directory containing `.dart` files. |
| 9 /// | 9 /// |
| 10 /// $ dart docgen.dart [OPTIONS] [FILE/DIR] | 10 /// $ dart docgen.dart [OPTIONS] [FILE/DIR] |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 """; | 99 """; |
| 100 | 100 |
| 101 /// Docgen constructor initializes the link resolver for markdown parsing. | 101 /// Docgen constructor initializes the link resolver for markdown parsing. |
| 102 /// Also initializes the command line arguments. | 102 /// Also initializes the command line arguments. |
| 103 /// | 103 /// |
| 104 /// [packageRoot] is the packages directory of the directory being analyzed. | 104 /// [packageRoot] is the packages directory of the directory being analyzed. |
| 105 /// If [includeSdk] is `true`, then any SDK libraries explicitly imported will | 105 /// If [includeSdk] is `true`, then any SDK libraries explicitly imported will |
| 106 /// also be documented. | 106 /// also be documented. |
| 107 /// If [parseSdk] is `true`, then all Dart SDK libraries will be documented. | 107 /// If [parseSdk] is `true`, then all Dart SDK libraries will be documented. |
| 108 /// This option is useful when only the SDK libraries are needed. | 108 /// This option is useful when only the SDK libraries are needed. |
| 109 /// If [compile] is `true`, then after generating the documents, compile the | |
| 110 /// viewer with dart2js. | |
| 109 /// If [serve] is `true`, then after generating the documents we fire up a | 111 /// If [serve] is `true`, then after generating the documents we fire up a |
| 110 /// simple server to view the documentation. | 112 /// simple server to view the documentation. |
| 111 /// | 113 /// |
| 112 /// Returned Future completes with true if document generation is successful. | 114 /// Returned Future completes with true if document generation is successful. |
| 113 Future<bool> docgen(List<String> files, {String packageRoot, | 115 Future<bool> docgen(List<String> files, {String packageRoot, |
| 114 bool outputToYaml: true, bool includePrivate: false, bool includeSdk: false, | 116 bool outputToYaml: true, bool includePrivate: false, bool includeSdk: false, |
| 115 bool parseSdk: false, bool append: false, String introFileName: '', | 117 bool parseSdk: false, bool append: false, String introFileName: '', |
| 116 out: _DEFAULT_OUTPUT_DIRECTORY, List<String> excludeLibraries : const [], | 118 out: _DEFAULT_OUTPUT_DIRECTORY, List<String> excludeLibraries : const [], |
| 117 bool includeDependentPackages: false, bool serve: false, | 119 bool includeDependentPackages: false, bool compile: false, bool serve: false , |
| 118 bool noDocs: false, String startPage, | 120 bool noDocs: false, String startPage, |
| 119 String pubScript, String dartBinary}) { | 121 String pubScript, String dartBinary}) { |
| 120 var result; | 122 var result; |
| 121 if (!noDocs) { | 123 if (!noDocs) { |
| 122 _Viewer.ensureMovedViewerCode(); | 124 _Viewer.ensureMovedViewerCode(); |
| 123 result = _Generator.generateDocumentation(files, packageRoot: packageRoot, | 125 result = _Generator.generateDocumentation(files, packageRoot: packageRoot, |
| 124 outputToYaml: outputToYaml, includePrivate: includePrivate, | 126 outputToYaml: outputToYaml, includePrivate: includePrivate, |
| 125 includeSdk: includeSdk, parseSdk: parseSdk, append: append, | 127 includeSdk: includeSdk, parseSdk: parseSdk, append: append, |
| 126 introFileName: introFileName, out: out, | 128 introFileName: introFileName, out: out, |
| 127 excludeLibraries: excludeLibraries, | 129 excludeLibraries: excludeLibraries, |
| 128 includeDependentPackages: includeDependentPackages, | 130 includeDependentPackages: includeDependentPackages, |
| 129 startPage: startPage, pubScript: pubScript, dartBinary: dartBinary); | 131 startPage: startPage, pubScript: pubScript, dartBinary: dartBinary); |
| 130 _Viewer.addBackViewerCode(); | 132 _Viewer.addBackViewerCode(); |
| 131 if (serve) { | 133 if (compile || serve) { |
| 132 result.then((success) { | 134 result.then((success) { |
| 133 if (success) { | 135 if (success) { |
| 134 _Viewer._cloneAndServe(); | 136 _createViewer(serve); |
| 135 } | 137 } |
| 136 }); | 138 }); |
| 137 } | 139 } |
| 138 } else if (serve) { | 140 } else if (compile || serve) { |
| 139 _Viewer._cloneAndServe(); | 141 _createViewer(serve); |
| 140 } | 142 } |
| 141 return result; | 143 return result; |
| 142 } | 144 } |
| 143 | 145 |
| 146 void _createViewer(bool serve) { | |
| 147 _Viewer._clone(); | |
| 148 _Viewer._compile(); | |
| 149 if (serve) { | |
| 150 _Viewer._runServer(); | |
| 151 } | |
| 152 } | |
| 153 | |
| 144 /// Analyzes set of libraries by getting a mirror system and triggers the | 154 /// Analyzes set of libraries by getting a mirror system and triggers the |
| 145 /// documentation of the libraries. | 155 /// documentation of the libraries. |
| 146 Future<MirrorSystem> getMirrorSystem(List<Uri> libraries, | 156 Future<MirrorSystem> getMirrorSystem(List<Uri> libraries, |
| 147 {String packageRoot, bool parseSdk: false}) { | 157 {String packageRoot, bool parseSdk: false}) { |
| 148 if (libraries.isEmpty) throw new StateError('No Libraries.'); | 158 if (libraries.isEmpty) throw new StateError('No Libraries.'); |
| 149 | 159 |
| 150 // Finds the root of SDK library based off the location of docgen. | 160 // Finds the root of SDK library based off the location of docgen. |
| 151 // We have two different places to look, depending if we're in a development | 161 // We have two different places to look, depending if we're in a development |
| 152 // repo or in a built SDK, either sdk or dart-sdk respectively | 162 // repo or in a built SDK, either sdk or dart-sdk respectively |
| 153 var root = _Generator._rootDirectory; | 163 var root = _Generator._rootDirectory; |
| (...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 643 } | 653 } |
| 644 } | 654 } |
| 645 | 655 |
| 646 /// Convenience methods wrapped up in a class to pull down the docgen viewer for | 656 /// Convenience methods wrapped up in a class to pull down the docgen viewer for |
| 647 /// a viewable website, and start up a server for viewing. | 657 /// a viewable website, and start up a server for viewing. |
| 648 class _Viewer { | 658 class _Viewer { |
| 649 static String _dartdocViewerString = path.join(Directory.current.path, | 659 static String _dartdocViewerString = path.join(Directory.current.path, |
| 650 'dartdoc-viewer'); | 660 'dartdoc-viewer'); |
| 651 static Directory _dartdocViewerDir = new Directory(_dartdocViewerString); | 661 static Directory _dartdocViewerDir = new Directory(_dartdocViewerString); |
| 652 static Directory _topLevelTempDir; | 662 static Directory _topLevelTempDir; |
| 663 static Directory _webDocsDir; | |
| 653 static bool movedViewerCode = false; | 664 static bool movedViewerCode = false; |
| 654 | 665 |
| 655 /// If our dartdoc-viewer code is already checked out, move it to a temporary | 666 /// If our dartdoc-viewer code is already checked out, move it to a temporary |
| 656 /// directory outside of the package directory, so we don't try to process it | 667 /// directory outside of the package directory, so we don't try to process it |
| 657 /// for documentation. | 668 /// for documentation. |
| 658 static void ensureMovedViewerCode() { | 669 static void ensureMovedViewerCode() { |
| 659 // TODO(efortuna): This will need to be modified to run on anyone's package | 670 // TODO(efortuna): This will need to be modified to run on anyone's package |
| 660 // outside of the checkout! | 671 // outside of the checkout! |
| 661 if (_dartdocViewerDir.existsSync()) { | 672 if (_dartdocViewerDir.existsSync()) { |
| 662 _topLevelTempDir = new Directory( | 673 _topLevelTempDir = new Directory( |
| 663 _Generator._rootDirectory).createTempSync(); | 674 _Generator._rootDirectory).createTempSync(); |
| 664 _dartdocViewerDir.renameSync(_topLevelTempDir.path); | 675 _dartdocViewerDir.renameSync(_topLevelTempDir.path); |
| 665 } | 676 } |
| 666 } | 677 } |
| 667 | 678 |
| 668 /// Move the dartdoc-viewer code back into place for "webpage deployment." | 679 /// Move the dartdoc-viewer code back into place for "webpage deployment." |
| 669 static void addBackViewerCode() { | 680 static void addBackViewerCode() { |
| 670 if (movedViewerCode) _dartdocViewerDir.renameSync(_dartdocViewerString); | 681 if (movedViewerCode) _dartdocViewerDir.renameSync(_dartdocViewerString); |
| 671 } | 682 } |
| 672 | 683 |
| 673 /// Serve up our generated documentation for viewing in a browser. | 684 /// Serve up our generated documentation for viewing in a browser. |
| 674 static void _cloneAndServe() { | 685 static void _clone() { |
| 675 // If the viewer code is already there, then don't clone again. | 686 // If the viewer code is already there, then don't clone again. |
| 676 if (_dartdocViewerDir.existsSync()) { | 687 if (_dartdocViewerDir.existsSync()) { |
| 677 _moveDirectoryAndServe(); | 688 _moveDirectoryAndServe(); |
| 678 } | 689 } |
| 679 else { | 690 else { |
| 680 var processResult = Process.runSync('git', ['clone', '-b', 'master', | 691 var processResult = Process.runSync('git', ['clone', '-b', 'master', |
| 681 'git://github.com/dart-lang/dartdoc-viewer.git'], | 692 'git://github.com/dart-lang/dartdoc-viewer.git'], |
| 682 runInShell: true); | 693 runInShell: true); |
| 683 | 694 |
| 684 if (processResult.exitCode == 0) { | 695 if (processResult.exitCode == 0) { |
| 685 _moveDirectoryAndServe(); | 696 /// Move the generated json/yaml docs directory to the dartdoc-viewer |
| 697 /// directory, to run as a webpage. | |
| 698 var processResult = Process.runSync(_Generator._pubScript, | |
| 699 ['upgrade'], runInShell: true, | |
| 700 workingDirectory: path.join(_dartdocViewerDir.path, 'client')); | |
| 701 print('process output: ${processResult.stdout}'); | |
| 702 print('process stderr: ${processResult.stderr}'); | |
| 703 | |
| 704 var dir = new Directory(_Generator._outputDirectory == null? 'docs' : | |
| 705 _Generator._outputDirectory); | |
| 706 _webDocsDir = new Directory(path.join(_dartdocViewerDir.path, 'client', | |
| 707 'web', 'docs')); | |
| 708 if (dir.existsSync()) { | |
| 709 // Move the docs folder to dartdoc-viewer/client/web/docs | |
| 710 dir.renameSync(_webDocsDir.path); | |
| 711 } | |
| 686 } else { | 712 } else { |
| 687 print('Error cloning git repository:'); | 713 print('Error cloning git repository:'); |
| 688 print('process output: ${processResult.stdout}'); | 714 print('process output: ${processResult.stdout}'); |
| 689 print('process stderr: ${processResult.stderr}'); | 715 print('process stderr: ${processResult.stderr}'); |
| 690 } | 716 } |
| 691 } | 717 } |
| 692 } | 718 } |
| 693 | 719 |
| 694 /// Move the generated json/yaml docs directory to the dartdoc-viewer | 720 static void _compile() { |
| 695 /// directory, to run as a webpage. | 721 if (_webDocsDir.existsSync()) { |
| 696 static void _moveDirectoryAndServe() { | |
|
kevmoo
2014/02/19 21:57:16
Still being used...
https://code.google.com/p/dar
| |
| 697 var processResult = Process.runSync(_Generator._pubScript, ['upgrade'], | |
| 698 runInShell: true, workingDirectory: path.join(_dartdocViewerDir.path, | |
| 699 'client')); | |
| 700 print('process output: ${processResult.stdout}'); | |
| 701 print('process stderr: ${processResult.stderr}'); | |
| 702 | |
| 703 var dir = new Directory(_Generator._outputDirectory == null? 'docs' : | |
| 704 _Generator._outputDirectory); | |
| 705 var webDocsDir = new Directory(path.join(_dartdocViewerDir.path, 'client', | |
| 706 'web', 'docs')); | |
| 707 if (dir.existsSync()) { | |
| 708 // Move the docs folder to dartdoc-viewer/client/web/docs | |
| 709 dir.renameSync(webDocsDir.path); | |
| 710 } | |
| 711 | |
| 712 if (webDocsDir.existsSync()) { | |
| 713 // Compile the code to JavaScript so we can run on any browser. | 722 // Compile the code to JavaScript so we can run on any browser. |
| 714 print('Compile app to JavaScript for viewing.'); | 723 print('Compile app to JavaScript for viewing.'); |
| 715 var processResult = Process.runSync(_Generator._dartBinary, | 724 var processResult = Process.runSync(_Generator._dartBinary, |
| 716 ['deploy.dart'], workingDirectory : path.join(_dartdocViewerDir.path, | 725 ['deploy.dart'], workingDirectory : path.join(_dartdocViewerDir.path, |
| 717 'client'), runInShell: true); | 726 'client'), runInShell: true); |
| 718 print('process output: ${processResult.stdout}'); | 727 print('process output: ${processResult.stdout}'); |
| 719 print('process stderr: ${processResult.stderr}'); | 728 print('process stderr: ${processResult.stderr}'); |
| 720 _runServer(); | 729 var outputDir = path.join(_dartdocViewerDir.path, 'client', 'out', 'web'); |
| 730 print('Docs are available at $outputDir'); | |
| 721 } | 731 } |
| 722 } | 732 } |
| 723 | 733 |
| 724 /// A simple HTTP server. Implemented here because this is part of the SDK, | 734 /// A simple HTTP server. Implemented here because this is part of the SDK, |
| 725 /// so it shouldn't have any external dependencies. | 735 /// so it shouldn't have any external dependencies. |
| 726 static void _runServer() { | 736 static void _runServer() { |
| 727 // Launch a server to serve out of the directory dartdoc-viewer/client/web. | 737 // Launch a server to serve out of the directory dartdoc-viewer/client/web. |
| 728 HttpServer.bind('localhost', 8080).then((HttpServer httpServer) { | 738 HttpServer.bind('localhost', 8080).then((HttpServer httpServer) { |
| 729 print('Server launched. Navigate your browser to: ' | 739 print('Server launched. Navigate your browser to: ' |
| 730 'http://localhost:${httpServer.port}'); | 740 'http://localhost:${httpServer.port}'); |
| (...skipping 1455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2186 .map((e) => originalMirror.getField(e.simpleName).reflectee) | 2196 .map((e) => originalMirror.getField(e.simpleName).reflectee) |
| 2187 .where((e) => e != null) | 2197 .where((e) => e != null) |
| 2188 .toList(); | 2198 .toList(); |
| 2189 } | 2199 } |
| 2190 | 2200 |
| 2191 Map toMap() => { | 2201 Map toMap() => { |
| 2192 'name': Indexable.getDocgenObject(mirror, owningLibrary).docName, | 2202 'name': Indexable.getDocgenObject(mirror, owningLibrary).docName, |
| 2193 'parameters': parameters | 2203 'parameters': parameters |
| 2194 }; | 2204 }; |
| 2195 } | 2205 } |
| OLD | NEW |