| 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 * **Note**: If you already have a `build.dart` in your application, we | 6 * **Note**: If you already have a `build.dart` in your application, we |
| 7 * recommend to use the `package:polymer/builder.dart` library instead. | 7 * recommend to use the `package:polymer/builder.dart` library instead. |
| 8 | 8 |
| 9 * Temporary deploy command used to create a version of the app that can be | 9 * Temporary deploy command used to create a version of the app that can be |
| 10 * compiled with dart2js and deployed. Following pub layout conventions, this | 10 * compiled with dart2js and deployed. Following pub layout conventions, this |
| 11 * script will treat any HTML file under a package 'web/' and 'test/' | 11 * script will treat any HTML file under a package 'web/' and 'test/' |
| 12 * directories as entry points. | 12 * directories as entry points. |
| 13 * | 13 * |
| 14 * From an application package you can run deploy by creating a small program | 14 * From an application package you can run deploy by creating a small program |
| 15 * as follows: | 15 * as follows: |
| 16 * | 16 * |
| 17 * import "package:polymer/deploy.dart" as deploy; | 17 * import "package:polymer/deploy.dart" as deploy; |
| 18 * main() => deploy.main(); | 18 * main() => deploy.main(); |
| 19 * | 19 * |
| 20 * This library should go away once `pub deploy` can be configured to run | 20 * This library should go away once `pub deploy` can be configured to run |
| 21 * barback transformers. | 21 * barback transformers. |
| 22 */ | 22 */ |
| 23 library polymer.deploy; | 23 library polymer.deploy; |
| 24 | 24 |
| 25 import 'dart:async'; | 25 import 'dart:async'; |
| 26 import 'dart:io'; | 26 import 'dart:io'; |
| 27 | 27 |
| 28 import 'package:args/args.dart'; | 28 import 'package:args/args.dart'; |
| 29 import 'package:path/path.dart' as path; | 29 import 'package:path/path.dart' as path; |
| 30 import 'src/build/common.dart' show TransformOptions; |
| 30 import 'src/build/runner.dart'; | 31 import 'src/build/runner.dart'; |
| 31 import 'transformer.dart'; | 32 import 'transformer.dart'; |
| 32 | 33 |
| 33 main() { | 34 main() { |
| 34 var args = _parseArgs(new Options().arguments); | 35 var args = _parseArgs(new Options().arguments); |
| 35 if (args == null) exit(1); | 36 if (args == null) exit(1); |
| 36 | 37 |
| 37 var test = args['test']; | 38 var test = args['test']; |
| 38 var outDir = args['out']; | 39 var outDir = args['out']; |
| 39 var options = (test == null) | 40 var options = (test == null) |
| 40 ? new BarbackOptions(createDeployPhases(new TransformOptions()), outDir) | 41 ? new BarbackOptions(createDeployPhases(new TransformOptions()), outDir) |
| 41 : _createTestOptions(test, outDir); | 42 : _createTestOptions(test, outDir); |
| 42 if (options == null) exit(1); | 43 if (options == null) exit(1); |
| 43 | 44 |
| 44 print('polymer/deploy.dart: creating a deploy target for ' | 45 print('polymer/deploy.dart: creating a deploy target for ' |
| 45 '"${options.currentPackage}"'); | 46 '"${options.currentPackage}"'); |
| 46 | 47 |
| 47 runBarback(options) | 48 runBarback(options) |
| 48 .then((_) => print('Done! All files written to "$outDir"')) | 49 .then((_) => print('Done! All files written to "$outDir"')) |
| 49 .catchError(_reportErrorAndExit); | 50 .catchError(_reportErrorAndExit); |
| 50 } | 51 } |
| 51 | 52 |
| 53 createDeployPhases(options) => new PolymerTransformerGroup(options).phases; |
| 54 |
| 52 BarbackOptions _createTestOptions(String testFile, String outDir) { | 55 BarbackOptions _createTestOptions(String testFile, String outDir) { |
| 53 var testDir = path.normalize(path.dirname(testFile)); | 56 var testDir = path.normalize(path.dirname(testFile)); |
| 54 | 57 |
| 55 // A test must be allowed to import things in the package. | 58 // A test must be allowed to import things in the package. |
| 56 // So we must find its package root, given the entry point. We can do this | 59 // So we must find its package root, given the entry point. We can do this |
| 57 // by walking up to find pubspec.yaml. | 60 // by walking up to find pubspec.yaml. |
| 58 var pubspecDir = _findDirWithFile(path.absolute(testDir), 'pubspec.yaml'); | 61 var pubspecDir = _findDirWithFile(path.absolute(testDir), 'pubspec.yaml'); |
| 59 if (pubspecDir == null) { | 62 if (pubspecDir == null) { |
| 60 print('error: pubspec.yaml file not found, please run this script from ' | 63 print('error: pubspec.yaml file not found, please run this script from ' |
| 61 'your package root directory or a subdirectory.'); | 64 'your package root directory or a subdirectory.'); |
| 62 return null; | 65 return null; |
| 63 } | 66 } |
| 64 | 67 |
| 65 var phases = createDeployPhases(new TransformOptions( | 68 var phases = createDeployPhases(new TransformOptions( |
| 66 '_test', [path.relative(testFile, from: pubspecDir)])); | 69 [path.relative(testFile, from: pubspecDir)])); |
| 67 return new BarbackOptions(phases, outDir, | 70 return new BarbackOptions(phases, outDir, |
| 68 currentPackage: '_test', | 71 currentPackage: '_test', |
| 69 packageDirs: {'_test' : pubspecDir}, | 72 packageDirs: {'_test' : pubspecDir}, |
| 70 transformTests: true); | 73 transformTests: true); |
| 71 } | 74 } |
| 72 | 75 |
| 73 String _findDirWithFile(String dir, String filename) { | 76 String _findDirWithFile(String dir, String filename) { |
| 74 while (!new File(path.join(dir, filename)).existsSync()) { | 77 while (!new File(path.join(dir, filename)).existsSync()) { |
| 75 var parentDir = path.dirname(dir); | 78 var parentDir = path.dirname(dir); |
| 76 // If we reached root and failed to find it, bail. | 79 // If we reached root and failed to find it, bail. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 _showUsage(parser); | 111 _showUsage(parser); |
| 109 return null; | 112 return null; |
| 110 } | 113 } |
| 111 } | 114 } |
| 112 | 115 |
| 113 _showUsage(parser) { | 116 _showUsage(parser) { |
| 114 print('Usage: dart --package-root=packages/ ' | 117 print('Usage: dart --package-root=packages/ ' |
| 115 'package:polymer/deploy.dart [options]'); | 118 'package:polymer/deploy.dart [options]'); |
| 116 print(parser.getUsage()); | 119 print(parser.getUsage()); |
| 117 } | 120 } |
| OLD | NEW |