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

Side by Side Diff: pkg/polymer/lib/deploy.dart

Issue 23576012: Added .scss transform (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: cleanup Created 7 years, 3 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
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 /**
6 * Temporary deploy command used to create a version of the app that can be
Siggi Cherem (dart-lang) 2013/09/08 20:31:33 Let's revert the changes to lib/deploy.dart bin/de
7 * compiled with dart2js and deployed. Following pub layout conventions, this
8 * script will treat any HTML file under a package 'web/' and 'test/'
9 * directories as entry points.
10 *
11 * From an application package you can run deploy by creating a small program
12 * as follows:
13 *
14 * import "package:polymer/deploy.dart" as deploy;
15 * main() => deploy.main();
16 *
17 * This library should go away once `pub deploy` can be configured to run
18 * barback transformers.
19 */
20 library polymer.deploy; 5 library polymer.deploy;
21 6
22 import 'dart:async'; 7 import 'dart:async';
23 import 'dart:convert'; 8 import 'dart:convert';
24 import 'dart:io'; 9 import 'dart:io';
25 10
26 import 'package:barback/barback.dart'; 11 import 'package:barback/barback.dart';
27 import 'package:path/path.dart' as path; 12 import 'package:path/path.dart' as path;
28 import 'package:polymer/src/transform.dart' show phases; 13 import 'package:polymer/src/transform.dart' show phases;
29 import 'package:stack_trace/stack_trace.dart'; 14 import 'package:stack_trace/stack_trace.dart';
30 import 'package:yaml/yaml.dart'; 15 import 'package:yaml/yaml.dart';
31 import 'package:args/args.dart';
32
33 main() {
34 var args = _parseArgs(new Options().arguments);
35 if (args == null) return;
36 print('polymer/deploy.dart: creating a deploy target for "$_currentPackage"');
37 var outDir = args['out'];
38 _run(args['webdir'], outDir).then(
39 (_) => print('Done! All files written to "$outDir"'));
40 }
41 16
42 /** 17 /**
43 * API exposed for testing purposes. Runs this deploy command but prentend that 18 * API exposed for testing purposes. Runs this deploy command but prentend that
44 * the sources under [webDir] belong to package 'test'. 19 * the sources under [webDir] belong to package 'test'.
45 */ 20 */
46 Future runForTest(String webDir, String outDir) { 21 Future runForTest(String webDir, String outDir) {
47 _currentPackage = 'test'; 22 currentPackage = 'test';
48 23
49 // associate package dirs with their location in the repo: 24 // associate package dirs with their location in the repo:
50 _packageDirs = {'test' : '.'}; 25 _packageDirs = {'test' : '.'};
51 addPackages(String dir) { 26 addPackages(String dir) {
52 for (var packageDir in new Directory(dir).listSync().map((d) => d.path)) { 27 for (var packageDir in new Directory(dir).listSync().map((d) => d.path)) {
53 _packageDirs[path.basename(packageDir)] = packageDir; 28 _packageDirs[path.basename(packageDir)] = packageDir;
54 } 29 }
55 } 30 }
56 addPackages('..'); 31 addPackages('..');
57 addPackages('../third_party'); 32 addPackages('../third_party');
58 addPackages('../../third_party/pkg'); 33 addPackages('../../third_party/pkg');
59 return _run(webDir, outDir); 34 return run(webDir, outDir);
60 } 35 }
61 36
62 Future _run(String webDir, String outDir) { 37 Future run(String webDir, String outDir) {
63 var barback = new Barback(new _PolymerDeployProvider()); 38 var barback = new Barback(new _PolymerDeployProvider());
64 _initializeBarback(barback, webDir); 39 _initializeBarback(barback, webDir);
65 _attachListeners(barback); 40 _attachListeners(barback);
66 return _emitAllFiles(barback, webDir, outDir); 41 return _emitAllFiles(barback, webDir, outDir);
67 } 42 }
68 43
69 /** Tell barback which transformers to use and which assets to process. */ 44 /** Tell barback which transformers to use and which assets to process. */
70 void _initializeBarback(Barback barback, String webDir) { 45 void _initializeBarback(Barback barback, String webDir) {
71 var assets = []; 46 var assets = [];
72 for (var package in _packageDirs.keys) { 47 for (var package in _packageDirs.keys) {
73 // Do not process packages like 'polymer' where there is nothing to do. 48 // Do not process packages like 'polymer' where there is nothing to do.
74 if (_ignoredPackages.contains(package)) continue; 49 if (_ignoredPackages.contains(package)) continue;
75 barback.updateTransformers(package, phases); 50 barback.updateTransformers(package, phases);
76 51
77 // notify barback to process anything under 'lib' and 'asset' 52 // notify barback to process anything under 'lib' and 'asset'
78 for (var filepath in _listDir(package, 'lib')) { 53 for (var filepath in _listDir(package, 'lib')) {
79 assets.add(new AssetId(package, filepath)); 54 assets.add(new AssetId(package, filepath));
80 } 55 }
81 56
82 for (var filepath in _listDir(package, 'asset')) { 57 for (var filepath in _listDir(package, 'asset')) {
83 assets.add(new AssetId(package, filepath)); 58 assets.add(new AssetId(package, filepath));
84 } 59 }
85 } 60 }
86 61
87 // In case of the current package, include also 'web'. 62 // In case of the current package, include also 'web'.
88 for (var filepath in _listDir(_currentPackage, webDir)) { 63 for (var filepath in _listDir(currentPackage, webDir)) {
89 assets.add(new AssetId(_currentPackage, filepath)); 64 assets.add(new AssetId(currentPackage, filepath));
90 } 65 }
91 barback.updateSources(assets); 66 barback.updateSources(assets);
92 } 67 }
93 68
94 /** Return the relative path of each file under [subDir] in a [package]. */ 69 /** Return the relative path of each file under [subDir] in a [package]. */
95 Iterable<String> _listDir(String package, String subDir) { 70 Iterable<String> _listDir(String package, String subDir) {
96 var packageDir = _packageDirs[package]; 71 var packageDir = _packageDirs[package];
97 if (packageDir == null) return const []; 72 if (packageDir == null) return const [];
98 var dir = new Directory(path.join(packageDir, subDir)); 73 var dir = new Directory(path.join(packageDir, subDir));
99 if (!dir.existsSync()) return const []; 74 if (!dir.existsSync()) return const [];
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 * Emits all outputs of [barback] and copies files that we didn't process (like 106 * Emits all outputs of [barback] and copies files that we didn't process (like
132 * polymer's libraries). 107 * polymer's libraries).
133 */ 108 */
134 Future _emitAllFiles(Barback barback, String webDir, String outDir) { 109 Future _emitAllFiles(Barback barback, String webDir, String outDir) {
135 return barback.getAllAssets().then((assets) { 110 return barback.getAllAssets().then((assets) {
136 // Copy all the assets we transformed 111 // Copy all the assets we transformed
137 var futures = []; 112 var futures = [];
138 for (var asset in assets) { 113 for (var asset in assets) {
139 var id = asset.id; 114 var id = asset.id;
140 var filepath; 115 var filepath;
141 if (id.package == _currentPackage && id.path.startsWith('$webDir/')) { 116 if (id.package == currentPackage && id.path.startsWith('$webDir/')) {
142 filepath = path.join(outDir, id.path); 117 filepath = path.join(outDir, id.path);
143 } else if (id.path.startsWith('lib/')) { 118 } else if (id.path.startsWith('lib/')) {
144 filepath = path.join(outDir, webDir, 'packages', id.package, 119 filepath = path.join(outDir, webDir, 'packages', id.package,
145 id.path.substring(4)); 120 id.path.substring(4));
146 } else { 121 } else {
147 // TODO(sigmund): do something about other assets? 122 // TODO(sigmund): do something about other assets?
148 continue; 123 continue;
149 } 124 }
150 125
151 _ensureDir(path.dirname(filepath)); 126 _ensureDir(path.dirname(filepath));
(...skipping 28 matching lines...) Expand all
180 155
181 Future<Asset> getAsset(AssetId id) => 156 Future<Asset> getAsset(AssetId id) =>
182 new Future.value(new Asset.fromPath(id, path.join( 157 new Future.value(new Asset.fromPath(id, path.join(
183 _packageDirs[id.package], 158 _packageDirs[id.package],
184 // Assets always use the posix style paths 159 // Assets always use the posix style paths
185 path.joinAll(path.posix.split(id.path))))); 160 path.joinAll(path.posix.split(id.path)))));
186 } 161 }
187 162
188 163
189 /** The current package extracted from the pubspec.yaml file. */ 164 /** The current package extracted from the pubspec.yaml file. */
190 String _currentPackage = () { 165 String currentPackage = () {
191 var pubspec = new File('pubspec.yaml'); 166 var pubspec = new File('pubspec.yaml');
192 if (!pubspec.existsSync()) { 167 if (!pubspec.existsSync()) {
193 print('error: pubspec.yaml file not found, please run this script from ' 168 print('error: pubspec.yaml file not found, please run this script from '
194 'your package root directory.'); 169 'your package root directory.');
195 return null; 170 return null;
196 } 171 }
197 return loadYaml(pubspec.readAsStringSync())['name']; 172 return loadYaml(pubspec.readAsStringSync())['name'];
198 }(); 173 }();
199 174
200 /** 175 /**
201 * Maps package names to the path in the file system where to find the sources 176 * Maps package names to the path in the file system where to find the sources
202 * of such package. This map will contain an entry for the current package and 177 * of such package. This map will contain an entry for the current package and
203 * everything it depends on (extracted via `pub list-pacakge-dirs`). 178 * everything it depends on (extracted via `pub list-pacakge-dirs`).
204 */ 179 */
205 Map<String, String> _packageDirs = () { 180 Map<String, String> _packageDirs = () {
206 var pub = path.join(path.dirname(new Options().executable), 181 var pub = path.join(path.dirname(new Options().executable),
207 Platform.isWindows ? 'pub.bat' : 'pub'); 182 Platform.isWindows ? 'pub.bat' : 'pub');
208 var result = Process.runSync(pub, ['list-package-dirs']); 183 var result = Process.runSync(pub, ['list-package-dirs']);
209 if (result.exitCode != 0) { 184 if (result.exitCode != 0) {
210 print("unexpected error invoking 'pub':"); 185 print("unexpected error invoking 'pub':");
211 print(result.stdout); 186 print(result.stdout);
212 print(result.stderr); 187 print(result.stderr);
213 exit(result.exitCode); 188 exit(result.exitCode);
214 } 189 }
215 var map = JSON.decode(result.stdout)["packages"]; 190 var map = JSON.decode(result.stdout)["packages"];
216 map.forEach((k, v) { map[k] = path.dirname(v); }); 191 map.forEach((k, v) { map[k] = path.dirname(v); });
217 map[_currentPackage] = '.'; 192 map[currentPackage] = '.';
218 return map; 193 return map;
219 }(); 194 }();
220 195
221 /** 196 /**
222 * Internal packages used by polymer which we can copy directly to the output 197 * Internal packages used by polymer which we can copy directly to the output
223 * folder without having to process them with barback. 198 * folder without having to process them with barback.
224 */ 199 */
225 // TODO(sigmund): consider computing this list by recursively parsing 200 // TODO(sigmund): consider computing this list by recursively parsing
226 // pubspec.yaml files in the [_packageDirs]. 201 // pubspec.yaml files in the [_packageDirs].
227 final Set<String> _ignoredPackages = 202 final Set<String> _ignoredPackages =
228 (const [ 'analyzer_experimental', 'args', 'barback', 'browser', 'csslib', 203 (const [ 'analyzer_experimental', 'args', 'barback', 'browser', 'csslib',
229 'custom_element', 'fancy_syntax', 'html5lib', 'html_import', 'js', 204 'custom_element', 'fancy_syntax', 'html5lib', 'html_import', 'js',
230 'logging', 'mdv', 'meta', 'mutation_observer', 'observe', 'path', 205 'logging', 'mdv', 'meta', 'mutation_observer', 'observe', 'path',
231 'polymer', 'polymer_expressions', 'serialization', 'shadow_dom', 206 'polymer', 'polymer_expressions', 'serialization', 'shadow_dom',
232 'source_maps', 'stack_trace', 'unittest', 207 'source_maps', 'stack_trace', 'unittest',
233 'unmodifiable_collection', 'yaml' 208 'unmodifiable_collection', 'yaml'
234 ]).toSet(); 209 ]).toSet();
235
236 ArgResults _parseArgs(arguments) {
237 var parser = new ArgParser()
238 ..addFlag('help', abbr: 'h', help: 'Displays this help message',
239 defaultsTo: false, negatable: false)
240 ..addOption('webdir', help: 'Directory containing the application',
241 defaultsTo: 'web')
242 ..addOption('out', abbr: 'o', help: 'Directory where to generated files',
243 defaultsTo: 'out');
244 try {
245 var results = parser.parse(arguments);
246 if (results['help']) {
247 _showUsage(parser);
248 return null;
249 }
250 return results;
251 } on FormatException catch (e) {
252 print(e.message);
253 _showUsage(parser);
254 return null;
255 }
256 }
257
258 _showUsage(parser) {
259 print('Usage: dart package:polymer/deploy.dart [options]');
260 print(parser.getUsage());
261 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698