| 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 import "dart:io"; | 5 import "dart:io"; |
| 6 import "package:args/args.dart"; | 6 import "package:args/args.dart"; |
| 7 | 7 |
| 8 bool cleanBuild; | 8 bool cleanBuild; |
| 9 bool fullBuild; | 9 bool fullBuild; |
| 10 bool useMachineInterface; | 10 bool useMachineInterface; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 | 63 |
| 64 cleanBuild = args["clean"]; | 64 cleanBuild = args["clean"]; |
| 65 fullBuild = args["full"]; | 65 fullBuild = args["full"]; |
| 66 } | 66 } |
| 67 | 67 |
| 68 /** | 68 /** |
| 69 * Delete all generated files. | 69 * Delete all generated files. |
| 70 */ | 70 */ |
| 71 void handleCleanCommand() { | 71 void handleCleanCommand() { |
| 72 Directory current = new Directory.current(); | 72 Directory current = new Directory.current(); |
| 73 current.list(recursive: true).onFile = _maybeClean; | 73 current.list(recursive: true).listen((entity) { |
| 74 if (entity.isFile) _maybeClean(entity.path) |
| 75 }); |
| 74 } | 76 } |
| 75 | 77 |
| 76 /** | 78 /** |
| 77 * Recursively scan the current directory looking for .foo files to process. | 79 * Recursively scan the current directory looking for .foo files to process. |
| 78 */ | 80 */ |
| 79 void handleFullBuild() { | 81 void handleFullBuild() { |
| 80 var files = <String>[]; | 82 var files = <String>[]; |
| 81 var lister = new Directory.current().list(recursive: true); | 83 new Directory.current().list(recursive: true).listen( |
| 82 | 84 (entity) { |
| 83 lister.onFile = (file) => files.add(file); | 85 if (entity.isFile) files.add(entity.path); |
| 84 lister.onDone = (_) => handleChangedFiles(files); | 86 }, |
| 87 onDone: () => handleChangedFiles(files)); |
| 85 } | 88 } |
| 86 | 89 |
| 87 /** | 90 /** |
| 88 * Process the given list of changed files. | 91 * Process the given list of changed files. |
| 89 */ | 92 */ |
| 90 void handleChangedFiles(List<String> files) { | 93 void handleChangedFiles(List<String> files) { |
| 91 files.forEach(_processFile); | 94 files.forEach(_processFile); |
| 92 } | 95 } |
| 93 | 96 |
| 94 /** | 97 /** |
| 95 * Process the given list of removed files. | 98 * Process the given list of removed files. |
| 96 */ | 99 */ |
| 97 void handleRemovedFiles(List<String> files) { | 100 void handleRemovedFiles(List<String> files) { |
| 98 | 101 |
| 99 } | 102 } |
| 100 | 103 |
| 101 /** | 104 /** |
| 102 * Convert a .foo file to a .foobar file. | 105 * Convert a .foo file to a .foobar file. |
| 103 */ | 106 */ |
| 104 void _processFile(String arg) { | 107 void _processFile(String arg) { |
| 105 if (arg.endsWith(".foo")) { | 108 if (arg.endsWith(".foo")) { |
| 106 print("processing: ${arg}"); | 109 print("processing: ${arg}"); |
| 107 | 110 |
| 108 File file = new File(arg); | 111 File file = new File(arg); |
| 109 | 112 |
| 110 String contents = file.readAsStringSync(); | 113 String contents = file.readAsStringSync(); |
| 111 | 114 |
| 112 File outFile = new File("${arg}bar"); | 115 File outFile = new File("${arg}bar"); |
| 113 | 116 |
| 114 OutputStream out = outFile.openOutputStream(); | 117 var out = outFile.openWrite(); |
| 115 out.writeString("// processed from ${file.name}:\n"); | 118 out.addString("// processed from ${file.name}:\n"); |
| 116 if (contents != null) { | 119 if (contents != null) { |
| 117 out.writeString(contents); | 120 out.addString(contents); |
| 118 } | 121 } |
| 119 out.close(); | 122 out.close(); |
| 120 | 123 |
| 121 _findErrors(arg); | 124 _findErrors(arg); |
| 122 | 125 |
| 123 print("wrote: ${outFile.name}"); | 126 print("wrote: ${outFile.name}"); |
| 124 } | 127 } |
| 125 } | 128 } |
| 126 | 129 |
| 127 void _findErrors(String arg) { | 130 void _findErrors(String arg) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 141 } | 144 } |
| 142 | 145 |
| 143 /** | 146 /** |
| 144 * If this file is a generated file (based on the extension), delete it. | 147 * If this file is a generated file (based on the extension), delete it. |
| 145 */ | 148 */ |
| 146 void _maybeClean(String file) { | 149 void _maybeClean(String file) { |
| 147 if (file.endsWith(".foobar")) { | 150 if (file.endsWith(".foobar")) { |
| 148 new File(file).delete(); | 151 new File(file).delete(); |
| 149 } | 152 } |
| 150 } | 153 } |
| OLD | NEW |