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 import '../lib/dartdoc.dart'; | 22 import '../lib/dartdoc.dart'; |
23 import '../lib/src/dartdoc/utils.dart'; | 23 import '../lib/src/dartdoc/utils.dart'; |
24 import 'package:args/args.dart'; | 24 import 'package:args/args.dart'; |
25 import 'package:path/path.dart' as path; | 25 import 'package:path/path.dart' as path; |
26 | 26 |
27 /** | 27 /** |
28 * Run this from the `lib/_internal/dartdoc` directory. | 28 * Run this from the `lib/_internal/dartdoc` directory. |
29 */ | 29 */ |
30 main() { | 30 main(List<String> arguments) { |
31 mainWithOptions(new Options()); | |
32 } | |
33 | |
34 /** | |
35 * We use this to include dartdoc in a single snapshot with dart2js. | |
36 * (They share 90% of the code) | |
37 */ | |
38 mainWithOptions(Options options) { | |
39 // Need this because ArgParser.getUsage doesn't show command invocation. | 31 // Need this because ArgParser.getUsage doesn't show command invocation. |
40 final USAGE = 'Usage dartdoc [options] <entrypoint(s)>\n[options] include:'; | 32 final USAGE = 'Usage dartdoc [options] <entrypoint(s)>\n[options] include:'; |
41 | 33 |
42 final args = options.arguments; | |
43 | |
44 final dartdoc = new Dartdoc(); | 34 final dartdoc = new Dartdoc(); |
45 | 35 |
46 final argParser = new ArgParser(); | 36 final argParser = new ArgParser(); |
47 | 37 |
48 String libPath = path.join(scriptDir, '..', '..', '..', '..'); | 38 String libPath = path.join(scriptDir, '..', '..', '..', '..'); |
49 | 39 |
50 String packageRoot; | 40 String packageRoot; |
51 | 41 |
52 argParser.addFlag('no-code', | 42 argParser.addFlag('no-code', |
53 help: 'Do not include source code in the documentation.', | 43 help: 'Do not include source code in the documentation.', |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 argParser.addOption('pkg', | 180 argParser.addOption('pkg', |
191 help: 'Deprecated: same as --package-root.', | 181 help: 'Deprecated: same as --package-root.', |
192 callback: (packageDir) { | 182 callback: (packageDir) { |
193 if(packageDir != null) { | 183 if(packageDir != null) { |
194 packageRoot = packageDir; | 184 packageRoot = packageDir; |
195 } | 185 } |
196 }); | 186 }); |
197 | 187 |
198 dartdoc.dartdocPath = path.join(libPath, 'lib', '_internal', 'dartdoc'); | 188 dartdoc.dartdocPath = path.join(libPath, 'lib', '_internal', 'dartdoc'); |
199 | 189 |
200 if (args.isEmpty) { | 190 if (arguments.isEmpty) { |
201 print('No arguments provided.'); | 191 print('No arguments provided.'); |
202 print(USAGE); | 192 print(USAGE); |
203 print(argParser.getUsage()); | 193 print(argParser.getUsage()); |
204 exit(1); | 194 exit(1); |
205 } | 195 } |
206 | 196 |
207 final entrypoints = <Uri>[]; | 197 final entrypoints = <Uri>[]; |
208 try { | 198 try { |
209 final option = argParser.parse(args, allowTrailingOptions: true); | 199 final option = argParser.parse(arguments, allowTrailingOptions: true); |
210 | 200 |
211 // This checks to see if the root of all entrypoints is the same. | 201 // This checks to see if the root of all entrypoints is the same. |
212 // If it is not, then we display a warning, as package imports might fail. | 202 // If it is not, then we display a warning, as package imports might fail. |
213 var entrypointRoot; | 203 var entrypointRoot; |
214 for (final entrypoint in option.rest) { | 204 for (final entrypoint in option.rest) { |
215 var uri = Uri.parse(entrypoint); | 205 var uri = Uri.parse(entrypoint); |
216 | 206 |
217 // If it looks like it was a file path (no scheme, or a one letter scheme | 207 // If it looks like it was a file path (no scheme, or a one letter scheme |
218 // which is likely a drive letter on Windows), turn it into a file URL. | 208 // which is likely a drive letter on Windows), turn it into a file URL. |
219 if (uri.scheme == '' || uri.scheme.length == 1) { | 209 if (uri.scheme == '' || uri.scheme.length == 1) { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 // If there is not, then check if the entrypoint is somewhere in a `lib` | 277 // If there is not, then check if the entrypoint is somewhere in a `lib` |
288 // directory. | 278 // directory. |
289 var parts = path.split(path.dirname(script)); | 279 var parts = path.split(path.dirname(script)); |
290 var libDir = parts.lastIndexOf('lib'); | 280 var libDir = parts.lastIndexOf('lib'); |
291 if (libDir > 0) { | 281 if (libDir > 0) { |
292 return path.join(path.joinAll(parts.take(libDir)), 'packages'); | 282 return path.join(path.joinAll(parts.take(libDir)), 'packages'); |
293 } else { | 283 } else { |
294 return null; | 284 return null; |
295 } | 285 } |
296 } | 286 } |
OLD | NEW |