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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 | 111 |
112 if (includeSource != null) dartdoc.includeSource = includeSource; | 112 if (includeSource != null) dartdoc.includeSource = includeSource; |
113 if (mode != null) dartdoc.mode = mode; | 113 if (mode != null) dartdoc.mode = mode; |
114 if (outputDir != null) dartdoc.outputDir = outputDir; | 114 if (outputDir != null) dartdoc.outputDir = outputDir; |
115 if (generateAppCache != null) dartdoc.generateAppCache = generateAppCache; | 115 if (generateAppCache != null) dartdoc.generateAppCache = generateAppCache; |
116 | 116 |
117 cleanOutputDirectory(dartdoc.outputDir); | 117 cleanOutputDirectory(dartdoc.outputDir); |
118 | 118 |
119 // Compile the client-side code to JS. | 119 // Compile the client-side code to JS. |
120 final clientScript = (dartdoc.mode == MODE_STATIC) ? 'static' : 'live-nav'; | 120 final clientScript = (dartdoc.mode == MODE_STATIC) ? 'static' : 'live-nav'; |
121 final Future scriptCompiled = compileScript(compilerPath, libDir, | 121 final Future scriptCompiled = compileScript(compilerPath, |
122 '$scriptDir/client-$clientScript.dart', | 122 '$scriptDir/client-$clientScript.dart', |
123 '${dartdoc.outputDir}/client-$clientScript.js'); | 123 '${dartdoc.outputDir}/client-$clientScript.js'); |
124 | 124 |
125 final Future filesCopied = copyFiles('$scriptDir/static', dartdoc.outputDir); | 125 final Future filesCopied = copyFiles('$scriptDir/static', dartdoc.outputDir); |
126 | 126 |
127 Futures.wait([scriptCompiled, filesCopied]).then((_) { | 127 Futures.wait([scriptCompiled, filesCopied]).then((_) { |
128 dartdoc.document(entrypoint); | 128 dartdoc.document(entrypoint); |
129 }); | 129 }); |
130 | 130 |
131 print('Documented ${dartdoc._totalLibraries} libraries, ' + | 131 print('Documented ${dartdoc._totalLibraries} libraries, ' + |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 }); | 180 }); |
181 }; | 181 }; |
182 lister.onDone = (done) => completer.complete(true); | 182 lister.onDone = (done) => completer.complete(true); |
183 return completer.future; | 183 return completer.future; |
184 } | 184 } |
185 | 185 |
186 /** | 186 /** |
187 * Compiles the given Dart script to a JavaScript file at [jsPath] using the | 187 * Compiles the given Dart script to a JavaScript file at [jsPath] using the |
188 * Dart-to-JS compiler located at [compilerPath]. | 188 * Dart-to-JS compiler located at [compilerPath]. |
189 */ | 189 */ |
190 Future compileScript(String compilerPath, String libDir, | 190 Future compileScript(String compilerPath, String dartPath, String jsPath) { |
191 String dartPath, String jsPath) { | |
192 final completer = new Completer(); | 191 final completer = new Completer(); |
193 onExit(ProcessResult result) { | 192 onExit(ProcessResult result) { |
194 if (result.exitCode != 0) { | 193 if (result.exitCode != 0) { |
195 final message = 'Non-zero exit code from $compilerPath'; | 194 final message = 'Non-zero exit code from $compilerPath'; |
196 print('$message.'); | 195 print('$message.'); |
197 print(result.stdout); | 196 print(result.stdout); |
198 print(result.stderr); | 197 print(result.stderr); |
199 throw message; | 198 throw message; |
200 } | 199 } |
201 completer.complete(true); | 200 completer.complete(true); |
202 } | 201 } |
203 | 202 |
204 onError(error) { | 203 onError(error) { |
205 final message = 'Error trying to execute $compilerPath. Error: $error'; | 204 final message = 'Error trying to execute $compilerPath. Error: $error'; |
206 print('$message.'); | 205 print('$message.'); |
207 throw message; | 206 throw message; |
208 } | 207 } |
209 | 208 |
210 print('Compiling $dartPath to $jsPath'); | 209 print('Compiling $dartPath to $jsPath'); |
211 var processFuture = Process.run(compilerPath, [ | 210 var processFuture = Process.run(compilerPath, ['--out=$jsPath', dartPath]); |
212 '--libdir=$libDir', '--out=$jsPath', | |
213 '--compile-only', '--enable-type-checks', '--warnings-as-errors', | |
214 dartPath]); | |
215 | |
216 processFuture.handleException(onError); | 211 processFuture.handleException(onError); |
217 processFuture.then(onExit); | 212 processFuture.then(onExit); |
218 | 213 |
219 return completer.future; | 214 return completer.future; |
220 } | 215 } |
221 | 216 |
222 class Dartdoc { | 217 class Dartdoc { |
223 | 218 |
224 /** Set to `false` to not include the source code in the generated docs. */ | 219 /** Set to `false` to not include the source code in the generated docs. */ |
225 bool includeSource = true; | 220 bool includeSource = true; |
(...skipping 1123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1349 if (filename.endsWith('appcache.manifest')) { | 1344 if (filename.endsWith('appcache.manifest')) { |
1350 return; | 1345 return; |
1351 } | 1346 } |
1352 var relativePath = filename.substring(pathPrefixLength + 1); | 1347 var relativePath = filename.substring(pathPrefixLength + 1); |
1353 write("$relativePath\n"); | 1348 write("$relativePath\n"); |
1354 }; | 1349 }; |
1355 toCache.onDone = (done) => endFile(); | 1350 toCache.onDone = (done) => endFile(); |
1356 toCache.list(recursive: true); | 1351 toCache.list(recursive: true); |
1357 } | 1352 } |
1358 } | 1353 } |
OLD | NEW |