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 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 dartdoc.tmpPath)) | 256 dartdoc.tmpPath)) |
257 .then((_) => copyDirectory( | 257 .then((_) => copyDirectory( |
258 path.join(libPath, 'lib', '_internal', 'dartdoc', 'static'), | 258 path.join(libPath, 'lib', '_internal', 'dartdoc', 'static'), |
259 dartdoc.outputDir)) | 259 dartdoc.outputDir)) |
260 .then((_) { | 260 .then((_) { |
261 print(dartdoc.status); | 261 print(dartdoc.status); |
262 if (dartdoc.totals == 0) { | 262 if (dartdoc.totals == 0) { |
263 exit(1); | 263 exit(1); |
264 } | 264 } |
265 }) | 265 }) |
266 .catchError((e) { | 266 .catchError((e, trace) { |
267 print('Error: generation failed: ${e}'); | 267 print('Error: generation failed: ${e}'); |
268 var trace = getAttachedStackTrace(e); | |
269 if (trace != null) print("StackTrace: $trace"); | 268 if (trace != null) print("StackTrace: $trace"); |
270 dartdoc.cleanup(); | 269 dartdoc.cleanup(); |
271 exit(1); | 270 exit(1); |
272 }) | 271 }) |
273 .whenComplete(() => dartdoc.cleanup()); | 272 .whenComplete(() => dartdoc.cleanup()); |
274 } | 273 } |
275 | 274 |
276 String _getPackageRoot(List<Uri> entrypoints) { | 275 String _getPackageRoot(List<Uri> entrypoints) { |
277 // Check if there's a `packages` directory in the entry point directory. | 276 // Check if there's a `packages` directory in the entry point directory. |
278 var fileEntrypoint = entrypoints.firstWhere( | 277 var fileEntrypoint = entrypoints.firstWhere( |
279 (entrypoint) => entrypoint.scheme == 'file', | 278 (entrypoint) => entrypoint.scheme == 'file', |
280 orElse: () => null); | 279 orElse: () => null); |
281 if (fileEntrypoint == null) return; | 280 if (fileEntrypoint == null) return; |
282 | 281 |
283 var script = path.normalize(path.absolute(path.fromUri(fileEntrypoint))); | 282 var script = path.normalize(path.absolute(path.fromUri(fileEntrypoint))); |
284 var dir = path.join(path.dirname(script), 'packages/'); | 283 var dir = path.join(path.dirname(script), 'packages/'); |
285 if (new Directory(dir).existsSync()) return dir; | 284 if (new Directory(dir).existsSync()) return dir; |
286 | 285 |
287 // If there is not, then check if the entrypoint is somewhere in a `lib` | 286 // If there is not, then check if the entrypoint is somewhere in a `lib` |
288 // directory. | 287 // directory. |
289 var parts = path.split(path.dirname(script)); | 288 var parts = path.split(path.dirname(script)); |
290 var libDir = parts.lastIndexOf('lib'); | 289 var libDir = parts.lastIndexOf('lib'); |
291 if (libDir > 0) { | 290 if (libDir > 0) { |
292 return path.join(path.joinAll(parts.take(libDir)), 'packages'); | 291 return path.join(path.joinAll(parts.take(libDir)), 'packages'); |
293 } else { | 292 } else { |
294 return null; | 293 return null; |
295 } | 294 } |
296 } | 295 } |
OLD | NEW |