| 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 19 matching lines...) Expand all Loading... |
| 30 // Need this because ArgParser.getUsage doesn't show command invocation. | 30 // Need this because ArgParser.getUsage doesn't show command invocation. |
| 31 final USAGE = 'Usage dartdoc [options] <entrypoint(s)>\n[options] include:'; | 31 final USAGE = 'Usage dartdoc [options] <entrypoint(s)>\n[options] include:'; |
| 32 | 32 |
| 33 final args = new Options().arguments; | 33 final args = new Options().arguments; |
| 34 | 34 |
| 35 final dartdoc = new Dartdoc(); | 35 final dartdoc = new Dartdoc(); |
| 36 | 36 |
| 37 final argParser = new ArgParser(); | 37 final argParser = new ArgParser(); |
| 38 | 38 |
| 39 final Path libPath = scriptDir.append('../../../../'); | 39 final Path libPath = scriptDir.append('../../../../'); |
| 40 | 40 |
| 41 Path pkgPath; | 41 Path pkgPath; |
| 42 | 42 |
| 43 argParser.addFlag('no-code', | 43 argParser.addFlag('no-code', |
| 44 help: 'Do not include source code in the documentation.', | 44 help: 'Do not include source code in the documentation.', |
| 45 defaultsTo: false, negatable: false, | 45 defaultsTo: false, negatable: false, |
| 46 callback: (noCode) => dartdoc.includeSource = !noCode); | 46 callback: (noCode) => dartdoc.includeSource = !noCode); |
| 47 | 47 |
| 48 argParser.addOption('mode', abbr: 'm', | 48 argParser.addOption('mode', abbr: 'm', |
| 49 help: 'Define how HTML pages are generated.', | 49 help: 'Define how HTML pages are generated.', |
| 50 allowed: ['static', 'live-nav'], allowedHelp: { | 50 allowed: ['static', 'live-nav'], allowedHelp: { |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 if (args.isEmpty) { | 173 if (args.isEmpty) { |
| 174 print('No arguments provided.'); | 174 print('No arguments provided.'); |
| 175 print(USAGE); | 175 print(USAGE); |
| 176 print(argParser.getUsage()); | 176 print(argParser.getUsage()); |
| 177 exit(1); | 177 exit(1); |
| 178 } | 178 } |
| 179 | 179 |
| 180 final entrypoints = <Path>[]; | 180 final entrypoints = <Path>[]; |
| 181 try { | 181 try { |
| 182 final option = argParser.parse(args); | 182 final option = argParser.parse(args); |
| 183 | 183 |
| 184 // This checks to see if the root of all entrypoints is the same. | 184 // This checks to see if the root of all entrypoints is the same. |
| 185 // If it is not, then we display a warning, as package imports might fail. | 185 // If it is not, then we display a warning, as package imports might fail. |
| 186 var entrypointRoot; | 186 var entrypointRoot; |
| 187 for(final arg in option.rest) { | 187 for(final arg in option.rest) { |
| 188 var entrypoint = new Path.fromNative(arg); | 188 var entrypoint = new Path.fromNative(arg); |
| 189 entrypoints.add(entrypoint); | 189 entrypoints.add(entrypoint); |
| 190 | 190 |
| 191 if (entrypointRoot == null) { | 191 if (entrypointRoot == null) { |
| 192 entrypointRoot = entrypoint.directoryPath; | 192 entrypointRoot = entrypoint.directoryPath; |
| 193 } else if (entrypointRoot.toNativePath() != | 193 } else if (entrypointRoot.toNativePath() != |
| 194 entrypoint.directoryPath.toNativePath()) { | 194 entrypoint.directoryPath.toNativePath()) { |
| 195 print('Warning: entrypoints are at different directories. "package:"' | 195 print('Warning: entrypoints are at different directories. "package:"' |
| 196 ' imports may fail.'); | 196 ' imports may fail.'); |
| 197 } | 197 } |
| 198 } | 198 } |
| 199 } on FormatException catch (e) { | 199 } on FormatException catch (e) { |
| 200 print(e.message); | 200 print(e.message); |
| 201 print(USAGE); | 201 print(USAGE); |
| 202 print(argParser.getUsage()); | 202 print(argParser.getUsage()); |
| 203 exit(1); | 203 exit(1); |
| 204 } | 204 } |
| 205 | 205 |
| 206 if (entrypoints.isEmpty) { | 206 if (entrypoints.isEmpty) { |
| 207 print('No entrypoints provided.'); | 207 print('No entrypoints provided.'); |
| 208 print(argParser.getUsage()); | 208 print(argParser.getUsage()); |
| 209 exit(1); | 209 exit(1); |
| 210 } | 210 } |
| 211 | 211 |
| 212 if (pkgPath == null) { | 212 if (pkgPath == null) { |
| 213 pkgPath = entrypoints[0].directoryPath.append('packages/'); | 213 pkgPath = entrypoints[0].directoryPath.append('packages/'); |
| 214 } | 214 } |
| 215 | 215 |
| 216 cleanOutputDirectory(dartdoc.outputDir); | 216 cleanOutputDirectory(dartdoc.outputDir); |
| 217 | 217 |
| 218 dartdoc.documentLibraries(entrypoints, libPath, pkgPath); | 218 dartdoc.documentLibraries(entrypoints, libPath, pkgPath); |
| 219 | 219 |
| 220 Future compiled = compileScript(dartdoc.mode, dartdoc.outputDir, libPath); | 220 Future compiled = compileScript(dartdoc.mode, dartdoc.outputDir, libPath); |
| 221 Future filesCopied = copyDirectory(scriptDir.append('../static'), | 221 Future filesCopied = copyDirectory(scriptDir.append('../static'), |
| 222 dartdoc.outputDir); | 222 dartdoc.outputDir); |
| 223 | 223 |
| 224 Futures.wait([compiled, filesCopied]).then((_) { | 224 Future.wait([compiled, filesCopied]).then((_) { |
| 225 dartdoc.cleanup(); | 225 dartdoc.cleanup(); |
| 226 print('Documented ${dartdoc.totalLibraries} libraries, ' | 226 print('Documented ${dartdoc.totalLibraries} libraries, ' |
| 227 '${dartdoc.totalTypes} types, and ${dartdoc.totalMembers} members.'); | 227 '${dartdoc.totalTypes} types, and ${dartdoc.totalMembers} members.'); |
| 228 }); | 228 }); |
| 229 } | 229 } |
| OLD | NEW |