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 27 matching lines...) Expand all Loading... |
38 mainWithOptions(Options options) { | 38 mainWithOptions(Options options) { |
39 // Need this because ArgParser.getUsage doesn't show command invocation. | 39 // Need this because ArgParser.getUsage doesn't show command invocation. |
40 final USAGE = 'Usage dartdoc [options] <entrypoint(s)>\n[options] include:'; | 40 final USAGE = 'Usage dartdoc [options] <entrypoint(s)>\n[options] include:'; |
41 | 41 |
42 final args = options.arguments; | 42 final args = options.arguments; |
43 | 43 |
44 final dartdoc = new Dartdoc(); | 44 final dartdoc = new Dartdoc(); |
45 | 45 |
46 final argParser = new ArgParser(); | 46 final argParser = new ArgParser(); |
47 | 47 |
48 Path libPath = scriptDir.append('../../../../'); | 48 String libPath = path.join(scriptDir, '..', '..', '..', '..'); |
49 | 49 |
50 String packageRoot; | 50 String packageRoot; |
51 | 51 |
52 argParser.addFlag('no-code', | 52 argParser.addFlag('no-code', |
53 help: 'Do not include source code in the documentation.', | 53 help: 'Do not include source code in the documentation.', |
54 defaultsTo: false, negatable: false, | 54 defaultsTo: false, negatable: false, |
55 callback: (noCode) => dartdoc.includeSource = !noCode); | 55 callback: (noCode) => dartdoc.includeSource = !noCode); |
56 | 56 |
57 argParser.addOption('mode', abbr: 'm', | 57 argParser.addOption('mode', abbr: 'm', |
58 help: 'Define how HTML pages are generated.', | 58 help: 'Define how HTML pages are generated.', |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 defaultsTo: false, negatable: false, | 119 defaultsTo: false, negatable: false, |
120 callback: (inherit) => dartdoc.inheritFromObject = inherit); | 120 callback: (inherit) => dartdoc.inheritFromObject = inherit); |
121 | 121 |
122 argParser.addFlag('enable-diagnostic-colors', negatable: false); | 122 argParser.addFlag('enable-diagnostic-colors', negatable: false); |
123 | 123 |
124 argParser.addOption('out', | 124 argParser.addOption('out', |
125 help: 'Generates files into directory specified. If\n' | 125 help: 'Generates files into directory specified. If\n' |
126 'omitted the files are generated into ./docs/', | 126 'omitted the files are generated into ./docs/', |
127 callback: (outDir) { | 127 callback: (outDir) { |
128 if(outDir != null) { | 128 if(outDir != null) { |
129 dartdoc.outputDir = new Path(outDir); | 129 dartdoc.outputDir = outDir; |
130 } | 130 } |
131 }); | 131 }); |
132 | 132 |
133 argParser.addOption('include-lib', | 133 argParser.addOption('include-lib', |
134 help: 'Use this option to explicitly specify which\n' | 134 help: 'Use this option to explicitly specify which\n' |
135 'libraries to include in the documentation. If\n' | 135 'libraries to include in the documentation. If\n' |
136 'omitted, all used libraries are included by\n' | 136 'omitted, all used libraries are included by\n' |
137 'default. Specify a comma-separated list of\n' | 137 'default. Specify a comma-separated list of\n' |
138 'library names, or call this option multiple times.', | 138 'library names, or call this option multiple times.', |
139 callback: (incLibs) { | 139 callback: (incLibs) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 callback: (packageDir) { | 175 callback: (packageDir) { |
176 if(packageDir != null) { | 176 if(packageDir != null) { |
177 packageRoot = packageDir; | 177 packageRoot = packageDir; |
178 } | 178 } |
179 }); | 179 }); |
180 | 180 |
181 argParser.addOption('library-root', | 181 argParser.addOption('library-root', |
182 help: 'Sets the library root directory to the specified directory.', | 182 help: 'Sets the library root directory to the specified directory.', |
183 callback: (libraryRoot) { | 183 callback: (libraryRoot) { |
184 if (libraryRoot != null) { | 184 if (libraryRoot != null) { |
185 libPath = new Path(libraryRoot); | 185 libPath = libraryRoot; |
186 } | 186 } |
187 }); | 187 }); |
188 | 188 |
189 // TODO(amouravski): This method is deprecated. Remove on April 22. | 189 // TODO(amouravski): This method is deprecated. Remove on April 22. |
190 argParser.addOption('pkg', | 190 argParser.addOption('pkg', |
191 help: 'Deprecated: same as --package-root.', | 191 help: 'Deprecated: same as --package-root.', |
192 callback: (packageDir) { | 192 callback: (packageDir) { |
193 if(packageDir != null) { | 193 if(packageDir != null) { |
194 packageRoot = packageDir; | 194 packageRoot = packageDir; |
195 } | 195 } |
196 }); | 196 }); |
197 | 197 |
198 dartdoc.dartdocPath = libPath.append('lib/_internal/dartdoc'); | 198 dartdoc.dartdocPath = path.join(libPath, 'lib', '_internal', 'dartdoc'); |
199 | 199 |
200 if (args.isEmpty) { | 200 if (args.isEmpty) { |
201 print('No arguments provided.'); | 201 print('No arguments provided.'); |
202 print(USAGE); | 202 print(USAGE); |
203 print(argParser.getUsage()); | 203 print(argParser.getUsage()); |
204 exit(1); | 204 exit(1); |
205 } | 205 } |
206 | 206 |
207 final entrypoints = <Uri>[]; | 207 final entrypoints = <Uri>[]; |
208 try { | 208 try { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 | 241 |
242 cleanOutputDirectory(dartdoc.outputDir); | 242 cleanOutputDirectory(dartdoc.outputDir); |
243 | 243 |
244 // Start the analysis and documentation. | 244 // Start the analysis and documentation. |
245 dartdoc.documentLibraries(entrypoints, libPath, packageRoot) | 245 dartdoc.documentLibraries(entrypoints, libPath, packageRoot) |
246 // Prepare the dart2js script code and copy static resources. | 246 // Prepare the dart2js script code and copy static resources. |
247 // TODO(amouravski): move compileScript out and pre-generate the client | 247 // TODO(amouravski): move compileScript out and pre-generate the client |
248 // 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. |
249 .then((_) => compileScript(dartdoc.mode, dartdoc.outputDir, libPath, | 249 .then((_) => compileScript(dartdoc.mode, dartdoc.outputDir, libPath, |
250 dartdoc.tmpPath)) | 250 dartdoc.tmpPath)) |
251 .then((_) => copyDirectory(libPath.append('lib/_internal/dartdoc/static'), | 251 .then((_) => copyDirectory( |
252 dartdoc.outputDir)) | 252 path.join(libPath, 'lib', '_internal', 'dartdoc', 'static'), |
| 253 dartdoc.outputDir)) |
253 .then((_) { | 254 .then((_) { |
254 print(dartdoc.status); | 255 print(dartdoc.status); |
255 if (dartdoc.totals == 0) { | 256 if (dartdoc.totals == 0) { |
256 exit(1); | 257 exit(1); |
257 } | 258 } |
258 }) | 259 }) |
259 .catchError((e) { | 260 .catchError((e) { |
260 print('Error: generation failed: ${e}'); | 261 print('Error: generation failed: ${e}'); |
261 var trace = getAttachedStackTrace(e); | 262 var trace = getAttachedStackTrace(e); |
262 if (trace != null) print("StackTrace: $trace"); | 263 if (trace != null) print("StackTrace: $trace"); |
(...skipping 17 matching lines...) Expand all Loading... |
280 // If there is not, then check if the entrypoint is somewhere in a `lib` | 281 // If there is not, then check if the entrypoint is somewhere in a `lib` |
281 // directory. | 282 // directory. |
282 var parts = path.split(path.dirname(script)); | 283 var parts = path.split(path.dirname(script)); |
283 var libDir = parts.lastIndexOf('lib'); | 284 var libDir = parts.lastIndexOf('lib'); |
284 if (libDir > 0) { | 285 if (libDir > 0) { |
285 return path.join(path.joinAll(parts.take(libDir)), 'packages'); | 286 return path.join(path.joinAll(parts.take(libDir)), 'packages'); |
286 } else { | 287 } else { |
287 return null; | 288 return null; |
288 } | 289 } |
289 } | 290 } |
OLD | NEW |