| 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 /// **Note**: If you already have a `build.dart` in your application, we | 5 /// **Note**: If you already have a `build.dart` in your application, we |
| 6 /// recommend to use the `package:polymer/builder.dart` library instead. | 6 /// recommend to use the `package:polymer/builder.dart` library instead. |
| 7 | 7 |
| 8 /// Temporary deploy command used to create a version of the app that can be | 8 /// Temporary deploy command used to create a version of the app that can be |
| 9 /// compiled with dart2js and deployed. Following pub layout conventions, this | 9 /// compiled with dart2js and deployed. Following pub layout conventions, this |
| 10 /// script will treat any HTML file under a package 'web/' and 'test/' | 10 /// script will treat any HTML file under a package 'web/' and 'test/' |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 import 'src/build/common.dart' show TransformOptions, phasesForPolymer; | 29 import 'src/build/common.dart' show TransformOptions, phasesForPolymer; |
| 30 import 'src/build/runner.dart'; | 30 import 'src/build/runner.dart'; |
| 31 import 'transformer.dart'; | 31 import 'transformer.dart'; |
| 32 | 32 |
| 33 main(List<String> arguments) { | 33 main(List<String> arguments) { |
| 34 var args = _parseArgs(arguments); | 34 var args = _parseArgs(arguments); |
| 35 if (args == null) exit(1); | 35 if (args == null) exit(1); |
| 36 | 36 |
| 37 var test = args['test']; | 37 var test = args['test']; |
| 38 var outDir = args['out']; | 38 var outDir = args['out']; |
| 39 var filters = []; |
| 40 if (args['file-filter'] != null) { |
| 41 filters = args['file-filter'].split(','); |
| 42 } |
| 39 | 43 |
| 40 var options; | 44 var options; |
| 41 if (test == null) { | 45 if (test == null) { |
| 42 var transformOps = new TransformOptions( | 46 var transformOps = new TransformOptions( |
| 43 directlyIncludeJS: args['js'], | 47 directlyIncludeJS: args['js'], |
| 44 contentSecurityPolicy: args['csp'], | 48 contentSecurityPolicy: args['csp'], |
| 45 releaseMode: !args['debug']); | 49 releaseMode: !args['debug']); |
| 46 var phases = createDeployPhases(transformOps); | 50 var phases = createDeployPhases(transformOps); |
| 47 options = new BarbackOptions(phases, outDir, | 51 options = new BarbackOptions(phases, outDir, |
| 48 // TODO(sigmund): include here also smoke transformer when it's on by | 52 // TODO(sigmund): include here also smoke transformer when it's on by |
| 49 // default. | 53 // default. |
| 50 packagePhases: {'polymer': phasesForPolymer}); | 54 packagePhases: {'polymer': phasesForPolymer}); |
| 51 } else { | 55 } else { |
| 52 options = _createTestOptions( | 56 options = _createTestOptions( |
| 53 test, outDir, args['js'], args['csp'], !args['debug']); | 57 test, outDir, args['js'], args['csp'], !args['debug'], |
| 58 filters); |
| 54 } | 59 } |
| 55 if (options == null) exit(1); | 60 if (options == null) exit(1); |
| 56 | 61 |
| 57 print('polymer/deploy.dart: creating a deploy target for ' | 62 print('polymer/deploy.dart: creating a deploy target for ' |
| 58 '"${options.currentPackage}"'); | 63 '"${options.currentPackage}"'); |
| 59 | 64 |
| 60 runBarback(options) | 65 runBarback(options) |
| 61 .then((_) => print('Done! All files written to "$outDir"')) | 66 .then((_) => print('Done! All files written to "$outDir"')) |
| 62 .catchError(_reportErrorAndExit); | 67 .catchError(_reportErrorAndExit); |
| 63 } | 68 } |
| 64 | 69 |
| 65 BarbackOptions _createTestOptions(String testFile, String outDir, | 70 BarbackOptions _createTestOptions(String testFile, String outDir, |
| 66 bool directlyIncludeJS, bool contentSecurityPolicy, bool releaseMode) { | 71 bool directlyIncludeJS, bool contentSecurityPolicy, bool releaseMode, |
| 72 List<String> filters) { |
| 67 | 73 |
| 68 var testDir = path.normalize(path.dirname(testFile)); | 74 var testDir = path.normalize(path.dirname(testFile)); |
| 69 | 75 |
| 70 // A test must be allowed to import things in the package. | 76 // A test must be allowed to import things in the package. |
| 71 // So we must find its package root, given the entry point. We can do this | 77 // So we must find its package root, given the entry point. We can do this |
| 72 // by walking up to find pubspec.yaml. | 78 // by walking up to find pubspec.yaml. |
| 73 var pubspecDir = _findDirWithFile(path.absolute(testDir), 'pubspec.yaml'); | 79 var pubspecDir = _findDirWithFile(path.absolute(testDir), 'pubspec.yaml'); |
| 74 if (pubspecDir == null) { | 80 if (pubspecDir == null) { |
| 75 print('error: pubspec.yaml file not found, please run this script from ' | 81 print('error: pubspec.yaml file not found, please run this script from ' |
| 76 'your package root directory or a subdirectory.'); | 82 'your package root directory or a subdirectory.'); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 94 _subDirs(pkgDir).forEach((p) { dirs[path.basename(p)] = p; }); | 100 _subDirs(pkgDir).forEach((p) { dirs[path.basename(p)] = p; }); |
| 95 // Note: packageName may be a duplicate of 'polymer', but that's ok (they | 101 // Note: packageName may be a duplicate of 'polymer', but that's ok (they |
| 96 // should be the same value). | 102 // should be the same value). |
| 97 dirs[packageName]= pubspecDir; | 103 dirs[packageName]= pubspecDir; |
| 98 return new BarbackOptions(phases, outDir, | 104 return new BarbackOptions(phases, outDir, |
| 99 currentPackage: packageName, | 105 currentPackage: packageName, |
| 100 packageDirs: dirs, | 106 packageDirs: dirs, |
| 101 // TODO(sigmund): include here also smoke transformer when it's on by | 107 // TODO(sigmund): include here also smoke transformer when it's on by |
| 102 // default. | 108 // default. |
| 103 packagePhases: {'polymer': phasesForPolymer}, | 109 packagePhases: {'polymer': phasesForPolymer}, |
| 104 transformTests: true); | 110 transformTests: true, |
| 111 fileFilter: filters); |
| 105 } | 112 } |
| 106 | 113 |
| 107 String _findDirWithFile(String dir, String filename) { | 114 String _findDirWithFile(String dir, String filename) { |
| 108 while (!new File(path.join(dir, filename)).existsSync()) { | 115 while (!new File(path.join(dir, filename)).existsSync()) { |
| 109 var parentDir = path.dirname(dir); | 116 var parentDir = path.dirname(dir); |
| 110 // If we reached root and failed to find it, bail. | 117 // If we reached root and failed to find it, bail. |
| 111 if (parentDir == dir) return null; | 118 if (parentDir == dir) return null; |
| 112 dir = parentDir; | 119 dir = parentDir; |
| 113 } | 120 } |
| 114 return dir; | 121 return dir; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 133 if (trace != null) print(trace); | 140 if (trace != null) print(trace); |
| 134 exit(1); | 141 exit(1); |
| 135 } | 142 } |
| 136 | 143 |
| 137 ArgResults _parseArgs(arguments) { | 144 ArgResults _parseArgs(arguments) { |
| 138 var parser = new ArgParser() | 145 var parser = new ArgParser() |
| 139 ..addFlag('help', abbr: 'h', help: 'Displays this help message.', | 146 ..addFlag('help', abbr: 'h', help: 'Displays this help message.', |
| 140 defaultsTo: false, negatable: false) | 147 defaultsTo: false, negatable: false) |
| 141 ..addOption('out', abbr: 'o', help: 'Directory to generate files into.', | 148 ..addOption('out', abbr: 'o', help: 'Directory to generate files into.', |
| 142 defaultsTo: 'out') | 149 defaultsTo: 'out') |
| 150 ..addOption('file-filter', help: 'Do not copy in files that match \n' |
| 151 'these filters to the deployed folder, e.g., ".svn"', |
| 152 defaultsTo: null) |
| 143 ..addOption('test', help: 'Deploy the test at the given path.\n' | 153 ..addOption('test', help: 'Deploy the test at the given path.\n' |
| 144 'Note: currently this will deploy all tests in its directory,\n' | 154 'Note: currently this will deploy all tests in its directory,\n' |
| 145 'but it will eventually deploy only the specified test.') | 155 'but it will eventually deploy only the specified test.') |
| 146 ..addFlag('js', help: | 156 ..addFlag('js', help: |
| 147 'deploy replaces *.dart scripts with *.dart.js. This flag \n' | 157 'deploy replaces *.dart scripts with *.dart.js. This flag \n' |
| 148 'leaves "packages/browser/dart.js" to do the replacement at runtime.', | 158 'leaves "packages/browser/dart.js" to do the replacement at runtime.', |
| 149 defaultsTo: true) | 159 defaultsTo: true) |
| 150 ..addFlag('debug', help: | 160 ..addFlag('debug', help: |
| 151 'run in debug mode. For example, use the debug polyfill \n' | 161 'run in debug mode. For example, use the debug polyfill \n' |
| 152 'web_components/platform.concat.js instead of the minified one.\n', | 162 'web_components/platform.concat.js instead of the minified one.\n', |
| (...skipping 13 matching lines...) Expand all Loading... |
| 166 _showUsage(parser); | 176 _showUsage(parser); |
| 167 return null; | 177 return null; |
| 168 } | 178 } |
| 169 } | 179 } |
| 170 | 180 |
| 171 _showUsage(parser) { | 181 _showUsage(parser) { |
| 172 print('Usage: dart --package-root=packages/ ' | 182 print('Usage: dart --package-root=packages/ ' |
| 173 'package:polymer/deploy.dart [options]'); | 183 'package:polymer/deploy.dart [options]'); |
| 174 print(parser.getUsage()); | 184 print(parser.getUsage()); |
| 175 } | 185 } |
| OLD | NEW |