Chromium Code Reviews| 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 use it, from this directory, run: | 6 * To generate docs for a library, run this script with the path to an |
| 7 * entrypoint .dart file, like: | |
| 7 * | 8 * |
| 8 * $ ./dartdoc <path to .dart file> | 9 * $ dart dartdoc.dart foo.dart |
|
nweiz
2012/03/17 00:39:31
Shouldn't this be indented so that it'll be code-f
Bob Nystrom
2012/03/17 01:14:19
Done.
| |
| 9 * | 10 * |
| 10 * This will create a "docs" directory with the docs for your libraries. To | 11 * This will create a "docs" directory with the docs for your libraries. To |
| 11 * create these beautiful docs, dartdoc parses your library and every library | 12 * create these beautiful docs, dartdoc parses your library and every library |
| 12 * it imports (recursively). From each library, it parses all classes and | 13 * it imports (recursively). From each library, it parses all classes and |
| 13 * members, finds the associated doc comments and builds crosslinked docs from | 14 * members, finds the associated doc comments and builds crosslinked docs from |
| 14 * them. | 15 * them. |
| 15 */ | 16 */ |
| 16 #library('dartdoc'); | 17 #library('dartdoc'); |
| 17 | 18 |
| 18 #import('dart:io'); | 19 #import('dart:io'); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 82 return; | 83 return; |
| 83 } | 84 } |
| 84 break; | 85 break; |
| 85 } | 86 } |
| 86 } | 87 } |
| 87 | 88 |
| 88 // The entrypoint of the library to generate docs for. | 89 // The entrypoint of the library to generate docs for. |
| 89 final entrypoint = args[args.length - 1]; | 90 final entrypoint = args[args.length - 1]; |
| 90 | 91 |
| 91 final files = new VMFileSystem(); | 92 final files = new VMFileSystem(); |
| 93 | |
| 94 final frogPath = joinPaths(scriptDir, '../../frog/'); | |
| 95 | |
| 92 // TODO(rnystrom): Note that the following line gets munged by create-sdk to | 96 // TODO(rnystrom): Note that the following line gets munged by create-sdk to |
| 93 // work with the SDK's different file layout. If you change it here, make | 97 // work with the SDK's different file layout. If you change it here, make |
| 94 // sure SDK builds still work. | 98 // sure SDK builds still work. |
| 95 parseOptions('../../frog', ['', '', '--libdir=../../frog/lib'], files); | 99 parseOptions(frogPath, ['', '', '--libdir=$frogPath/lib'], files); |
| 96 initializeWorld(files); | 100 initializeWorld(files); |
| 97 | 101 |
| 98 var dartdoc; | 102 var dartdoc = new Dartdoc(); |
|
nweiz
2012/03/17 00:39:31
final
Bob Nystrom
2012/03/17 01:14:19
Done.
| |
| 99 final elapsed = time(() { | |
| 100 dartdoc = new Dartdoc(); | |
| 101 | 103 |
| 102 if (includeSource != null) dartdoc.includeSource = includeSource; | 104 if (includeSource != null) dartdoc.includeSource = includeSource; |
| 103 if (mode != null) dartdoc.mode = mode; | 105 if (mode != null) dartdoc.mode = mode; |
| 104 if (outputDir != null) dartdoc.outputDir = outputDir; | 106 if (outputDir != null) dartdoc.outputDir = outputDir; |
| 105 | 107 |
| 106 cleanOutputDirectory(outputDir); | 108 cleanOutputDirectory(dartdoc.outputDir); |
| 107 | 109 |
| 108 // TODO(rnystrom): Use platform-specific path separator. | 110 // Compile the client-side code to JS. |
| 109 copyFiles('$scriptDir/static', outputDir); | 111 final clientScript = (dartdoc.mode == MODE_STATIC) ? 'static' : 'live-nav'; |
| 112 compileScript(frogPath, '$scriptDir/client-$clientScript.dart', | |
| 113 '${dartdoc.outputDir}/client-$clientScript.js'); | |
| 110 | 114 |
| 111 dartdoc.document(entrypoint); | 115 // TODO(rnystrom): Use platform-specific path separator. |
|
nweiz
2012/03/17 00:39:31
I thought you were getting rid of this TODO
Bob Nystrom
2012/03/17 01:14:19
Done.
| |
| 112 }); | 116 copyFiles('$scriptDir/static', dartdoc.outputDir); |
| 117 | |
| 118 dartdoc.document(entrypoint); | |
| 113 | 119 |
| 114 print('Documented ${dartdoc._totalLibraries} libraries, ' + | 120 print('Documented ${dartdoc._totalLibraries} libraries, ' + |
| 115 '${dartdoc._totalTypes} types, and ' + | 121 '${dartdoc._totalTypes} types, and ' + |
| 116 '${dartdoc._totalMembers} members in ${elapsed}msec.'); | 122 '${dartdoc._totalMembers} members.'); |
| 117 } | 123 } |
| 118 | 124 |
| 119 /** | 125 /** |
| 120 * Gets the full path to the directory containing the entrypoint of the current | 126 * Gets the full path to the directory containing the entrypoint of the current |
| 121 * script. In other words, if you invoked dartdoc, directly, it will be the | 127 * script. In other words, if you invoked dartdoc, directly, it will be the |
| 122 * path to the directory containing `dartdoc.dart`. If you're running a script | 128 * path to the directory containing `dartdoc.dart`. If you're running a script |
| 123 * that imports dartdoc, it will be the path to that script. | 129 * that imports dartdoc, it will be the path to that script. |
| 124 */ | 130 */ |
| 125 String get scriptDir() { | 131 String get scriptDir() { |
| 126 return dirname(new File(new Options().script).fullPathSync()); | 132 return dirname(new File(new Options().script).fullPathSync()); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 154 new File(path).readAsBytes((bytes) { | 160 new File(path).readAsBytes((bytes) { |
| 155 final outFile = new File('$to/$name'); | 161 final outFile = new File('$to/$name'); |
| 156 final stream = outFile.openOutputStream(FileMode.WRITE); | 162 final stream = outFile.openOutputStream(FileMode.WRITE); |
| 157 stream.write(bytes, copyBuffer: false); | 163 stream.write(bytes, copyBuffer: false); |
| 158 stream.close(); | 164 stream.close(); |
| 159 }); | 165 }); |
| 160 }; | 166 }; |
| 161 fromDir.list(recursive: false); | 167 fromDir.list(recursive: false); |
| 162 } | 168 } |
| 163 | 169 |
| 170 /** | |
| 171 * Compiles the given Dart script to a JavaScript file at [jsPath] using frog. | |
| 172 */ | |
| 173 void compileScript(String frogPath, String dartPath, String jsPath) { | |
| 174 final process = new Process.start('$frogPath/minfrog', [ | |
| 175 '--libdir=$frogPath/lib', '--out=$jsPath', | |
| 176 '--compile-only', '--enable-type-checks', '--warnings-as-errors', | |
| 177 dartPath]); | |
| 178 | |
| 179 process.stdout.pipe(stdout, close: false); | |
| 180 | |
| 181 process.onError = (error) { | |
| 182 print('Failed to compile $dartPath. Error:'); | |
| 183 print(error); | |
| 184 }; | |
| 185 } | |
| 186 | |
| 164 class Dartdoc { | 187 class Dartdoc { |
| 165 /** Set to `false` to not include the source code in the generated docs. */ | 188 /** Set to `false` to not include the source code in the generated docs. */ |
| 166 bool includeSource = true; | 189 bool includeSource = true; |
| 167 | 190 |
| 168 /** | 191 /** |
| 169 * Dartdoc can generate docs in a few different ways based on how dynamic you | 192 * Dartdoc can generate docs in a few different ways based on how dynamic you |
| 170 * want the client-side behavior to be. The value for this should be one of | 193 * want the client-side behavior to be. The value for this should be one of |
| 171 * the `MODE_` constants. | 194 * the `MODE_` constants. |
| 172 */ | 195 */ |
| 173 int mode = MODE_LIVE_NAV; | 196 int mode = MODE_LIVE_NAV; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 // Patch in support for [:...:]-style code to the markdown parser. | 256 // Patch in support for [:...:]-style code to the markdown parser. |
| 234 // TODO(rnystrom): Markdown already has syntax for this. Phase this out? | 257 // TODO(rnystrom): Markdown already has syntax for this. Phase this out? |
| 235 md.InlineParser.syntaxes.insertRange(0, 1, | 258 md.InlineParser.syntaxes.insertRange(0, 1, |
| 236 new md.CodeSyntax(@'\[\:((?:.|\n)*?)\:\]')); | 259 new md.CodeSyntax(@'\[\:((?:.|\n)*?)\:\]')); |
| 237 | 260 |
| 238 md.setImplicitLinkResolver((name) => resolveNameReference(name, | 261 md.setImplicitLinkResolver((name) => resolveNameReference(name, |
| 239 library: _currentLibrary, type: _currentType, | 262 library: _currentLibrary, type: _currentType, |
| 240 member: _currentMember)); | 263 member: _currentMember)); |
| 241 } | 264 } |
| 242 | 265 |
| 243 void document(String entrypoint) { | 266 void document([String entrypoint]) { |
| 244 var oldDietParse = options.dietParse; | 267 var oldDietParse = options.dietParse; |
| 245 try { | 268 try { |
| 246 options.dietParse = true; | 269 options.dietParse = true; |
| 247 | 270 |
| 248 // Handle the built-in entrypoints. | 271 // If we have an entrypoint, process it. Otherwise, just use whatever |
| 249 switch (entrypoint) { | 272 // libraries have been previously loaded by the calling code. |
| 250 case 'corelib': | 273 if (entrypoint != null) { |
| 251 world.getOrAddLibrary('dart:core'); | 274 world.processDartScript(entrypoint); |
| 252 world.getOrAddLibrary('dart:coreimpl'); | |
| 253 world.getOrAddLibrary('dart:json'); | |
| 254 world.getOrAddLibrary('dart:isolate'); | |
| 255 world.process(); | |
| 256 break; | |
| 257 | |
| 258 case 'dom': | |
| 259 world.getOrAddLibrary('dart:core'); | |
| 260 world.getOrAddLibrary('dart:coreimpl'); | |
| 261 world.getOrAddLibrary('dart:json'); | |
| 262 world.getOrAddLibrary('dart:dom'); | |
| 263 world.getOrAddLibrary('dart:isolate'); | |
| 264 world.process(); | |
| 265 break; | |
| 266 | |
| 267 case 'html': | |
| 268 world.getOrAddLibrary('dart:core'); | |
| 269 world.getOrAddLibrary('dart:coreimpl'); | |
| 270 world.getOrAddLibrary('dart:json'); | |
| 271 world.getOrAddLibrary('dart:dom'); | |
| 272 world.getOrAddLibrary('dart:html'); | |
| 273 world.getOrAddLibrary('dart:isolate'); | |
| 274 world.process(); | |
| 275 break; | |
| 276 | |
| 277 default: | |
| 278 // Normal entrypoint script. | |
| 279 world.processDartScript(entrypoint); | |
| 280 } | 275 } |
| 281 | 276 |
| 282 world.resolveAll(); | 277 world.resolveAll(); |
| 283 | 278 |
| 284 // Sort the libraries by name (not key). | 279 // Sort the libraries by name (not key). |
| 285 _sortedLibraries = world.libraries.getValues(); | 280 _sortedLibraries = world.libraries.getValues(); |
| 286 _sortedLibraries.sort((a, b) { | 281 _sortedLibraries.sort((a, b) { |
| 287 return a.name.toUpperCase().compareTo(b.name.toUpperCase()); | 282 return a.name.toUpperCase().compareTo(b.name.toUpperCase()); |
| 288 }); | 283 }); |
| 289 | 284 |
| (...skipping 984 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1274 | 1269 |
| 1275 return new md.Element.text('code', name); | 1270 return new md.Element.text('code', name); |
| 1276 } | 1271 } |
| 1277 | 1272 |
| 1278 // TODO(rnystrom): Move into SourceSpan? | 1273 // TODO(rnystrom): Move into SourceSpan? |
| 1279 int getSpanColumn(SourceSpan span) { | 1274 int getSpanColumn(SourceSpan span) { |
| 1280 final line = span.file.getLine(span.start); | 1275 final line = span.file.getLine(span.start); |
| 1281 return span.file.getColumn(line, span.start); | 1276 return span.file.getColumn(line, span.start); |
| 1282 } | 1277 } |
| 1283 } | 1278 } |
| OLD | NEW |