| 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 21 matching lines...) Expand all Loading... |
| 32 final USAGE = 'Usage dartdoc [options] <entrypoint(s)>\n[options] include:'; | 32 final USAGE = 'Usage dartdoc [options] <entrypoint(s)>\n[options] include:'; |
| 33 | 33 |
| 34 final args = new Options().arguments; | 34 final args = new Options().arguments; |
| 35 | 35 |
| 36 final dartdoc = new Dartdoc(); | 36 final dartdoc = new Dartdoc(); |
| 37 | 37 |
| 38 final argParser = new ArgParser(); | 38 final argParser = new ArgParser(); |
| 39 | 39 |
| 40 final Path libPath = scriptDir.append('../../../../'); | 40 final Path libPath = scriptDir.append('../../../../'); |
| 41 | 41 |
| 42 Path pkgPath; | 42 Path packageRoot; |
| 43 | 43 |
| 44 argParser.addFlag('no-code', | 44 argParser.addFlag('no-code', |
| 45 help: 'Do not include source code in the documentation.', | 45 help: 'Do not include source code in the documentation.', |
| 46 defaultsTo: false, negatable: false, | 46 defaultsTo: false, negatable: false, |
| 47 callback: (noCode) => dartdoc.includeSource = !noCode); | 47 callback: (noCode) => dartdoc.includeSource = !noCode); |
| 48 | 48 |
| 49 argParser.addOption('mode', abbr: 'm', | 49 argParser.addOption('mode', abbr: 'm', |
| 50 help: 'Define how HTML pages are generated.', | 50 help: 'Define how HTML pages are generated.', |
| 51 allowed: ['static', 'live-nav'], allowedHelp: { | 51 allowed: ['static', 'live-nav'], allowedHelp: { |
| 52 'static': 'Generates completely static HTML containing\n' | 52 'static': 'Generates completely static HTML containing\n' |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 for(final lst in excLibs) { | 153 for(final lst in excLibs) { |
| 154 var someLibs = lst.split(','); | 154 var someLibs = lst.split(','); |
| 155 for(final lib in someLibs) { | 155 for(final lib in someLibs) { |
| 156 allLibs.add(lib); | 156 allLibs.add(lib); |
| 157 } | 157 } |
| 158 } | 158 } |
| 159 dartdoc.excludedLibraries = allLibs; | 159 dartdoc.excludedLibraries = allLibs; |
| 160 } | 160 } |
| 161 }, allowMultiple: true); | 161 }, allowMultiple: true); |
| 162 | 162 |
| 163 argParser.addOption('pkg', | 163 argParser.addOption('package-root', |
| 164 help: 'Sets the package directory to the specified directory.\n' | 164 help: 'Sets the package directory to the specified directory.\n' |
| 165 'If omitted the package directory is the SDK pkg/ dir', | 165 'If omitted the package directory is the closest packages directory to' |
| 166 callback: (pkgDir) { | 166 ' the entrypoint.', |
| 167 if(pkgDir != null) { | 167 callback: (packageDir) { |
| 168 pkgPath = new Path(pkgDir); | 168 if(packageDir != null) { |
| 169 packageRoot = new Path(packageDir); |
| 169 } | 170 } |
| 170 }); | 171 }); |
| 171 | 172 |
| 173 // TODO(amouravski): This method is deprecated. Remove on April 22. |
| 174 argParser.addOption('pkg', |
| 175 help: 'Deprecated: same as --package-root.', |
| 176 callback: (packageDir) { |
| 177 if(packageDir != null) { |
| 178 packageRoot = new Path(packageDir); |
| 179 } |
| 180 }); |
| 181 |
| 172 dartdoc.dartdocPath = libPath.append('lib/_internal/dartdoc'); | 182 dartdoc.dartdocPath = libPath.append('lib/_internal/dartdoc'); |
| 173 | 183 |
| 174 if (args.isEmpty) { | 184 if (args.isEmpty) { |
| 175 print('No arguments provided.'); | 185 print('No arguments provided.'); |
| 176 print(USAGE); | 186 print(USAGE); |
| 177 print(argParser.getUsage()); | 187 print(argParser.getUsage()); |
| 178 exit(1); | 188 exit(1); |
| 179 } | 189 } |
| 180 | 190 |
| 181 final entrypoints = <Path>[]; | 191 final entrypoints = <Path>[]; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 203 print(argParser.getUsage()); | 213 print(argParser.getUsage()); |
| 204 exit(1); | 214 exit(1); |
| 205 } | 215 } |
| 206 | 216 |
| 207 if (entrypoints.isEmpty) { | 217 if (entrypoints.isEmpty) { |
| 208 print('No entrypoints provided.'); | 218 print('No entrypoints provided.'); |
| 209 print(argParser.getUsage()); | 219 print(argParser.getUsage()); |
| 210 exit(1); | 220 exit(1); |
| 211 } | 221 } |
| 212 | 222 |
| 213 if (pkgPath == null) { | 223 if (packageRoot == null) { |
| 214 // Check if there's a `packages` directory in the entry point directory. | 224 // Check if there's a `packages` directory in the entry point directory. |
| 215 var script = path.normalize(path.absolute(entrypoints[0].toNativePath())); | 225 var script = path.normalize(path.absolute(entrypoints[0].toNativePath())); |
| 216 var dir = path.join(path.dirname(script), 'packages/'); | 226 var dir = path.join(path.dirname(script), 'packages/'); |
| 217 if (new Directory(dir).existsSync()) { | 227 if (new Directory(dir).existsSync()) { |
| 218 // TODO(amouravski): convert all of dartdoc to use pathos. | 228 // TODO(amouravski): convert all of dartdoc to use pathos. |
| 219 pkgPath = new Path(dir); | 229 packageRoot = new Path(dir); |
| 220 } else { | 230 } else { |
| 221 // If there is not, then check if the entrypoint is somewhere in a `lib` | 231 // If there is not, then check if the entrypoint is somewhere in a `lib` |
| 222 // directory. | 232 // directory. |
| 223 dir = path.dirname(script); | 233 dir = path.dirname(script); |
| 224 var parts = path.split(dir); | 234 var parts = path.split(dir); |
| 225 var libDir = parts.lastIndexOf('lib'); | 235 var libDir = parts.lastIndexOf('lib'); |
| 226 if (libDir > 0) { | 236 if (libDir > 0) { |
| 227 pkgPath = new Path(path.join(path.joinAll(parts.take(libDir)), | 237 packageRoot = new Path(path.join(path.joinAll(parts.take(libDir)), |
| 228 'packages')); | 238 'packages')); |
| 229 } | 239 } |
| 230 } | 240 } |
| 231 } | 241 } |
| 232 | 242 |
| 233 cleanOutputDirectory(dartdoc.outputDir); | 243 cleanOutputDirectory(dartdoc.outputDir); |
| 234 | 244 |
| 235 // Start the analysis and documentation. | 245 // Start the analysis and documentation. |
| 236 dartdoc.documentLibraries(entrypoints, libPath, pkgPath) | 246 dartdoc.documentLibraries(entrypoints, libPath, packageRoot) |
| 237 .then((_) { | 247 .then((_) { |
| 238 print('Copying static files...'); | 248 print('Copying static files...'); |
| 239 Future.wait([ | 249 Future.wait([ |
| 240 // Prepare the dart2js script code and copy static resources. | 250 // Prepare the dart2js script code and copy static resources. |
| 241 // TODO(amouravski): move compileScript out and pre-generate the client | 251 // TODO(amouravski): move compileScript out and pre-generate the client |
| 242 // scripts. This takes a long time and the js hardly ever changes. | 252 // scripts. This takes a long time and the js hardly ever changes. |
| 243 compileScript(dartdoc.mode, dartdoc.outputDir, libPath), | 253 compileScript(dartdoc.mode, dartdoc.outputDir, libPath), |
| 244 copyDirectory(scriptDir.append('../static'), dartdoc.outputDir) | 254 copyDirectory(scriptDir.append('../static'), dartdoc.outputDir) |
| 245 ]); | 255 ]); |
| 246 }) | 256 }) |
| 247 .then((_) { | 257 .then((_) { |
| 248 print(dartdoc.status); | 258 print(dartdoc.status); |
| 249 if (dartdoc.totals == 0) { | 259 if (dartdoc.totals == 0) { |
| 250 exit(1); | 260 exit(1); |
| 251 } | 261 } |
| 252 }) | 262 }) |
| 253 .catchError((e) { | 263 .catchError((e) { |
| 254 print('Error: generation failed: ${e.error}'); | 264 print('Error: generation failed: ${e.error}'); |
| 255 exit(1); | 265 exit(1); |
| 256 }) | 266 }) |
| 257 .whenComplete(() => dartdoc.cleanup()); | 267 .whenComplete(() => dartdoc.cleanup()); |
| 258 } | 268 } |
| OLD | NEW |