| OLD | NEW |
| 1 #!/usr/bin/env dart | 1 #!/usr/bin/env dart |
| 2 | 2 |
| 3 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 3 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 4 // for details. All rights reserved. Use of this source code is governed by a | 4 // for details. All rights reserved. Use of this source code is governed by a |
| 5 // BSD-style license that can be found in the LICENSE file. | 5 // BSD-style license that can be found in the LICENSE file. |
| 6 | 6 |
| 7 import 'dart:convert'; | 7 import 'dart:convert'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 | 9 |
| 10 import 'package:args/args.dart'; | 10 import 'package:args/args.dart'; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 if (_isDartFile(file)) { | 106 if (_isDartFile(file)) { |
| 107 if (_isPatchFile(file) && !paths.contains(file.path)) { | 107 if (_isPatchFile(file) && !paths.contains(file.path)) { |
| 108 _log('Skipping patch file "${file.path}"'); | 108 _log('Skipping patch file "${file.path}"'); |
| 109 return; | 109 return; |
| 110 } | 110 } |
| 111 try { | 111 try { |
| 112 var buffer = new StringBuffer(); | 112 var buffer = new StringBuffer(); |
| 113 var rawSource = file.readAsStringSync(); | 113 var rawSource = file.readAsStringSync(); |
| 114 var formatted = _format(rawSource, CodeKind.COMPILATION_UNIT); | 114 var formatted = _format(rawSource, CodeKind.COMPILATION_UNIT); |
| 115 if (overwriteFileContents) { | 115 if (overwriteFileContents) { |
| 116 file.writeAsStringSync(formatted); | 116 // Only touch files files whose contents will be changed |
| 117 if (rawSource != formatted) { |
| 118 file.writeAsStringSync(formatted); |
| 119 } |
| 117 } else { | 120 } else { |
| 118 print(formatted); | 121 print(formatted); |
| 119 } | 122 } |
| 120 } catch (e) { | 123 } catch (e) { |
| 121 _log('Unable to format "${file.path}": $e'); | 124 _log('Unable to format "${file.path}": $e'); |
| 122 } | 125 } |
| 123 } | 126 } |
| 124 } | 127 } |
| 125 | 128 |
| 126 _isPatchFile(file) => file.path.endsWith('_patch.dart'); | 129 _isPatchFile(file) => file.path.endsWith('_patch.dart'); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 'offset': formatResult.selection.offset, | 199 'offset': formatResult.selection.offset, |
| 197 'length': formatResult.selection.length | 200 'length': formatResult.selection.length |
| 198 } | 201 } |
| 199 }); | 202 }); |
| 200 | 203 |
| 201 /// Log the given [msg]. | 204 /// Log the given [msg]. |
| 202 _log(String msg) { | 205 _log(String msg) { |
| 203 //TODO(pquitslund): add proper log support | 206 //TODO(pquitslund): add proper log support |
| 204 print(msg); | 207 print(msg); |
| 205 } | 208 } |
| OLD | NEW |