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