Chromium Code Reviews| 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:async'; |
| 20 import 'dart:io'; | 20 import 'dart:io'; |
| 21 | 21 |
| 22 // TODO(rnystrom): Use "package:" URL (#4968). | 22 // TODO(rnystrom): Use "package:" URL (#4968). |
| 23 import '../lib/dartdoc.dart'; | 23 import '../lib/dartdoc.dart'; |
| 24 import '../lib/src/dartdoc/utils.dart'; | 24 import '../lib/src/dartdoc/utils.dart'; |
| 25 import 'package:args/args.dart'; | 25 import 'package:args/args.dart'; |
| 26 import 'package:pathos/path.dart' as path; | 26 import 'package:pathos/path.dart' as path; |
| 27 | 27 |
| 28 | |
| 29 main() { | |
| 30 mainWithOptions(new Options()); | |
| 31 } | |
| 32 | |
| 28 /** | 33 /** |
| 29 * Run this from the `lib/_internal/dartdoc` directory. | 34 * Run this from the `lib/_internal/dartdoc` directory. |
| 30 */ | 35 */ |
| 31 main() { | 36 mainWithOptions(Options options) { |
| 32 // Need this because ArgParser.getUsage doesn't show command invocation. | 37 // Need this because ArgParser.getUsage doesn't show command invocation. |
| 33 final USAGE = 'Usage dartdoc [options] <entrypoint(s)>\n[options] include:'; | 38 final USAGE = 'Usage dartdoc [options] <entrypoint(s)>\n[options] include:'; |
| 34 | 39 |
| 35 final args = new Options().arguments; | 40 final args = options.arguments; |
| 36 | 41 |
| 37 final dartdoc = new Dartdoc(); | 42 final dartdoc = new Dartdoc(); |
| 38 | 43 |
| 39 final argParser = new ArgParser(); | 44 final argParser = new ArgParser(); |
| 40 | 45 |
| 41 Path libPath = scriptDir.append('../../../../'); | 46 Path libPath = scriptDir.append('../../../../'); |
| 42 | 47 |
| 43 String packageRoot; | 48 String packageRoot; |
| 44 | 49 |
| 45 argParser.addFlag('no-code', | 50 argParser.addFlag('no-code', |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 228 print('No entrypoints provided.'); | 233 print('No entrypoints provided.'); |
| 229 print(argParser.getUsage()); | 234 print(argParser.getUsage()); |
| 230 exit(1); | 235 exit(1); |
| 231 } | 236 } |
| 232 | 237 |
| 233 if (packageRoot == null) packageRoot = _getPackageRoot(entrypoints); | 238 if (packageRoot == null) packageRoot = _getPackageRoot(entrypoints); |
| 234 | 239 |
| 235 cleanOutputDirectory(dartdoc.outputDir); | 240 cleanOutputDirectory(dartdoc.outputDir); |
| 236 | 241 |
| 237 // Start the analysis and documentation. | 242 // Start the analysis and documentation. |
| 243 var staticPath = | |
|
kustermann
2013/06/03 11:58:56
What is this 'var staticPath =' doing here?
ricow1
2013/06/03 12:08:19
Removed, leftover
| |
| 244 | |
| 238 dartdoc.documentLibraries(entrypoints, libPath, packageRoot) | 245 dartdoc.documentLibraries(entrypoints, libPath, packageRoot) |
| 239 // Prepare the dart2js script code and copy static resources. | 246 // Prepare the dart2js script code and copy static resources. |
| 240 // TODO(amouravski): move compileScript out and pre-generate the client | 247 // TODO(amouravski): move compileScript out and pre-generate the client |
| 241 // scripts. This takes a long time and the js hardly ever changes. | 248 // scripts. This takes a long time and the js hardly ever changes. |
| 242 .then((_) => compileScript(dartdoc.mode, dartdoc.outputDir, libPath)) | 249 .then((_) => compileScript(dartdoc.mode, dartdoc.outputDir, libPath)) |
| 243 .then((_) => copyDirectory(scriptDir.append('../static'), | 250 .then((_) => copyDirectory(libPath.append('lib/_internal/dartdoc/static'), |
| 244 dartdoc.outputDir)) | 251 dartdoc.outputDir)) |
| 245 .then((_) { | 252 .then((_) { |
| 246 print(dartdoc.status); | 253 print(dartdoc.status); |
| 247 if (dartdoc.totals == 0) { | 254 if (dartdoc.totals == 0) { |
| 248 exit(1); | 255 exit(1); |
| 249 } | 256 } |
| 250 }) | 257 }) |
| 251 .catchError((e) { | 258 .catchError((e) { |
| 252 print('Error: generation failed: ${e}'); | 259 print('Error: generation failed: ${e}'); |
| 253 var trace = getAttachedStackTrace(e); | 260 var trace = getAttachedStackTrace(e); |
| 254 if (trace != null) print("StackTrace: $trace"); | 261 if (trace != null) print("StackTrace: $trace"); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 272 // If there is not, then check if the entrypoint is somewhere in a `lib` | 279 // If there is not, then check if the entrypoint is somewhere in a `lib` |
| 273 // directory. | 280 // directory. |
| 274 var parts = path.split(path.dirname(script)); | 281 var parts = path.split(path.dirname(script)); |
| 275 var libDir = parts.lastIndexOf('lib'); | 282 var libDir = parts.lastIndexOf('lib'); |
| 276 if (libDir > 0) { | 283 if (libDir > 0) { |
| 277 return path.join(path.joinAll(parts.take(libDir)), 'packages'); | 284 return path.join(path.joinAll(parts.take(libDir)), 'packages'); |
| 278 } else { | 285 } else { |
| 279 return null; | 286 return null; |
| 280 } | 287 } |
| 281 } | 288 } |
| OLD | NEW |