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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 | 207 |
208 final entrypoints = <Uri>[]; | 208 final entrypoints = <Uri>[]; |
209 try { | 209 try { |
210 final option = argParser.parse(args); | 210 final option = argParser.parse(args); |
211 | 211 |
212 // This checks to see if the root of all entrypoints is the same. | 212 // This checks to see if the root of all entrypoints is the same. |
213 // If it is not, then we display a warning, as package imports might fail. | 213 // If it is not, then we display a warning, as package imports might fail. |
214 var entrypointRoot; | 214 var entrypointRoot; |
215 for (final entrypoint in option.rest) { | 215 for (final entrypoint in option.rest) { |
216 var uri = Uri.parse(entrypoint); | 216 var uri = Uri.parse(entrypoint); |
217 if (uri.scheme == '') uri = pathToFileUri(entrypoint); | 217 if (uri.scheme == '') uri = path.toUri(entrypoint); |
218 entrypoints.add(uri); | 218 entrypoints.add(uri); |
219 | 219 |
220 if (uri.scheme != 'file') continue; | 220 if (uri.scheme != 'file') continue; |
221 if (entrypointRoot == null) { | 221 if (entrypointRoot == null) { |
222 entrypointRoot = path.dirname(entrypoint); | 222 entrypointRoot = path.dirname(entrypoint); |
223 } else if (entrypointRoot != path.dirname(entrypoint)) { | 223 } else if (entrypointRoot != path.dirname(entrypoint)) { |
224 print('Warning: entrypoints are at different directories. "package:"' | 224 print('Warning: entrypoints are at different directories. "package:"' |
225 ' imports may fail.'); | 225 ' imports may fail.'); |
226 } | 226 } |
227 } | 227 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 .whenComplete(() => dartdoc.cleanup()); | 267 .whenComplete(() => dartdoc.cleanup()); |
268 } | 268 } |
269 | 269 |
270 String _getPackageRoot(List<Uri> entrypoints) { | 270 String _getPackageRoot(List<Uri> entrypoints) { |
271 // Check if there's a `packages` directory in the entry point directory. | 271 // Check if there's a `packages` directory in the entry point directory. |
272 var fileEntrypoint = entrypoints.firstWhere( | 272 var fileEntrypoint = entrypoints.firstWhere( |
273 (entrypoint) => entrypoint.scheme == 'file', | 273 (entrypoint) => entrypoint.scheme == 'file', |
274 orElse: () => null); | 274 orElse: () => null); |
275 if (fileEntrypoint == null) return; | 275 if (fileEntrypoint == null) return; |
276 | 276 |
277 var script = path.normalize(path.absolute(fileUriToPath(fileEntrypoint))); | 277 var script = path.normalize(path.absolute(path.fromUri(fileEntrypoint))); |
278 var dir = path.join(path.dirname(script), 'packages/'); | 278 var dir = path.join(path.dirname(script), 'packages/'); |
279 if (new Directory(dir).existsSync()) return dir; | 279 if (new Directory(dir).existsSync()) return dir; |
280 | 280 |
281 // 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` |
282 // directory. | 282 // directory. |
283 var parts = path.split(path.dirname(script)); | 283 var parts = path.split(path.dirname(script)); |
284 var libDir = parts.lastIndexOf('lib'); | 284 var libDir = parts.lastIndexOf('lib'); |
285 if (libDir > 0) { | 285 if (libDir > 0) { |
286 return path.join(path.joinAll(parts.take(libDir)), 'packages'); | 286 return path.join(path.joinAll(parts.take(libDir)), 'packages'); |
287 } else { | 287 } else { |
288 return null; | 288 return null; |
289 } | 289 } |
290 } | 290 } |
OLD | NEW |