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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 /** | 158 /** |
159 * Copies all of the files in the directory [from] to [to]. Does *not* | 159 * Copies all of the files in the directory [from] to [to]. Does *not* |
160 * recursively copy subdirectories. | 160 * recursively copy subdirectories. |
161 * | 161 * |
162 * Note: runs asynchronously, so you won't see any files copied until after the | 162 * Note: runs asynchronously, so you won't see any files copied until after the |
163 * event loop has had a chance to pump (i.e. after `main()` has returned). | 163 * event loop has had a chance to pump (i.e. after `main()` has returned). |
164 */ | 164 */ |
165 Future copyFiles(String from, String to) { | 165 Future copyFiles(String from, String to) { |
166 final completer = new Completer(); | 166 final completer = new Completer(); |
167 final fromDir = new Directory(from); | 167 final fromDir = new Directory(from); |
168 fromDir.onFile = (path) { | 168 final lister = fromDir.list(recursive: false); |
| 169 |
| 170 lister.onFile = (path) { |
169 final name = basename(path); | 171 final name = basename(path); |
170 // TODO(rnystrom): Hackish. Ignore 'hidden' files like .DS_Store. | 172 // TODO(rnystrom): Hackish. Ignore 'hidden' files like .DS_Store. |
171 if (name.startsWith('.')) return; | 173 if (name.startsWith('.')) return; |
172 | 174 |
173 new File(path).readAsBytes((bytes) { | 175 new File(path).readAsBytes().then((bytes) { |
174 final outFile = new File('$to/$name'); | 176 final outFile = new File('$to/$name'); |
175 final stream = outFile.openOutputStream(FileMode.WRITE); | 177 final stream = outFile.openOutputStream(FileMode.WRITE); |
176 stream.write(bytes, copyBuffer: false); | 178 stream.write(bytes, copyBuffer: false); |
177 stream.close(); | 179 stream.close(); |
178 }); | 180 }); |
179 }; | 181 }; |
180 fromDir.onDone = (done) => completer.complete(true); | 182 lister.onDone = (done) => completer.complete(true); |
181 fromDir.list(recursive: false); | |
182 return completer.future; | 183 return completer.future; |
183 } | 184 } |
184 | 185 |
185 /** | 186 /** |
186 * 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 |
187 * Dart-to-JS compiler located at [compilerPath]. | 188 * Dart-to-JS compiler located at [compilerPath]. |
188 */ | 189 */ |
189 Future compileScript(String compilerPath, String libDir, | 190 Future compileScript(String compilerPath, String libDir, |
190 String dartPath, String jsPath) { | 191 String dartPath, String jsPath) { |
191 final completer = new Completer(); | 192 final completer = new Completer(); |
192 onExit(int exitCode, String stdout, String stderr) { | 193 onExit(ProcessResult result) { |
193 if (exitCode != 0) { | 194 if (result.exitCode != 0) { |
194 final message = 'Non-zero exit code from $compilerPath'; | 195 final message = 'Non-zero exit code from $compilerPath'; |
195 print('$message.'); | 196 print('$message.'); |
196 print(stdout); | 197 print(result.stdout); |
197 print(stderr); | 198 print(result.stderr); |
198 throw message; | 199 throw message; |
199 } | 200 } |
200 completer.complete(true); | 201 completer.complete(true); |
201 } | 202 } |
202 | 203 |
203 onError(error) { | 204 onError(error) { |
204 final message = 'Error trying to execute $compilerPath. Error: $error'; | 205 final message = 'Error trying to execute $compilerPath. Error: $error'; |
205 print('$message.'); | 206 print('$message.'); |
206 throw message; | 207 throw message; |
207 } | 208 } |
208 | 209 |
209 print('Compiling $dartPath to $jsPath'); | 210 print('Compiling $dartPath to $jsPath'); |
210 new Process.run(compilerPath, [ | 211 var processFuture = Process.run(compilerPath, [ |
211 '--libdir=$libDir', '--out=$jsPath', | 212 '--libdir=$libDir', '--out=$jsPath', |
212 '--compile-only', '--enable-type-checks', '--warnings-as-errors', | 213 '--compile-only', '--enable-type-checks', '--warnings-as-errors', |
213 dartPath], null, onExit).onError = onError; | 214 dartPath]); |
| 215 |
| 216 processFuture.handleException(onError); |
| 217 processFuture.then(onExit); |
| 218 |
214 return completer.future; | 219 return completer.future; |
215 } | 220 } |
216 | 221 |
217 class Dartdoc { | 222 class Dartdoc { |
218 | 223 |
219 /** Set to `false` to not include the source code in the generated docs. */ | 224 /** Set to `false` to not include the source code in the generated docs. */ |
220 bool includeSource = true; | 225 bool includeSource = true; |
221 | 226 |
222 /** | 227 /** |
223 * Dartdoc can generate docs in a few different ways based on how dynamic you | 228 * Dartdoc can generate docs in a few different ways based on how dynamic you |
(...skipping 1120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1344 if (filename.endsWith('appcache.manifest')) { | 1349 if (filename.endsWith('appcache.manifest')) { |
1345 return; | 1350 return; |
1346 } | 1351 } |
1347 var relativePath = filename.substring(pathPrefixLength + 1); | 1352 var relativePath = filename.substring(pathPrefixLength + 1); |
1348 write("$relativePath\n"); | 1353 write("$relativePath\n"); |
1349 }; | 1354 }; |
1350 toCache.onDone = (done) => endFile(); | 1355 toCache.onDone = (done) => endFile(); |
1351 toCache.list(recursive: true); | 1356 toCache.list(recursive: true); |
1352 } | 1357 } |
1353 } | 1358 } |
OLD | NEW |