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 /// **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/' |
| 11 /// directories as entry points. | 11 /// directories as entry points. |
| 12 /// | 12 /// |
| 13 /// From an application package you can run deploy by creating a small program | 13 /// From an application package you can run deploy by creating a small program |
| 14 /// as follows: | 14 /// as follows: |
| 15 /// | 15 /// |
| 16 /// import "package:polymer/deploy.dart" as deploy; | 16 /// import "package:polymer/deploy.dart" as deploy; |
| 17 /// main() => deploy.main(); | 17 /// main() => deploy.main(); |
| 18 /// | 18 /// |
| 19 /// This library should go away once `pub deploy` can be configured to run | 19 /// This library should go away once `pub deploy` can be configured to run |
| 20 /// barback transformers. | 20 /// barback transformers. |
| 21 library polymer.deploy; | 21 library polymer.deploy; |
| 22 | 22 |
| 23 import 'dart:io'; | 23 import 'dart:io'; |
| 24 | 24 |
| 25 import 'package:args/args.dart'; | 25 import 'package:args/args.dart'; |
| 26 import 'package:path/path.dart' as path; | 26 import 'package:path/path.dart' as path; |
| 27 import 'src/build/common.dart' show TransformOptions, phasesForPolymer; | 27 import 'src/build/common.dart' show TransformOptions, phasesForPolymer; |
| 28 import 'src/build/runner.dart'; | 28 import 'src/build/runner.dart'; |
| 29 import 'transformer.dart'; | 29 import 'transformer.dart'; |
|
Jennifer Messerly
2014/03/27 02:20:32
move up by other package: imports?
Siggi Cherem (dart-lang)
2014/03/28 01:04:26
Done.
| |
| 30 import 'package:code_transformers/tests.dart' show testingDartSdkDirectory; | |
| 30 | 31 |
| 31 main(List<String> arguments) { | 32 main(List<String> arguments) { |
| 32 var args = _parseArgs(arguments); | 33 var args = _parseArgs(arguments); |
| 33 if (args == null) exit(1); | 34 if (args == null) exit(1); |
| 34 | 35 |
| 35 var test = args['test']; | 36 var test = args['test']; |
| 36 var outDir = args['out']; | 37 var outDir = args['out']; |
| 37 | 38 |
| 38 var options; | 39 var options; |
| 39 if (test == null) { | 40 if (test == null) { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 53 if (options == null) exit(1); | 54 if (options == null) exit(1); |
| 54 | 55 |
| 55 print('polymer/deploy.dart: creating a deploy target for ' | 56 print('polymer/deploy.dart: creating a deploy target for ' |
| 56 '"${options.currentPackage}"'); | 57 '"${options.currentPackage}"'); |
| 57 | 58 |
| 58 runBarback(options) | 59 runBarback(options) |
| 59 .then((_) => print('Done! All files written to "$outDir"')) | 60 .then((_) => print('Done! All files written to "$outDir"')) |
| 60 .catchError(_reportErrorAndExit); | 61 .catchError(_reportErrorAndExit); |
| 61 } | 62 } |
| 62 | 63 |
| 63 createDeployPhases(options) => new PolymerTransformerGroup(options).phases; | |
| 64 | |
| 65 BarbackOptions _createTestOptions(String testFile, String outDir, | 64 BarbackOptions _createTestOptions(String testFile, String outDir, |
|
Jennifer Messerly
2014/03/27 02:20:32
off topic, but I wonder how long until we can use
Siggi Cherem (dart-lang)
2014/03/28 01:04:26
not clear yet. There is still a lot of work to be
| |
| 66 bool directlyIncludeJS, bool contentSecurityPolicy, bool releaseMode) { | 65 bool directlyIncludeJS, bool contentSecurityPolicy, bool releaseMode) { |
| 67 | 66 |
| 68 var testDir = path.normalize(path.dirname(testFile)); | 67 var testDir = path.normalize(path.dirname(testFile)); |
| 69 | 68 |
| 70 // A test must be allowed to import things in the package. | 69 // 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 | 70 // So we must find its package root, given the entry point. We can do this |
| 72 // by walking up to find pubspec.yaml. | 71 // by walking up to find pubspec.yaml. |
| 73 var pubspecDir = _findDirWithFile(path.absolute(testDir), 'pubspec.yaml'); | 72 var pubspecDir = _findDirWithFile(path.absolute(testDir), 'pubspec.yaml'); |
| 74 if (pubspecDir == null) { | 73 if (pubspecDir == null) { |
| 75 print('error: pubspec.yaml file not found, please run this script from ' | 74 print('error: pubspec.yaml file not found, please run this script from ' |
| 76 'your package root directory or a subdirectory.'); | 75 'your package root directory or a subdirectory.'); |
| 77 return null; | 76 return null; |
| 78 } | 77 } |
| 79 var packageName = readCurrentPackageFromPubspec(pubspecDir); | 78 var packageName = readCurrentPackageFromPubspec(pubspecDir); |
| 80 | 79 |
| 81 // Find the dart-root so we can include both polymer and smoke as additional | 80 // Find the dart-root so we can include all package dependencies and |
| 82 // packages whose transformers we need to run. | 81 // transformers from other packages. |
| 83 var pkgDir = path.join(_findDirWithDir(path.absolute(testDir), 'pkg'), 'pkg'); | 82 var pkgDir = path.join(_findDirWithDir(path.absolute(testDir), 'pkg'), 'pkg'); |
| 84 | 83 |
| 85 var phases = createDeployPhases(new TransformOptions( | 84 var phases = createDeployPhases(new TransformOptions( |
| 86 entryPoints: [path.relative(testFile, from: pubspecDir)], | 85 entryPoints: [path.relative(testFile, from: pubspecDir)], |
| 87 directlyIncludeJS: directlyIncludeJS, | 86 directlyIncludeJS: directlyIncludeJS, |
| 88 contentSecurityPolicy: contentSecurityPolicy, | 87 contentSecurityPolicy: contentSecurityPolicy, |
| 89 releaseMode: releaseMode, | 88 releaseMode: releaseMode, |
| 90 lint: false)); | 89 lint: false), sdkDir: testingDartSdkDirectory); |
| 90 var dirs = {}; | |
| 91 // Note: we include all packages in pkg/ to keep things simple. Ideally this | |
| 92 // should be restricted to the transitive dependencies of this package. | |
| 93 _subDirs(pkgDir).forEach((p) { dirs[path.basename(p)] = p; }); | |
| 94 // Note: packageName may be a duplicate of 'polymer', but that's ok (they | |
| 95 // should be the same value). | |
| 96 dirs[packageName]= pubspecDir; | |
| 91 return new BarbackOptions(phases, outDir, | 97 return new BarbackOptions(phases, outDir, |
| 92 currentPackage: packageName, | 98 currentPackage: packageName, |
| 93 packageDirs: { | 99 packageDirs: dirs, |
| 94 'polymer': path.join(pkgDir, 'polymer'), | |
| 95 'smoke': path.join(pkgDir, 'smoke'), | |
| 96 // packageName may be a duplicate of 'polymer', but that's ok, the | |
| 97 // following will be the value used in the map (they should also be the | |
| 98 // same value). | |
| 99 packageName: pubspecDir, | |
| 100 }, | |
| 101 // TODO(sigmund): include here also smoke transformer when it's on by | 100 // TODO(sigmund): include here also smoke transformer when it's on by |
| 102 // default. | 101 // default. |
| 103 packagePhases: {'polymer': phasesForPolymer}, | 102 packagePhases: {'polymer': phasesForPolymer}, |
| 104 transformTests: true); | 103 transformTests: true); |
| 105 } | 104 } |
| 106 | 105 |
| 107 String _findDirWithFile(String dir, String filename) { | 106 String _findDirWithFile(String dir, String filename) { |
| 108 while (!new File(path.join(dir, filename)).existsSync()) { | 107 while (!new File(path.join(dir, filename)).existsSync()) { |
| 109 var parentDir = path.dirname(dir); | 108 var parentDir = path.dirname(dir); |
| 110 // If we reached root and failed to find it, bail. | 109 // If we reached root and failed to find it, bail. |
| 111 if (parentDir == dir) return null; | 110 if (parentDir == dir) return null; |
| 112 dir = parentDir; | 111 dir = parentDir; |
| 113 } | 112 } |
| 114 return dir; | 113 return dir; |
| 115 } | 114 } |
| 116 | 115 |
| 117 String _findDirWithDir(String dir, String subdir) { | 116 String _findDirWithDir(String dir, String subdir) { |
| 118 while (!new Directory(path.join(dir, subdir)).existsSync()) { | 117 while (!new Directory(path.join(dir, subdir)).existsSync()) { |
| 119 var parentDir = path.dirname(dir); | 118 var parentDir = path.dirname(dir); |
| 120 // If we reached root and failed to find it, bail. | 119 // If we reached root and failed to find it, bail. |
| 121 if (parentDir == dir) return null; | 120 if (parentDir == dir) return null; |
| 122 dir = parentDir; | 121 dir = parentDir; |
| 123 } | 122 } |
| 124 return dir; | 123 return dir; |
| 125 } | 124 } |
| 126 | 125 |
| 126 List<String> _subDirs(String dir) => | |
| 127 new Directory(dir).listSync(recursive: false, followLinks: false) | |
|
Jennifer Messerly
2014/03/27 02:20:32
fyi -- recursive: false is the default:
https://ap
Siggi Cherem (dart-lang)
2014/03/28 01:04:26
thx, done
| |
| 128 .where((d) => d is Directory).map((d) => d.path).toList(); | |
| 129 | |
| 130 | |
| 127 void _reportErrorAndExit(e, trace) { | 131 void _reportErrorAndExit(e, trace) { |
| 128 print('Uncaught error: $e'); | 132 print('Uncaught error: $e'); |
| 129 if (trace != null) print(trace); | 133 if (trace != null) print(trace); |
| 130 exit(1); | 134 exit(1); |
| 131 } | 135 } |
| 132 | 136 |
| 133 ArgResults _parseArgs(arguments) { | 137 ArgResults _parseArgs(arguments) { |
| 134 var parser = new ArgParser() | 138 var parser = new ArgParser() |
| 135 ..addFlag('help', abbr: 'h', help: 'Displays this help message.', | 139 ..addFlag('help', abbr: 'h', help: 'Displays this help message.', |
| 136 defaultsTo: false, negatable: false) | 140 defaultsTo: false, negatable: false) |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 162 _showUsage(parser); | 166 _showUsage(parser); |
| 163 return null; | 167 return null; |
| 164 } | 168 } |
| 165 } | 169 } |
| 166 | 170 |
| 167 _showUsage(parser) { | 171 _showUsage(parser) { |
| 168 print('Usage: dart --package-root=packages/ ' | 172 print('Usage: dart --package-root=packages/ ' |
| 169 'package:polymer/deploy.dart [options]'); | 173 'package:polymer/deploy.dart [options]'); |
| 170 print(parser.getUsage()); | 174 print(parser.getUsage()); |
| 171 } | 175 } |
| OLD | NEW |