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:code_transformers/tests.dart' show testingDartSdkDirectory; |
26 import 'package:path/path.dart' as path; | 27 import 'package:path/path.dart' as path; |
| 28 |
27 import 'src/build/common.dart' show TransformOptions, phasesForPolymer; | 29 import 'src/build/common.dart' show TransformOptions, phasesForPolymer; |
28 import 'src/build/runner.dart'; | 30 import 'src/build/runner.dart'; |
29 import 'transformer.dart'; | 31 import 'transformer.dart'; |
30 | 32 |
31 main(List<String> arguments) { | 33 main(List<String> arguments) { |
32 var args = _parseArgs(arguments); | 34 var args = _parseArgs(arguments); |
33 if (args == null) exit(1); | 35 if (args == null) exit(1); |
34 | 36 |
35 var test = args['test']; | 37 var test = args['test']; |
36 var outDir = args['out']; | 38 var outDir = args['out']; |
(...skipping 16 matching lines...) Expand all Loading... |
53 if (options == null) exit(1); | 55 if (options == null) exit(1); |
54 | 56 |
55 print('polymer/deploy.dart: creating a deploy target for ' | 57 print('polymer/deploy.dart: creating a deploy target for ' |
56 '"${options.currentPackage}"'); | 58 '"${options.currentPackage}"'); |
57 | 59 |
58 runBarback(options) | 60 runBarback(options) |
59 .then((_) => print('Done! All files written to "$outDir"')) | 61 .then((_) => print('Done! All files written to "$outDir"')) |
60 .catchError(_reportErrorAndExit); | 62 .catchError(_reportErrorAndExit); |
61 } | 63 } |
62 | 64 |
63 createDeployPhases(options) => new PolymerTransformerGroup(options).phases; | |
64 | |
65 BarbackOptions _createTestOptions(String testFile, String outDir, | 65 BarbackOptions _createTestOptions(String testFile, String outDir, |
66 bool directlyIncludeJS, bool contentSecurityPolicy, bool releaseMode) { | 66 bool directlyIncludeJS, bool contentSecurityPolicy, bool releaseMode) { |
67 | 67 |
68 var testDir = path.normalize(path.dirname(testFile)); | 68 var testDir = path.normalize(path.dirname(testFile)); |
69 | 69 |
70 // A test must be allowed to import things in the package. | 70 // 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 | 71 // So we must find its package root, given the entry point. We can do this |
72 // by walking up to find pubspec.yaml. | 72 // by walking up to find pubspec.yaml. |
73 var pubspecDir = _findDirWithFile(path.absolute(testDir), 'pubspec.yaml'); | 73 var pubspecDir = _findDirWithFile(path.absolute(testDir), 'pubspec.yaml'); |
74 if (pubspecDir == null) { | 74 if (pubspecDir == null) { |
75 print('error: pubspec.yaml file not found, please run this script from ' | 75 print('error: pubspec.yaml file not found, please run this script from ' |
76 'your package root directory or a subdirectory.'); | 76 'your package root directory or a subdirectory.'); |
77 return null; | 77 return null; |
78 } | 78 } |
79 var packageName = readCurrentPackageFromPubspec(pubspecDir); | 79 var packageName = readCurrentPackageFromPubspec(pubspecDir); |
80 | 80 |
81 // Find the dart-root so we can include both polymer and smoke as additional | 81 // Find the dart-root so we can include all package dependencies and |
82 // packages whose transformers we need to run. | 82 // transformers from other packages. |
83 var pkgDir = path.join(_findDirWithDir(path.absolute(testDir), 'pkg'), 'pkg'); | 83 var pkgDir = path.join(_findDirWithDir(path.absolute(testDir), 'pkg'), 'pkg'); |
84 | 84 |
85 var phases = createDeployPhases(new TransformOptions( | 85 var phases = createDeployPhases(new TransformOptions( |
86 entryPoints: [path.relative(testFile, from: pubspecDir)], | 86 entryPoints: [path.relative(testFile, from: pubspecDir)], |
87 directlyIncludeJS: directlyIncludeJS, | 87 directlyIncludeJS: directlyIncludeJS, |
88 contentSecurityPolicy: contentSecurityPolicy, | 88 contentSecurityPolicy: contentSecurityPolicy, |
89 releaseMode: releaseMode, | 89 releaseMode: releaseMode, |
90 lint: false)); | 90 lint: false), sdkDir: testingDartSdkDirectory); |
| 91 var dirs = {}; |
| 92 // Note: we include all packages in pkg/ to keep things simple. Ideally this |
| 93 // should be restricted to the transitive dependencies of this package. |
| 94 _subDirs(pkgDir).forEach((p) { dirs[path.basename(p)] = p; }); |
| 95 // Note: packageName may be a duplicate of 'polymer', but that's ok (they |
| 96 // should be the same value). |
| 97 dirs[packageName]= pubspecDir; |
91 return new BarbackOptions(phases, outDir, | 98 return new BarbackOptions(phases, outDir, |
92 currentPackage: packageName, | 99 currentPackage: packageName, |
93 packageDirs: { | 100 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 | 101 // TODO(sigmund): include here also smoke transformer when it's on by |
102 // default. | 102 // default. |
103 packagePhases: {'polymer': phasesForPolymer}, | 103 packagePhases: {'polymer': phasesForPolymer}, |
104 transformTests: true); | 104 transformTests: true); |
105 } | 105 } |
106 | 106 |
107 String _findDirWithFile(String dir, String filename) { | 107 String _findDirWithFile(String dir, String filename) { |
108 while (!new File(path.join(dir, filename)).existsSync()) { | 108 while (!new File(path.join(dir, filename)).existsSync()) { |
109 var parentDir = path.dirname(dir); | 109 var parentDir = path.dirname(dir); |
110 // If we reached root and failed to find it, bail. | 110 // If we reached root and failed to find it, bail. |
111 if (parentDir == dir) return null; | 111 if (parentDir == dir) return null; |
112 dir = parentDir; | 112 dir = parentDir; |
113 } | 113 } |
114 return dir; | 114 return dir; |
115 } | 115 } |
116 | 116 |
117 String _findDirWithDir(String dir, String subdir) { | 117 String _findDirWithDir(String dir, String subdir) { |
118 while (!new Directory(path.join(dir, subdir)).existsSync()) { | 118 while (!new Directory(path.join(dir, subdir)).existsSync()) { |
119 var parentDir = path.dirname(dir); | 119 var parentDir = path.dirname(dir); |
120 // If we reached root and failed to find it, bail. | 120 // If we reached root and failed to find it, bail. |
121 if (parentDir == dir) return null; | 121 if (parentDir == dir) return null; |
122 dir = parentDir; | 122 dir = parentDir; |
123 } | 123 } |
124 return dir; | 124 return dir; |
125 } | 125 } |
126 | 126 |
| 127 List<String> _subDirs(String dir) => |
| 128 new Directory(dir).listSync(followLinks: false) |
| 129 .where((d) => d is Directory).map((d) => d.path).toList(); |
| 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 |