| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 /** | 5 /** |
| 6 * To generate docs for a library, run this script with the path to an | 6 * To generate docs for a library, run this script with the path to an |
| 7 * entrypoint .dart file, like: | 7 * entrypoint .dart file, like: |
| 8 * | 8 * |
| 9 * $ dart dartdoc.dart foo.dart | 9 * $ dart dartdoc.dart foo.dart |
| 10 * | 10 * |
| 11 * This will create a "docs" directory with the docs for your libraries. To | 11 * This will create a "docs" directory with the docs for your libraries. To |
| 12 * create these beautiful docs, dartdoc parses your library and every library | 12 * create these beautiful docs, dartdoc parses your library and every library |
| 13 * it imports (recursively). From each library, it parses all classes and | 13 * it imports (recursively). From each library, it parses all classes and |
| 14 * members, finds the associated doc comments and builds crosslinked docs from | 14 * members, finds the associated doc comments and builds crosslinked docs from |
| 15 * them. | 15 * them. |
| 16 */ | 16 */ |
| 17 library dartdoc; | 17 library dartdoc; |
| 18 | 18 |
| 19 import 'dart:async'; |
| 19 import 'dart:io'; | 20 import 'dart:io'; |
| 20 import 'dart:async'; | 21 |
| 22 import '../lib/dartdoc.dart'; |
| 21 | 23 |
| 22 // TODO(rnystrom): Use "package:" URL (#4968). | 24 // TODO(rnystrom): Use "package:" URL (#4968). |
| 23 import '../lib/dartdoc.dart'; | 25 import '../../../../../pkg/args/lib/args.dart'; |
| 24 import '../../../../../pkg/pathos/lib/path.dart' as path; | 26 import '../../../../../pkg/pathos/lib/path.dart' as path; |
| 25 import '../../../../../pkg/args/lib/args.dart'; | |
| 26 | 27 |
| 27 /** | 28 /** |
| 28 * Run this from the `lib/_internal/dartdoc` directory. | 29 * Run this from the `lib/_internal/dartdoc` directory. |
| 29 */ | 30 */ |
| 30 main() { | 31 main() { |
| 31 // Need this because ArgParser.getUsage doesn't show command invocation. | 32 // Need this because ArgParser.getUsage doesn't show command invocation. |
| 32 final USAGE = 'Usage dartdoc [options] <entrypoint(s)>\n[options] include:'; | 33 final USAGE = 'Usage dartdoc [options] <entrypoint(s)>\n[options] include:'; |
| 33 | 34 |
| 34 final args = new Options().arguments; | 35 final args = new Options().arguments; |
| 35 | 36 |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 if (new Directory(dir).existsSync()) { | 218 if (new Directory(dir).existsSync()) { |
| 218 // TODO(amouravski): convert all of dartdoc to use pathos. | 219 // TODO(amouravski): convert all of dartdoc to use pathos. |
| 219 pkgPath = new Path(dir); | 220 pkgPath = new Path(dir); |
| 220 } else { | 221 } else { |
| 221 // If there is not, then check if the entrypoint is somewhere in a `lib` | 222 // If there is not, then check if the entrypoint is somewhere in a `lib` |
| 222 // directory. | 223 // directory. |
| 223 dir = path.dirname(script); | 224 dir = path.dirname(script); |
| 224 var parts = path.split(dir); | 225 var parts = path.split(dir); |
| 225 var libDir = parts.lastIndexOf('lib'); | 226 var libDir = parts.lastIndexOf('lib'); |
| 226 if (libDir > 0) { | 227 if (libDir > 0) { |
| 227 pkgPath = new Path(path.join(path.joinAll(parts.take(libDir - 1)), | 228 pkgPath = new Path(path.join(path.joinAll(parts.take(libDir)), |
| 228 'packages')); | 229 'packages')); |
| 229 } | 230 } |
| 230 } | 231 } |
| 231 } | 232 } |
| 232 | 233 |
| 233 cleanOutputDirectory(dartdoc.outputDir); | 234 cleanOutputDirectory(dartdoc.outputDir); |
| 234 | 235 |
| 235 print('Analyzing sources'); | 236 // Start the analysis and documentation. |
| 236 Future documented = dartdoc.documentLibraries(entrypoints, libPath, pkgPath); | 237 dartdoc.documentLibraries(entrypoints, libPath, pkgPath) |
| 237 | 238 .then((_) { |
| 238 documented.then((_) { | 239 print('Copying static files...'); |
| 239 Future compiled = compileScript(dartdoc.mode, dartdoc.outputDir, libPath); | 240 Future.wait([ |
| 240 Future filesCopied = copyDirectory(scriptDir.append('../static'), | 241 // Prepare the dart2js script code and copy static resources. |
| 241 dartdoc.outputDir); | 242 // TODO(amouravski): move compileScript out and pre-generate the client |
| 242 | 243 // scripts. This takes a long time and the js hardly ever changes. |
| 243 Future.wait([compiled, filesCopied]).then((_) { | 244 compileScript(dartdoc.mode, dartdoc.outputDir, libPath), |
| 244 dartdoc.cleanup(); | 245 copyDirectory(scriptDir.append('../static'), dartdoc.outputDir) |
| 245 if (dartdoc.totalLibraries + dartdoc.totalTypes + | 246 ]); |
| 246 dartdoc.totalMembers == 0) { | 247 }) |
| 247 print('Nothing was documented!'); | 248 .then((_) { |
| 249 print(dartdoc.status); |
| 250 if (dartdoc.totals == 0) { |
| 248 exit(1); | 251 exit(1); |
| 249 } else { | |
| 250 print('Documented ${dartdoc.totalLibraries} libraries, ' | |
| 251 '${dartdoc.totalTypes} types, and ${dartdoc.totalMembers} ' | |
| 252 'members.'); | |
| 253 } | 252 } |
| 254 }); | 253 }) |
| 255 }, onError: (AsyncError asyncError) { | 254 .catchError((e) { |
| 256 print('Generation failed: ${asyncError.error}'); | 255 print('Error: generation failed: ${e.error}'); |
| 257 dartdoc.cleanup(); | 256 exit(1); |
| 258 exit(1); | 257 }) |
| 259 }); | 258 .whenComplete(() => dartdoc.cleanup()); |
| 260 } | 259 } |
| OLD | NEW |