Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 /** | 5 /** |
| 6 * Temporary deploy command used to create a version of the app that can be | 6 * Temporary deploy command used to create a version of the app that can be |
| 7 * compiled with dart2js and deployed. This library should go away once `pub | 7 * compiled with dart2js and deployed. This library should go away once `pub |
| 8 * deploy` can be configured to run barback transformers. | 8 * deploy` can be configured to run barback transformers. |
| 9 * | 9 * |
| 10 * From an application package you can run this program by calling dart with a | 10 * From an application package you can run this program by calling dart with a |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 import 'package:barback/barback.dart'; | 21 import 'package:barback/barback.dart'; |
| 22 import 'package:path/path.dart' as path; | 22 import 'package:path/path.dart' as path; |
| 23 import 'package:polymer/src/transform.dart' show phases; | 23 import 'package:polymer/src/transform.dart' show phases; |
| 24 import 'package:stack_trace/stack_trace.dart'; | 24 import 'package:stack_trace/stack_trace.dart'; |
| 25 import 'package:yaml/yaml.dart'; | 25 import 'package:yaml/yaml.dart'; |
| 26 import 'package:args/args.dart'; | 26 import 'package:args/args.dart'; |
| 27 | 27 |
| 28 main() { | 28 main() { |
| 29 var args = _parseArgs(new Options().arguments); | 29 var args = _parseArgs(new Options().arguments); |
| 30 if (args == null) return; | 30 if (args == null) return; |
| 31 | |
| 32 var test = args['test']; | |
| 33 if (test != null) { | |
| 34 _initForTest(test); | |
| 35 } | |
| 36 | |
| 31 print('polymer/deploy.dart: creating a deploy target for "$_currentPackage"'); | 37 print('polymer/deploy.dart: creating a deploy target for "$_currentPackage"'); |
| 32 var outDir = args['out']; | 38 var outDir = args['out']; |
| 33 _run(args['webdir'], outDir).then( | 39 _run(outDir, test != null).then( |
| 34 (_) => print('Done! All files written to "$outDir"')); | 40 (_) => print('Done! All files written to "$outDir"')); |
| 35 } | 41 } |
| 36 | 42 |
| 43 // TODO(jmesserly): the current deploy/barback architecture is very unfriendly | |
| 44 // to deploying a single test. We need to fix it somehow but it isn't clear yet. | |
| 45 void _initForTest(String testFile) { | |
| 46 var testDir = path.normalize(path.dirname(testFile)); | |
| 47 | |
| 48 // A test must be allowed to import things in the package. | |
| 49 // So we must find its package root, given the entry point. We can do this | |
| 50 // by walking up to find pubspec.yaml. | |
| 51 var pubspecDir = _findDirWithFile(path.absolute(testDir), 'pubspec.yaml'); | |
| 52 if (pubspecDir == null) { | |
| 53 print('error: pubspec.yaml file not found, please run this script from ' | |
| 54 'your package root directory or a subdirectory.'); | |
| 55 exit(1); | |
| 56 } | |
| 57 | |
| 58 _currentPackage = '_test'; | |
| 59 _packageDirs = {'_test' : pubspecDir}; | |
| 60 } | |
| 61 | |
| 62 String _findDirWithFile(String dir, String filename) { | |
| 63 while (!new File(path.join(dir, filename)).existsSync()) { | |
| 64 var parentDir = path.dirname(dir); | |
| 65 // If we reached root and failed to find it, bail. | |
| 66 if (parentDir == dir) return null; | |
|
Siggi Cherem (dart-lang)
2013/08/30 23:22:13
maybe define `var root = path.rootPrefix(dir)` upf
Jennifer Messerly
2013/09/04 04:36:40
hmmm. I was woried that dirname does not necessari
Siggi Cherem (dart-lang)
2013/09/04 15:23:32
I see - it seems that in that case it will converg
| |
| 67 dir = parentDir; | |
| 68 } | |
| 69 return dir; | |
| 70 } | |
| 71 | |
| 37 /** | 72 /** |
| 38 * API exposed for testing purposes. Runs this deploy command but prentend that | 73 * API exposed for testing purposes. Runs this deploy command but prentend that |
| 39 * the sources under [webDir] belong to package 'test'. | 74 * the sources under [webDir] belong to package 'test'. |
| 40 */ | 75 */ |
| 41 Future runForTest(String webDir, String outDir) { | 76 Future runForTest(String webDir, String outDir) { |
| 42 _currentPackage = 'test'; | 77 _currentPackage = 'test'; |
| 43 | 78 |
| 44 // associate package dirs with their location in the repo: | 79 // associate package dirs with their location in the repo: |
| 45 _packageDirs = {'test' : '.'}; | 80 _packageDirs = {'test' : '.'}; |
| 46 addPackages(String dir) { | 81 _addPackages('..'); |
| 47 for (var packageDir in new Directory(dir).listSync().map((d) => d.path)) { | 82 _addPackages('../third_party'); |
| 48 _packageDirs[path.basename(packageDir)] = packageDir; | 83 _addPackages('../../third_party/pkg'); |
| 49 } | |
| 50 } | |
| 51 addPackages('..'); | |
| 52 addPackages('../third_party'); | |
| 53 addPackages('../../third_party/pkg'); | |
| 54 return _run(webDir, outDir); | 84 return _run(webDir, outDir); |
| 55 } | 85 } |
| 56 | 86 |
| 57 Future _run(String webDir, String outDir) { | 87 _addPackages(String dir) { |
| 88 for (var packageDir in new Directory(dir).listSync().map((d) => d.path)) { | |
| 89 _packageDirs[path.basename(packageDir)] = packageDir; | |
| 90 } | |
| 91 } | |
| 92 | |
| 93 Future _run(String outDir, bool includeTests) { | |
| 58 var barback = new Barback(new _PolymerDeployProvider()); | 94 var barback = new Barback(new _PolymerDeployProvider()); |
| 59 _initializeBarback(barback, webDir); | 95 |
|
Siggi Cherem (dart-lang)
2013/08/30 23:22:13
delete empty line?
Jennifer Messerly
2013/09/04 04:36:40
Done.
| |
| 96 _initializeBarback(barback, includeTests); | |
| 60 _attachListeners(barback); | 97 _attachListeners(barback); |
| 61 return _emitAllFiles(barback, webDir, outDir); | 98 return _emitAllFiles(barback, 'web', outDir).then( |
| 99 (_) => includeTests ? _emitAllFiles(barback, 'test', outDir) : null); | |
| 62 } | 100 } |
| 63 | 101 |
| 64 /** Tell barback which transformers to use and which assets to process. */ | 102 /** Tell barback which transformers to use and which assets to process. */ |
| 65 void _initializeBarback(Barback barback, String webDir) { | 103 void _initializeBarback(Barback barback, bool includeTests) { |
| 66 var assets = []; | 104 var assets = []; |
| 105 void addAssets(String package, String subDir) { | |
| 106 for (var filepath in _listDir(package, subDir)) { | |
| 107 assets.add(new AssetId(package, filepath)); | |
| 108 } | |
| 109 } | |
| 110 | |
| 67 for (var package in _packageDirs.keys) { | 111 for (var package in _packageDirs.keys) { |
| 68 // Do not process packages like 'polymer' where there is nothing to do. | 112 // Do not process packages like 'polymer' where there is nothing to do. |
| 69 if (_ignoredPackages.contains(package)) continue; | 113 if (_ignoredPackages.contains(package)) continue; |
| 70 barback.updateTransformers(package, phases); | 114 barback.updateTransformers(package, phases); |
| 71 | 115 |
| 72 // notify barback to process anything under 'lib' and 'asset' | 116 // notify barback to process anything under 'lib' and 'asset' |
| 73 for (var filepath in _listDir(package, 'lib')) { | 117 addAssets(package, 'lib'); |
| 74 assets.add(new AssetId(package, filepath)); | 118 addAssets(package, 'asset'); |
| 75 } | |
| 76 | |
| 77 for (var filepath in _listDir(package, 'asset')) { | |
| 78 assets.add(new AssetId(package, filepath)); | |
| 79 } | |
| 80 } | 119 } |
| 81 | 120 |
| 82 // In case of the current package, include also 'web'. | 121 // In case of the current package, include also 'web'. |
| 83 for (var filepath in _listDir(_currentPackage, webDir)) { | 122 addAssets(_currentPackage, 'web'); |
| 84 assets.add(new AssetId(_currentPackage, filepath)); | 123 if (includeTests) addAssets(_currentPackage, 'test'); |
| 85 } | 124 |
| 86 barback.updateSources(assets); | 125 barback.updateSources(assets); |
| 87 } | 126 } |
| 88 | 127 |
| 89 /** Return the relative path of each file under [subDir] in a [package]. */ | 128 /** Return the relative path of each file under [subDir] in a [package]. */ |
| 90 Iterable<String> _listDir(String package, String subDir) { | 129 Iterable<String> _listDir(String package, String subDir) { |
| 91 var packageDir = _packageDirs[package]; | 130 var packageDir = _packageDirs[package]; |
| 92 if (packageDir == null) return const []; | 131 if (packageDir == null) return const []; |
| 93 var dir = new Directory(path.join(packageDir, subDir)); | 132 var dir = new Directory(path.join(packageDir, subDir)); |
| 94 if (!dir.existsSync()) return const []; | 133 if (!dir.existsSync()) return const []; |
| 95 return dir.listSync(recursive: true, followLinks: false) | 134 return dir.listSync(recursive: true, followLinks: false) |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 (const [ 'analyzer_experimental', 'args', 'barback', 'browser', 'csslib', | 262 (const [ 'analyzer_experimental', 'args', 'barback', 'browser', 'csslib', |
| 224 'custom_element', 'fancy_syntax', 'html5lib', 'html_import', 'js', | 263 'custom_element', 'fancy_syntax', 'html5lib', 'html_import', 'js', |
| 225 'logging', 'mdv', 'meta', 'mutation_observer', 'observe', 'path', | 264 'logging', 'mdv', 'meta', 'mutation_observer', 'observe', 'path', |
| 226 'polymer', 'polymer_expressions', 'serialization', 'shadow_dom', | 265 'polymer', 'polymer_expressions', 'serialization', 'shadow_dom', |
| 227 'source_maps', 'stack_trace', 'unittest', | 266 'source_maps', 'stack_trace', 'unittest', |
| 228 'unmodifiable_collection', 'yaml' | 267 'unmodifiable_collection', 'yaml' |
| 229 ]).toSet(); | 268 ]).toSet(); |
| 230 | 269 |
| 231 ArgResults _parseArgs(arguments) { | 270 ArgResults _parseArgs(arguments) { |
| 232 var parser = new ArgParser() | 271 var parser = new ArgParser() |
| 233 ..addFlag('help', abbr: 'h', help: 'Displays this help message', | 272 ..addFlag('help', abbr: 'h', help: 'Displays this help message.', |
| 234 defaultsTo: false, negatable: false) | 273 defaultsTo: false, negatable: false) |
| 235 ..addOption('webdir', help: 'Directory containing the application', | 274 ..addOption('out', abbr: 'o', help: 'Directory where to generated files.', |
| 236 defaultsTo: 'web') | 275 defaultsTo: 'out') |
| 237 ..addOption('out', abbr: 'o', help: 'Directory where to generated files', | 276 ..addOption('test', help: 'Deploy the test at the given path.'); |
|
Siggi Cherem (dart-lang)
2013/08/30 23:22:13
minor nit: maybe indicate that this is to limit de
Jennifer Messerly
2013/09/04 04:36:40
thought about that, was worried about length makin
| |
| 238 defaultsTo: 'out'); | |
| 239 try { | 277 try { |
| 240 var results = parser.parse(arguments); | 278 var results = parser.parse(arguments); |
| 241 if (results['help']) { | 279 if (results['help']) { |
| 242 _showUsage(parser); | 280 _showUsage(parser); |
| 243 return null; | 281 return null; |
| 244 } | 282 } |
| 245 return results; | 283 return results; |
| 246 } on FormatException catch (e) { | 284 } on FormatException catch (e) { |
| 247 print(e.message); | 285 print(e.message); |
| 248 _showUsage(parser); | 286 _showUsage(parser); |
| 249 return null; | 287 return null; |
| 250 } | 288 } |
| 251 } | 289 } |
| 252 | 290 |
| 253 _showUsage(parser) { | 291 _showUsage(parser) { |
| 254 print('Usage: dart package:polymer/deploy.dart [options]'); | 292 print('Usage: dart package:polymer/deploy.dart [options]'); |
| 255 print(parser.getUsage()); | 293 print(parser.getUsage()); |
| 256 } | 294 } |
| OLD | NEW |