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 |
(...skipping 19 matching lines...) Expand all Loading... |
30 import 'src/build/common.dart' show TransformOptions; | 30 import 'src/build/common.dart' show TransformOptions; |
31 import 'src/build/runner.dart'; | 31 import 'src/build/runner.dart'; |
32 import 'transformer.dart'; | 32 import 'transformer.dart'; |
33 | 33 |
34 main() { | 34 main() { |
35 var args = _parseArgs(new Options().arguments); | 35 var args = _parseArgs(new Options().arguments); |
36 if (args == null) exit(1); | 36 if (args == null) exit(1); |
37 | 37 |
38 var test = args['test']; | 38 var test = args['test']; |
39 var outDir = args['out']; | 39 var outDir = args['out']; |
| 40 |
| 41 var transformOps = new TransformOptions( |
| 42 directlyIncludeJS: args['js'], |
| 43 contentSecurityPolicy: args['csp']); |
| 44 |
40 var options = (test == null) | 45 var options = (test == null) |
41 ? new BarbackOptions(createDeployPhases(new TransformOptions()), outDir) | 46 ? new BarbackOptions(createDeployPhases(transformOps), outDir) |
42 : _createTestOptions(test, outDir); | 47 : _createTestOptions(transformOps, test, outDir); |
43 if (options == null) exit(1); | 48 if (options == null) exit(1); |
44 | 49 |
45 print('polymer/deploy.dart: creating a deploy target for ' | 50 print('polymer/deploy.dart: creating a deploy target for ' |
46 '"${options.currentPackage}"'); | 51 '"${options.currentPackage}"'); |
47 | 52 |
48 runBarback(options) | 53 runBarback(options) |
49 .then((_) => print('Done! All files written to "$outDir"')) | 54 .then((_) => print('Done! All files written to "$outDir"')) |
50 .catchError(_reportErrorAndExit); | 55 .catchError(_reportErrorAndExit); |
51 } | 56 } |
52 | 57 |
53 createDeployPhases(options) => new PolymerTransformerGroup(options).phases; | 58 createDeployPhases(options) => new PolymerTransformerGroup(options).phases; |
54 | 59 |
55 BarbackOptions _createTestOptions(String testFile, String outDir) { | 60 BarbackOptions _createTestOptions(TransformOptions transformOps, |
| 61 String testFile, String outDir) { |
56 var testDir = path.normalize(path.dirname(testFile)); | 62 var testDir = path.normalize(path.dirname(testFile)); |
57 | 63 |
58 // A test must be allowed to import things in the package. | 64 // A test must be allowed to import things in the package. |
59 // So we must find its package root, given the entry point. We can do this | 65 // So we must find its package root, given the entry point. We can do this |
60 // by walking up to find pubspec.yaml. | 66 // by walking up to find pubspec.yaml. |
61 var pubspecDir = _findDirWithFile(path.absolute(testDir), 'pubspec.yaml'); | 67 var pubspecDir = _findDirWithFile(path.absolute(testDir), 'pubspec.yaml'); |
62 if (pubspecDir == null) { | 68 if (pubspecDir == null) { |
63 print('error: pubspec.yaml file not found, please run this script from ' | 69 print('error: pubspec.yaml file not found, please run this script from ' |
64 'your package root directory or a subdirectory.'); | 70 'your package root directory or a subdirectory.'); |
65 return null; | 71 return null; |
66 } | 72 } |
67 | 73 |
68 var phases = createDeployPhases(new TransformOptions( | 74 transformOps.entryPoints = [path.relative(testFile, from: pubspecDir)]; |
69 [path.relative(testFile, from: pubspecDir)])); | 75 var phases = createDeployPhases(transformOps); |
70 return new BarbackOptions(phases, outDir, | 76 return new BarbackOptions(phases, outDir, |
71 currentPackage: '_test', | 77 currentPackage: '_test', |
72 packageDirs: {'_test' : pubspecDir}, | 78 packageDirs: {'_test' : pubspecDir}, |
73 transformTests: true); | 79 transformTests: true); |
74 } | 80 } |
75 | 81 |
76 String _findDirWithFile(String dir, String filename) { | 82 String _findDirWithFile(String dir, String filename) { |
77 while (!new File(path.join(dir, filename)).existsSync()) { | 83 while (!new File(path.join(dir, filename)).existsSync()) { |
78 var parentDir = path.dirname(dir); | 84 var parentDir = path.dirname(dir); |
79 // If we reached root and failed to find it, bail. | 85 // If we reached root and failed to find it, bail. |
(...skipping 11 matching lines...) Expand all Loading... |
91 } | 97 } |
92 | 98 |
93 ArgResults _parseArgs(arguments) { | 99 ArgResults _parseArgs(arguments) { |
94 var parser = new ArgParser() | 100 var parser = new ArgParser() |
95 ..addFlag('help', abbr: 'h', help: 'Displays this help message.', | 101 ..addFlag('help', abbr: 'h', help: 'Displays this help message.', |
96 defaultsTo: false, negatable: false) | 102 defaultsTo: false, negatable: false) |
97 ..addOption('out', abbr: 'o', help: 'Directory to generate files into.', | 103 ..addOption('out', abbr: 'o', help: 'Directory to generate files into.', |
98 defaultsTo: 'out') | 104 defaultsTo: 'out') |
99 ..addOption('test', help: 'Deploy the test at the given path.\n' | 105 ..addOption('test', help: 'Deploy the test at the given path.\n' |
100 'Note: currently this will deploy all tests in its directory,\n' | 106 'Note: currently this will deploy all tests in its directory,\n' |
101 'but it will eventually deploy only the specified test.'); | 107 'but it will eventually deploy only the specified test.') |
| 108 ..addFlag('js', help: |
| 109 'deploy replaces *.dart scripts with *.dart.js. This flag \n' |
| 110 'leaves "packages/browser/dart.js" to do the replacement at runtime.', |
| 111 defaultsTo: true) |
| 112 ..addFlag('csp', help: |
| 113 'replaces *.dart with *.dart.precompiled.js to comply with \n' |
| 114 'Content Security Policy restrictions.'); |
102 try { | 115 try { |
103 var results = parser.parse(arguments); | 116 var results = parser.parse(arguments); |
104 if (results['help']) { | 117 if (results['help']) { |
105 _showUsage(parser); | 118 _showUsage(parser); |
106 return null; | 119 return null; |
107 } | 120 } |
108 return results; | 121 return results; |
109 } on FormatException catch (e) { | 122 } on FormatException catch (e) { |
110 print(e.message); | 123 print(e.message); |
111 _showUsage(parser); | 124 _showUsage(parser); |
112 return null; | 125 return null; |
113 } | 126 } |
114 } | 127 } |
115 | 128 |
116 _showUsage(parser) { | 129 _showUsage(parser) { |
117 print('Usage: dart --package-root=packages/ ' | 130 print('Usage: dart --package-root=packages/ ' |
118 'package:polymer/deploy.dart [options]'); | 131 'package:polymer/deploy.dart [options]'); |
119 print(parser.getUsage()); | 132 print(parser.getUsage()); |
120 } | 133 } |
OLD | NEW |