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 * |
(...skipping 11 matching lines...) Expand all Loading... | |
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 /** | 28 /** |
29 * Run this from the `lib/_internal/dartdoc` directory. | 29 * Run this from the `lib/_internal/dartdoc` directory. |
30 */ | 30 */ |
31 main() { | 31 main() { |
32 mainWithOptions(new Options()); | |
33 } | |
34 | |
35 /** | |
36 * We use this to include dartdoc in a single snapshot with dart2js. | |
37 * (They share 90% of the code) | |
38 */ | |
39 mainWithOptions(Options options) { | |
nweiz
2013/06/04 22:54:00
Why not just have the snapshot call main()? "new O
Andrei Mouravski
2013/06/05 00:18:49
Because the snapshot actually calls this with diff
| |
32 // Need this because ArgParser.getUsage doesn't show command invocation. | 40 // Need this because ArgParser.getUsage doesn't show command invocation. |
33 final USAGE = 'Usage dartdoc [options] <entrypoint(s)>\n[options] include:'; | 41 final USAGE = 'Usage dartdoc [options] <entrypoint(s)>\n[options] include:'; |
34 | 42 |
35 final args = new Options().arguments; | 43 final args = options.arguments; |
36 | 44 |
37 final dartdoc = new Dartdoc(); | 45 final dartdoc = new Dartdoc(); |
38 | 46 |
39 final argParser = new ArgParser(); | 47 final argParser = new ArgParser(); |
40 | 48 |
41 Path libPath = scriptDir.append('../../../../'); | 49 Path libPath = scriptDir.append('../../../../'); |
42 | 50 |
43 String packageRoot; | 51 String packageRoot; |
44 | 52 |
45 argParser.addFlag('no-code', | 53 argParser.addFlag('no-code', |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
181 | 189 |
182 // TODO(amouravski): This method is deprecated. Remove on April 22. | 190 // TODO(amouravski): This method is deprecated. Remove on April 22. |
183 argParser.addOption('pkg', | 191 argParser.addOption('pkg', |
184 help: 'Deprecated: same as --package-root.', | 192 help: 'Deprecated: same as --package-root.', |
185 callback: (packageDir) { | 193 callback: (packageDir) { |
186 if(packageDir != null) { | 194 if(packageDir != null) { |
187 packageRoot = packageDir; | 195 packageRoot = packageDir; |
188 } | 196 } |
189 }); | 197 }); |
190 | 198 |
191 dartdoc.dartdocPath = libPath.append('lib/_internal/dartdoc'); | 199 dartdoc.dartdocPath = libPath.append('lib/_internal/dartdoc'); |
nweiz
2013/06/04 22:54:00
It's weird that this is separate from what's essen
Andrei Mouravski
2013/06/05 00:18:49
Yes, but I don't want to try and unstuck this. Tha
| |
192 | 200 |
193 if (args.isEmpty) { | 201 if (args.isEmpty) { |
194 print('No arguments provided.'); | 202 print('No arguments provided.'); |
195 print(USAGE); | 203 print(USAGE); |
196 print(argParser.getUsage()); | 204 print(argParser.getUsage()); |
197 exit(1); | 205 exit(1); |
198 } | 206 } |
199 | 207 |
200 final entrypoints = <Uri>[]; | 208 final entrypoints = <Uri>[]; |
201 try { | 209 try { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
233 if (packageRoot == null) packageRoot = _getPackageRoot(entrypoints); | 241 if (packageRoot == null) packageRoot = _getPackageRoot(entrypoints); |
234 | 242 |
235 cleanOutputDirectory(dartdoc.outputDir); | 243 cleanOutputDirectory(dartdoc.outputDir); |
236 | 244 |
237 // Start the analysis and documentation. | 245 // Start the analysis and documentation. |
238 dartdoc.documentLibraries(entrypoints, libPath, packageRoot) | 246 dartdoc.documentLibraries(entrypoints, libPath, packageRoot) |
239 // Prepare the dart2js script code and copy static resources. | 247 // Prepare the dart2js script code and copy static resources. |
240 // TODO(amouravski): move compileScript out and pre-generate the client | 248 // TODO(amouravski): move compileScript out and pre-generate the client |
241 // scripts. This takes a long time and the js hardly ever changes. | 249 // scripts. This takes a long time and the js hardly ever changes. |
242 .then((_) => compileScript(dartdoc.mode, dartdoc.outputDir, libPath)) | 250 .then((_) => compileScript(dartdoc.mode, dartdoc.outputDir, libPath)) |
243 .then((_) => copyDirectory(scriptDir.append('../static'), | 251 .then((_) => copyDirectory(libPath.append('lib/_internal/dartdoc/static'), |
nweiz
2013/06/04 22:54:00
libPath and scriptPath seem very brittle. It's not
Andrei Mouravski
2013/06/05 00:18:49
I agree, and this will be fixed in a new CL.
| |
244 dartdoc.outputDir)) | 252 dartdoc.outputDir)) |
245 .then((_) { | 253 .then((_) { |
246 print(dartdoc.status); | 254 print(dartdoc.status); |
247 if (dartdoc.totals == 0) { | 255 if (dartdoc.totals == 0) { |
248 exit(1); | 256 exit(1); |
249 } | 257 } |
250 }) | 258 }) |
251 .catchError((e) { | 259 .catchError((e) { |
252 print('Error: generation failed: ${e}'); | 260 print('Error: generation failed: ${e}'); |
253 var trace = getAttachedStackTrace(e); | 261 var trace = getAttachedStackTrace(e); |
254 if (trace != null) print("StackTrace: $trace"); | 262 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` | 280 // If there is not, then check if the entrypoint is somewhere in a `lib` |
273 // directory. | 281 // directory. |
274 var parts = path.split(path.dirname(script)); | 282 var parts = path.split(path.dirname(script)); |
275 var libDir = parts.lastIndexOf('lib'); | 283 var libDir = parts.lastIndexOf('lib'); |
276 if (libDir > 0) { | 284 if (libDir > 0) { |
277 return path.join(path.joinAll(parts.take(libDir)), 'packages'); | 285 return path.join(path.joinAll(parts.take(libDir)), 'packages'); |
278 } else { | 286 } else { |
279 return null; | 287 return null; |
280 } | 288 } |
281 } | 289 } |
OLD | NEW |