| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 /// Common logic to make it easy to run the polymer linter and deploy tool. | 5 /// Common logic to make it easy to run the polymer linter and deploy tool. |
| 6 /// | 6 /// |
| 7 /// The functions in this library are designed to make it easier to create | 7 /// The functions in this library are designed to make it easier to create |
| 8 /// `build.dart` files. A `build.dart` file is a Dart script that can be invoked | 8 /// `build.dart` files. A `build.dart` file is a Dart script that can be invoked |
| 9 /// from the command line, but that can also invoked automatically by the Dart | 9 /// from the command line, but that can also invoked automatically by the Dart |
| 10 /// Editor whenever a file in your project changes or when selecting some menu | 10 /// Editor whenever a file in your project changes or when selecting some menu |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 /// | 76 /// |
| 77 /// main(args) { | 77 /// main(args) { |
| 78 /// build(entryPoints: ['web/index.html'], options: parseOptions(args)); | 78 /// build(entryPoints: ['web/index.html'], options: parseOptions(args)); |
| 79 /// } | 79 /// } |
| 80 library polymer.builder; | 80 library polymer.builder; |
| 81 | 81 |
| 82 import 'dart:async'; | 82 import 'dart:async'; |
| 83 import 'dart:io'; | 83 import 'dart:io'; |
| 84 | 84 |
| 85 import 'package:args/args.dart'; | 85 import 'package:args/args.dart'; |
| 86 import 'package:path/path.dart' as path; |
| 87 import 'package:yaml/yaml.dart'; |
| 86 | 88 |
| 87 import 'src/build/linter.dart'; | 89 import 'src/build/linter.dart'; |
| 88 import 'src/build/runner.dart'; | 90 import 'src/build/runner.dart'; |
| 89 import 'src/build/common.dart'; | 91 import 'src/build/common.dart'; |
| 90 | 92 |
| 91 import 'transformer.dart'; | 93 import 'transformer.dart'; |
| 92 | 94 |
| 93 | 95 |
| 94 /// Runs the polymer linter on any relevant file in your package, such as any | 96 /// Runs the polymer linter on any relevant file in your package, such as any |
| 95 /// .html file under 'lib/', 'asset/', and 'web/'. And, if requested, creates a | 97 /// .html file under 'lib/', 'asset/', and 'web/'. And, if requested, creates a |
| (...skipping 13 matching lines...) Expand all Loading... |
| 109 /// and the location where to find the code for any package it depends on | 111 /// and the location where to find the code for any package it depends on |
| 110 /// ([packageDirs]). This is inferred automatically, but can be overriden if | 112 /// ([packageDirs]). This is inferred automatically, but can be overriden if |
| 111 /// those arguments are provided. | 113 /// those arguments are provided. |
| 112 Future build({List<String> entryPoints, CommandLineOptions options, | 114 Future build({List<String> entryPoints, CommandLineOptions options, |
| 113 String currentPackage, Map<String, String> packageDirs}) { | 115 String currentPackage, Map<String, String> packageDirs}) { |
| 114 if (options == null) { | 116 if (options == null) { |
| 115 print('warning: now that main takes arguments, you need to explicitly pass' | 117 print('warning: now that main takes arguments, you need to explicitly pass' |
| 116 ' options to build(). Running as if no options were passed.'); | 118 ' options to build(). Running as if no options were passed.'); |
| 117 options = parseOptions([]); | 119 options = parseOptions([]); |
| 118 } | 120 } |
| 121 if (entryPoints == null) entryPoints = _parseEntryPointsFromPubspec(); |
| 122 |
| 119 return options.forceDeploy | 123 return options.forceDeploy |
| 120 ? deploy(entryPoints: entryPoints, options: options, | 124 ? deploy(entryPoints: entryPoints, options: options, |
| 121 currentPackage: currentPackage, packageDirs: packageDirs) | 125 currentPackage: currentPackage, packageDirs: packageDirs) |
| 122 : lint(entryPoints: entryPoints, options: options, | 126 : lint(entryPoints: entryPoints, options: options, |
| 123 currentPackage: currentPackage, packageDirs: packageDirs); | 127 currentPackage: currentPackage, packageDirs: packageDirs); |
| 124 } | 128 } |
| 125 | 129 |
| 126 | 130 |
| 127 /// Runs the polymer linter on any relevant file in your package, | 131 /// Runs the polymer linter on any relevant file in your package, |
| 128 /// such as any .html file under 'lib/', 'asset/', and 'web/'. | 132 /// such as any .html file under 'lib/', 'asset/', and 'web/'. |
| 129 /// | 133 /// |
| 130 /// The [entryPoints] list contains files under web/ that should be treated as | 134 /// The [entryPoints] list contains files under web/ that should be treated as |
| 131 /// entry points. Each entry on this list is a relative path from the package | 135 /// entry points. Each entry on this list is a relative path from the package |
| 132 /// root (for example 'web/index.html'). If null, all files under 'web/' are | 136 /// root (for example 'web/index.html'). If null, all files under 'web/' are |
| 133 /// treated as possible entry points. | 137 /// treated as possible entry points. |
| 134 /// | 138 /// |
| 135 /// Options must be passed by passing the [options] argument. | 139 /// Options must be passed by passing the [options] argument. |
| 136 /// | 140 /// |
| 137 /// The linter needs to know the name of the [currentPackage] and the location | 141 /// The linter needs to know the name of the [currentPackage] and the location |
| 138 /// where to find the code for any package it depends on ([packageDirs]). This | 142 /// where to find the code for any package it depends on ([packageDirs]). This |
| 139 /// is inferred automatically, but can be overriden by passing the arguments. | 143 /// is inferred automatically, but can be overriden by passing the arguments. |
| 140 Future lint({List<String> entryPoints, CommandLineOptions options, | 144 Future lint({List<String> entryPoints, CommandLineOptions options, |
| 141 String currentPackage, Map<String, String> packageDirs}) { | 145 String currentPackage, Map<String, String> packageDirs}) { |
| 142 if (options == null) { | 146 if (options == null) { |
| 143 print('warning: now that main takes arguments, you need to explicitly pass' | 147 print('warning: now that main takes arguments, you need to explicitly pass' |
| 144 ' options to lint(). Running as if no options were passed.'); | 148 ' options to lint(). Running as if no options were passed.'); |
| 145 options = parseOptions([]); | 149 options = parseOptions([]); |
| 146 } | 150 } |
| 147 if (currentPackage == null) currentPackage = readCurrentPackageFromPubspec(); | 151 if (currentPackage == null) currentPackage = readCurrentPackageFromPubspec(); |
| 152 if (entryPoints == null) entryPoints = _parseEntryPointsFromPubspec(); |
| 148 var linterOptions = new TransformOptions(entryPoints: entryPoints); | 153 var linterOptions = new TransformOptions(entryPoints: entryPoints); |
| 149 var linter = new Linter(linterOptions); | 154 var linter = new Linter(linterOptions); |
| 155 |
| 150 return runBarback(new BarbackOptions([[linter]], null, | 156 return runBarback(new BarbackOptions([[linter]], null, |
| 151 currentPackage: currentPackage, packageDirs: packageDirs, | 157 currentPackage: currentPackage, packageDirs: packageDirs, |
| 152 machineFormat: options.machineFormat)); | 158 machineFormat: options.machineFormat)); |
| 153 } | 159 } |
| 154 | 160 |
| 155 /// Creates a directory suitable for deploying a Polymer application to a | 161 /// Creates a directory suitable for deploying a Polymer application to a |
| 156 /// server. | 162 /// server. |
| 157 /// | 163 /// |
| 158 /// **Note**: this function will be replaced in the future by the `pub deploy` | 164 /// **Note**: this function will be replaced in the future by the `pub deploy` |
| 159 /// command. | 165 /// command. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 170 /// ([packageDirs]). This is inferred automatically, but can be overriden if | 176 /// ([packageDirs]). This is inferred automatically, but can be overriden if |
| 171 /// those arguments are provided. | 177 /// those arguments are provided. |
| 172 Future deploy({List<String> entryPoints, CommandLineOptions options, | 178 Future deploy({List<String> entryPoints, CommandLineOptions options, |
| 173 String currentPackage, Map<String, String> packageDirs}) { | 179 String currentPackage, Map<String, String> packageDirs}) { |
| 174 if (options == null) { | 180 if (options == null) { |
| 175 print('warning: now that main takes arguments, you need to explicitly pass' | 181 print('warning: now that main takes arguments, you need to explicitly pass' |
| 176 ' options to deploy(). Running as if no options were passed.'); | 182 ' options to deploy(). Running as if no options were passed.'); |
| 177 options = parseOptions([]); | 183 options = parseOptions([]); |
| 178 } | 184 } |
| 179 if (currentPackage == null) currentPackage = readCurrentPackageFromPubspec(); | 185 if (currentPackage == null) currentPackage = readCurrentPackageFromPubspec(); |
| 186 if (entryPoints == null) entryPoints = _parseEntryPointsFromPubspec(); |
| 180 | 187 |
| 181 var transformOptions = new TransformOptions( | 188 var transformOptions = new TransformOptions( |
| 182 entryPoints: entryPoints, | 189 entryPoints: entryPoints, |
| 183 directlyIncludeJS: options.directlyIncludeJS, | 190 directlyIncludeJS: options.directlyIncludeJS, |
| 184 contentSecurityPolicy: options.contentSecurityPolicy, | 191 contentSecurityPolicy: options.contentSecurityPolicy, |
| 185 releaseMode: options.releaseMode); | 192 releaseMode: options.releaseMode); |
| 186 | 193 |
| 187 var phases = new PolymerTransformerGroup(transformOptions).phases; | 194 var phases = new PolymerTransformerGroup(transformOptions).phases; |
| 188 var barbackOptions = new BarbackOptions( | 195 var barbackOptions = new BarbackOptions( |
| 189 phases, options.outDir, currentPackage: currentPackage, | 196 phases, options.outDir, currentPackage: currentPackage, |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 } | 318 } |
| 312 if (res['help']) { | 319 if (res['help']) { |
| 313 print('A build script that invokes the polymer linter and deploy tools.'); | 320 print('A build script that invokes the polymer linter and deploy tools.'); |
| 314 showUsage(); | 321 showUsage(); |
| 315 exit(0); | 322 exit(0); |
| 316 } | 323 } |
| 317 return new CommandLineOptions(res['changed'], res['removed'], res['clean'], | 324 return new CommandLineOptions(res['changed'], res['removed'], res['clean'], |
| 318 res['full'], res['machine'], res['deploy'], res['out'], res['js'], | 325 res['full'], res['machine'], res['deploy'], res['out'], res['js'], |
| 319 res['csp'], !res['debug']); | 326 res['csp'], !res['debug']); |
| 320 } | 327 } |
| 328 |
| 329 List<String> _parseEntryPointsFromPubspec() { |
| 330 var entryPoints = []; |
| 331 var pubspec = new File(path.join( |
| 332 path.dirname(Platform.script.path), 'pubspec.yaml')); |
| 333 if (!pubspec.existsSync()) { |
| 334 print('error: pubspec.yaml file not found.'); |
| 335 return null; |
| 336 } |
| 337 var transformers = loadYaml(pubspec.readAsStringSync())['transformers']; |
| 338 if (transformers == null) return null; |
| 339 if (transformers is! List) { |
| 340 print('Unexpected value for transformers, expected a List.'); |
| 341 return null; |
| 342 } |
| 343 |
| 344 transformers.forEach((t) { |
| 345 if (t is! Map) return; |
| 346 var polymer = t['polymer']; |
| 347 if (polymer == null || polymer is! Map) return; |
| 348 |
| 349 var parsedEntryPoints = readEntrypoints(polymer['entry_points']); |
| 350 if (parsedEntryPoints == null) return; |
| 351 |
| 352 entryPoints.addAll(parsedEntryPoints); |
| 353 }); |
| 354 return entryPoints.isEmpty ? null : entryPoints; |
| 355 } |
| OLD | NEW |