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'; |
11 import 'package:args/args.dart'; | 11 import 'package:args/args.dart'; |
12 import 'package:path/path.dart' as path; | 12 import 'package:path/path.dart' as path; |
13 import 'package:yaml/yaml.dart'; | 13 import 'package:yaml/yaml.dart'; |
14 import 'package:source_span/source_span.dart'; | 14 import 'package:source_span/source_span.dart'; |
15 | 15 |
16 void printUsage() { | 16 void printUsage() { |
17 print('pub run polymer:new_entry entry_point_file.html'); | 17 print('pub run polymer:new_entry entry_point_file.html'); |
18 } | 18 } |
19 | 19 |
20 void main(List<String> args) { | 20 void main(List<String> args) { |
21 var parser = new ArgParser(allowTrailingOptions: true); | 21 var parser = new ArgParser(allowTrailingOptions: true); |
22 parser.addFlag('help', abbr: 'h'); | 22 parser.addFlag('help', abbr: 'h'); |
23 var entryPoint; | 23 var entryPoint; |
24 | 24 |
25 try { | 25 try { |
26 var options = parser.parse(args); | 26 var options = parser.parse(args); |
27 if (options['help'] != null) { | 27 if (options['help']) { |
28 printUsage(); | 28 printUsage(); |
29 return; | 29 return; |
30 } | 30 } |
31 entryPoint = options.rest[0]; | 31 entryPoint = options.rest[0]; |
32 } catch(e) { | 32 } catch(e) { |
33 print('$e\n'); | 33 print('$e\n'); |
34 printUsage(); | 34 printUsage(); |
35 exitCode = 1; | 35 exitCode = 1; |
36 return; | 36 return; |
37 } | 37 } |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 '${textToInsert}\n${pubspecText.substring(insertionPoint)}'; | 179 '${textToInsert}\n${pubspecText.substring(insertionPoint)}'; |
180 } | 180 } |
181 | 181 |
182 _writePubspec(pubspecPath, pubspecText); | 182 _writePubspec(pubspecPath, pubspecText); |
183 return true; | 183 return true; |
184 } | 184 } |
185 | 185 |
186 _writePubspec(String pubspecPath, String text) { | 186 _writePubspec(String pubspecPath, String text) { |
187 new File(pubspecPath).writeAsStringSync(text); | 187 new File(pubspecPath).writeAsStringSync(text); |
188 } | 188 } |
OLD | NEW |