Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: pkg/polymer/bin/new_entry.dart

Issue 473663002: Fix bug that prevent the entry point from being added to the pubspec (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 ' because of already-existing transformer|polymer section'); 103 ' because of already-existing transformer|polymer section');
104 } 104 }
105 return false; 105 return false;
106 } else if (e['polymer'].keys.length > 1) { 106 } else if (e['polymer'].keys.length > 1) {
107 // TODO(dgrove): handle the case where there are additional sections 107 // TODO(dgrove): handle the case where there are additional sections
108 // in the polymer transformer. 108 // in the polymer transformer.
109 throw new UnimplementedError('Cannot handle non-entry_point entries ' 109 throw new UnimplementedError('Cannot handle non-entry_point entries '
110 'for polymer transformer'); 110 'for polymer transformer');
111 } else { 111 } else {
112 var existing = e['polymer']['entry_points']; 112 var existing = e['polymer']['entry_points'];
113 entryPoints = existing == null ? [] : 113 entryPoints = (existing == null ? [] :
114 (existing is String ? [existing] : existing.toList()); 114 (existing is String ? [existing] : existing.toList()));
115 115
116 if (entryPoints.contains(entryPoint)) return false; 116 if (entryPoints.contains(entryPoint)) return false;
117 entryPoints.add(entryPoint); 117 entryPoints.add(entryPoint);
118 118
119 sourceSpan = e.span; 119 sourceSpan = e.span;
120 } 120 }
121 } 121 }
122 122
123 if (sourceSpan == null) { 123 if (sourceSpan == null) {
124 // There were no polymer transformers. 124 // There were no polymer transformers.
125 insertionPoint = transformersSourceSpan.start.offset; 125 insertionPoint = transformersSourceSpan.start.offset;
126 textToInsert = '- '; 126 textToInsert = '- ';
127 } else { 127 } else {
128 insertionPoint = sourceSpan.start.offset; 128 insertionPoint = sourceSpan.start.offset;
129 pubspecText = '${pubspecText.substring(0, insertionPoint)}' 129 pubspecText = '${pubspecText.substring(0, insertionPoint)}'
130 '${pubspecText.substring(sourceSpan.end.offset)}'; 130 '${pubspecText.substring(sourceSpan.end.offset)}';
131 } 131 }
132 } else { 132 } else {
133 // There were no transformers at all. 133 // There were no transformers at all.
134 insertionPoint = pubspecText.length; 134 insertionPoint = pubspecText.length;
135 textToInsert = 'transformers:\n- '; 135 textToInsert = 'transformers:\n- ';
136 entryPoints = [entryPoint];
136 } 137 }
137 138
138 // TODO(dgrove): Once dartbug.com/20409 is addressed, use that here. 139 // TODO(dgrove): Once dartbug.com/20409 is addressed, use that here.
139 var entryPointsText = entryPoints.map((e) => ' - $e').join('\n'); 140 var entryPointsText = entryPoints.map((e) => ' - $e').join('\n');
140 141
141 textToInsert = 142 textToInsert =
142 '''${textToInsert}polymer: 143 '''${textToInsert}polymer:
143 entry_points: 144 entry_points:
144 $entryPointsText'''; 145 $entryPointsText''';
145 146
146 147
147 if (insertionPoint == pubspecText.length) { 148 if (insertionPoint == pubspecText.length) {
148 pubspecText = '${pubspecText}${textToInsert}'; 149 pubspecText = '${pubspecText}${textToInsert}';
149 } else { 150 } else {
150 pubspecText = '${pubspecText.substring(0, insertionPoint)}' 151 pubspecText = '${pubspecText.substring(0, insertionPoint)}'
151 '${textToInsert}\n${pubspecText.substring(insertionPoint)}'; 152 '${textToInsert}\n${pubspecText.substring(insertionPoint)}';
152 } 153 }
153 154
154 _writePubspec(pubspecPath, pubspecText); 155 _writePubspec(pubspecPath, pubspecText);
155 return true; 156 return true;
156 } 157 }
157 158
158 _writePubspec(String pubspecPath, String text) { 159 _writePubspec(String pubspecPath, String text) {
159 new File(pubspecPath).writeAsStringSync(text); 160 new File(pubspecPath).writeAsStringSync(text);
160 } 161 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698