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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 .then((_) => copyDirectory(scriptDir.append('../static'), | 244 .then((_) => copyDirectory(scriptDir.append('../static'), |
245 dartdoc.outputDir)) | 245 dartdoc.outputDir)) |
246 .then((_) { | 246 .then((_) { |
247 print(dartdoc.status); | 247 print(dartdoc.status); |
248 if (dartdoc.totals == 0) { | 248 if (dartdoc.totals == 0) { |
249 exit(1); | 249 exit(1); |
250 } | 250 } |
251 }) | 251 }) |
252 .catchError((e) { | 252 .catchError((e) { |
253 print('Error: generation failed: ${e}'); | 253 print('Error: generation failed: ${e}'); |
| 254 var trace = getAttachedStackTrace(e); |
| 255 if (trace != null) print("StackTrace: $trace"); |
254 dartdoc.cleanup(); | 256 dartdoc.cleanup(); |
255 exit(1); | 257 exit(1); |
256 }) | 258 }) |
257 .whenComplete(() => dartdoc.cleanup()); | 259 .whenComplete(() => dartdoc.cleanup()); |
258 } | 260 } |
259 | 261 |
260 String _getPackageRoot(List<Uri> entrypoints) { | 262 String _getPackageRoot(List<Uri> entrypoints) { |
261 // Check if there's a `packages` directory in the entry point directory. | 263 // Check if there's a `packages` directory in the entry point directory. |
262 var fileEntrypoint = entrypoints.firstWhere( | 264 var fileEntrypoint = entrypoints.firstWhere( |
263 (entrypoint) => entrypoint.scheme == 'file', | 265 (entrypoint) => entrypoint.scheme == 'file', |
264 orElse: () => null); | 266 orElse: () => null); |
265 if (fileEntrypoint == null) return; | 267 if (fileEntrypoint == null) return; |
266 | 268 |
267 var script = path.normalize(path.absolute(fileUriToPath(fileEntrypoint))); | 269 var script = path.normalize(path.absolute(fileUriToPath(fileEntrypoint))); |
268 var dir = path.join(path.dirname(script), 'packages/'); | 270 var dir = path.join(path.dirname(script), 'packages/'); |
269 if (new Directory(dir).existsSync()) return dir; | 271 if (new Directory(dir).existsSync()) return dir; |
270 | 272 |
271 // If there is not, then check if the entrypoint is somewhere in a `lib` | 273 // If there is not, then check if the entrypoint is somewhere in a `lib` |
272 // directory. | 274 // directory. |
273 var parts = path.split(path.dirname(script)); | 275 var parts = path.split(path.dirname(script)); |
274 var libDir = parts.lastIndexOf('lib'); | 276 var libDir = parts.lastIndexOf('lib'); |
275 if (libDir > 0) { | 277 if (libDir > 0) { |
276 return path.join(path.joinAll(parts.take(libDir)), 'packages'); | 278 return path.join(path.joinAll(parts.take(libDir)), 'packages'); |
277 } else { | 279 } else { |
278 return null; | 280 return null; |
279 } | 281 } |
280 } | 282 } |
OLD | NEW |