OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 /** |
| 6 * To generate docs for a library, run this script with the path to an |
| 7 * entrypoint .dart file, like: |
| 8 * |
| 9 * $ dart dartdoc.dart foo.dart |
| 10 * |
| 11 * This will create a "docs" directory with the docs for your libraries. To |
| 12 * create these beautiful docs, dartdoc parses your library and every library |
| 13 * it imports (recursively). From each library, it parses all classes and |
| 14 * members, finds the associated doc comments and builds crosslinked docs from |
| 15 * them. |
| 16 */ |
| 17 #library('dartdoc'); |
| 18 |
| 19 #import('dart:io'); |
| 20 |
| 21 // TODO(rnystrom): Use "package:" URL (#4968). |
| 22 #import('../lib/dartdoc.dart'); |
| 23 |
| 24 // TODO(johnniwinther): Note that [IN_SDK] gets initialized to true when this |
| 25 // file is modified by the SDK deployment script. If you change, be sure to test |
| 26 // that dartdoc still works when run from the built SDK directory. |
| 27 const bool _IN_SDK = false; |
| 28 |
| 29 // TODO(johnniwinther): Trailing slashes matter due to the use of [libPath] as |
| 30 // a base URI with [Uri.resolve]. |
| 31 /// Relative path to the library in which dart2js resides. |
| 32 Path get libPath => _IN_SDK |
| 33 ? scriptDir.append('../../../lib/dart2js/') |
| 34 : scriptDir.append('../../../'); |
| 35 |
| 36 /** |
| 37 * Run this from the `pkg/dartdoc` directory. |
| 38 */ |
| 39 main() { |
| 40 final args = new Options().arguments; |
| 41 |
| 42 final dartdoc = new Dartdoc(); |
| 43 |
| 44 if (args.isEmpty()) { |
| 45 print('No arguments provided.'); |
| 46 printUsage(); |
| 47 return; |
| 48 } |
| 49 |
| 50 final entrypoints = <Path>[]; |
| 51 |
| 52 var i = 0; |
| 53 while (i < args.length) { |
| 54 final arg = args[i]; |
| 55 if (!arg.startsWith('--')) { |
| 56 // The remaining arguments must be entry points. |
| 57 break; |
| 58 } |
| 59 |
| 60 switch (arg) { |
| 61 case '--no-code': |
| 62 dartdoc.includeSource = false; |
| 63 break; |
| 64 |
| 65 case '--mode=static': |
| 66 dartdoc.mode = MODE_STATIC; |
| 67 break; |
| 68 |
| 69 case '--mode=live-nav': |
| 70 dartdoc.mode = MODE_LIVE_NAV; |
| 71 break; |
| 72 |
| 73 case '--generate-app-cache': |
| 74 case '--generate-app-cache=true': |
| 75 dartdoc.generateAppCache = true; |
| 76 break; |
| 77 |
| 78 case '--omit-generation-time': |
| 79 dartdoc.omitGenerationTime = true; |
| 80 break; |
| 81 case '--verbose': |
| 82 dartdoc.verbose = true; |
| 83 break; |
| 84 case '--include-api': |
| 85 dartdoc.includeApi = true; |
| 86 break; |
| 87 case '--link-api': |
| 88 dartdoc.linkToApi = true; |
| 89 break; |
| 90 |
| 91 default: |
| 92 if (arg.startsWith('--out=')) { |
| 93 dartdoc.outputDir = |
| 94 new Path.fromNative(arg.substring('--out='.length)); |
| 95 } else if (arg.startsWith('--include-lib=')) { |
| 96 dartdoc.includedLibraries = |
| 97 arg.substring('--include-lib='.length).split(','); |
| 98 } else if (arg.startsWith('--exclude-lib=')) { |
| 99 dartdoc.excludedLibraries = |
| 100 arg.substring('--exclude-lib='.length).split(','); |
| 101 } else { |
| 102 print('Unknown option: $arg'); |
| 103 printUsage(); |
| 104 return; |
| 105 } |
| 106 break; |
| 107 } |
| 108 i++; |
| 109 } |
| 110 while (i < args.length) { |
| 111 final arg = args[i]; |
| 112 entrypoints.add(new Path.fromNative(arg)); |
| 113 i++; |
| 114 } |
| 115 |
| 116 if (entrypoints.isEmpty()) { |
| 117 print('No entrypoints provided.'); |
| 118 printUsage(); |
| 119 return; |
| 120 } |
| 121 |
| 122 cleanOutputDirectory(dartdoc.outputDir); |
| 123 |
| 124 dartdoc.documentLibraries(entrypoints, libPath); |
| 125 |
| 126 Future compiled = compileScript(dartdoc.mode, dartdoc.outputDir, libPath); |
| 127 Future filesCopied = copyDirectory(scriptDir.append('../static'), |
| 128 dartdoc.outputDir); |
| 129 |
| 130 Futures.wait([compiled, filesCopied]).then((_) { |
| 131 dartdoc.cleanup(); |
| 132 print('Documented ${dartdoc.totalLibraries} libraries, ' |
| 133 '${dartdoc.totalTypes} types, and ${dartdoc.totalMembers} members.'); |
| 134 }); |
| 135 } |
| 136 |
| 137 void printUsage() { |
| 138 print(''' |
| 139 Usage dartdoc [options] <entrypoint(s)> |
| 140 [options] include |
| 141 --no-code Do not include source code in the documentation. |
| 142 |
| 143 --mode=static Generates completely static HTML containing |
| 144 everything you need to browse the docs. The only |
| 145 client side behavior is trivial stuff like syntax |
| 146 highlighting code. |
| 147 |
| 148 --mode=live-nav (default) Generated docs do not include baked HTML |
| 149 navigation. Instead, a single `nav.json` file is |
| 150 created and the appropriate navigation is generated |
| 151 client-side by parsing that and building HTML. |
| 152 This dramatically reduces the generated size of |
| 153 the HTML since a large fraction of each static page |
| 154 is just redundant navigation links. |
| 155 In this mode, the browser will do a XHR for |
| 156 nav.json which means that to preview docs locally, |
| 157 you will need to enable requesting file:// links in |
| 158 your browser or run a little local server like |
| 159 `python -m SimpleHTTPServer`. |
| 160 |
| 161 --generate-app-cache Generates the App Cache manifest file, enabling |
| 162 offline doc viewing. |
| 163 |
| 164 --out=<dir> Generates files into directory <dir>. If omitted |
| 165 the files are generated into ./docs/ |
| 166 |
| 167 --link-api Link to the online language API in the generated |
| 168 documentation. The option overrides inclusion |
| 169 through --include-api or --include-lib. |
| 170 |
| 171 --include-api Include the used API libraries in the generated |
| 172 documentation. If the --link-api option is used, |
| 173 this option is ignored. |
| 174 |
| 175 --include-lib=<libs> Use this option to explicitly specify which |
| 176 libraries to include in the documentation. If |
| 177 omitted, all used libraries are included by |
| 178 default. <libs> is comma-separated list of library |
| 179 names. |
| 180 |
| 181 --exclude-lib=<libs> Use this option to explicitly specify which |
| 182 libraries to exclude from the documentation. If |
| 183 omitted, no libraries are excluded. <libs> is |
| 184 comma-separated list of library names. |
| 185 |
| 186 --verbose Print verbose information during generation. |
| 187 '''); |
| 188 } |
OLD | NEW |