| OLD | NEW |
| 1 /// | 1 /// |
| 2 /// Script to create boilerplate for a Polymer element. | 2 /// Script to create boilerplate for a Polymer element. |
| 3 /// Produces new .html entry point for a polymer app and updates the | 3 /// Produces new .html entry point for a polymer app and updates the |
| 4 /// pubspec.yaml to reflect it. | 4 /// pubspec.yaml to reflect it. |
| 5 /// | 5 /// |
| 6 /// Run this script with pub run: | 6 /// Run this script with pub run: |
| 7 /// | 7 /// |
| 8 /// pub run polymer:new_entry <html_file> | 8 /// pub run polymer:new_entry <html_file> |
| 9 /// | 9 /// |
| 10 import 'dart:io'; | 10 import 'dart:io'; |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 insertionPoint = transformersSourceSpan.start.offset; | 152 insertionPoint = transformersSourceSpan.start.offset; |
| 153 textToInsert = '- '; | 153 textToInsert = '- '; |
| 154 } else { | 154 } else { |
| 155 insertionPoint = sourceSpan.start.offset; | 155 insertionPoint = sourceSpan.start.offset; |
| 156 pubspecText = '${pubspecText.substring(0, insertionPoint)}' | 156 pubspecText = '${pubspecText.substring(0, insertionPoint)}' |
| 157 '${pubspecText.substring(sourceSpan.end.offset)}'; | 157 '${pubspecText.substring(sourceSpan.end.offset)}'; |
| 158 } | 158 } |
| 159 } else { | 159 } else { |
| 160 // There were no transformers at all. | 160 // There were no transformers at all. |
| 161 insertionPoint = pubspecText.length; | 161 insertionPoint = pubspecText.length; |
| 162 textToInsert = 'transformers:\n- '; | 162 var optionalNewline = pubspecText.endsWith('\n') ? '' : '\n'; |
| 163 textToInsert = '${optionalNewline}transformers:\n- '; |
| 163 entryPoints = [entryPoint]; | 164 entryPoints = [entryPoint]; |
| 164 } | 165 } |
| 165 | 166 |
| 166 // TODO(dgrove): Once dartbug.com/20409 is addressed, use that here. | 167 // TODO(dgrove): Once dartbug.com/20409 is addressed, use that here. |
| 167 var entryPointsText = entryPoints.map((e) => ' - $e').join('\n'); | 168 var entryPointsText = entryPoints.map((e) => ' - $e').join('\n'); |
| 168 | 169 |
| 169 textToInsert = | 170 textToInsert = |
| 170 '''${textToInsert}polymer: | 171 '''${textToInsert}polymer: |
| 171 entry_points: | 172 entry_points: |
| 172 $entryPointsText'''; | 173 $entryPointsText'''; |
| 173 | 174 |
| 174 | 175 |
| 175 if (insertionPoint == pubspecText.length) { | 176 if (insertionPoint == pubspecText.length) { |
| 176 pubspecText = '${pubspecText}${textToInsert}'; | 177 pubspecText = '${pubspecText}${textToInsert}'; |
| 177 } else { | 178 } else { |
| 178 pubspecText = '${pubspecText.substring(0, insertionPoint)}' | 179 pubspecText = '${pubspecText.substring(0, insertionPoint)}' |
| 179 '${textToInsert}\n${pubspecText.substring(insertionPoint)}'; | 180 '${textToInsert}\n${pubspecText.substring(insertionPoint)}'; |
| 180 } | 181 } |
| 181 | 182 |
| 182 _writePubspec(pubspecPath, pubspecText); | 183 _writePubspec(pubspecPath, pubspecText); |
| 183 return true; | 184 return true; |
| 184 } | 185 } |
| 185 | 186 |
| 186 _writePubspec(String pubspecPath, String text) { | 187 _writePubspec(String pubspecPath, String text) { |
| 187 new File(pubspecPath).writeAsStringSync(text); | 188 new File(pubspecPath).writeAsStringSync(text); |
| 188 } | 189 } |
| OLD | NEW |