| 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 /** | 5 /** |
| 6 * Common logic to make it easy to run the polymer linter and deploy tool. | 6 * Common logic to make it easy to run the polymer linter and deploy tool. |
| 7 * | 7 * |
| 8 * The functions in this library are designed to make it easier to create | 8 * The functions in this library are designed to make it easier to create |
| 9 * `build.dart` files. A `build.dart` file is a Dart script that can be invoked | 9 * `build.dart` files. A `build.dart` file is a Dart script that can be invoked |
| 10 * from the command line, but that can also invoked automatically by the Dart | 10 * from the command line, but that can also invoked automatically by the Dart |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 | 86 |
| 87 import 'src/build/linter.dart'; | 87 import 'src/build/linter.dart'; |
| 88 import 'src/build/runner.dart'; | 88 import 'src/build/runner.dart'; |
| 89 import 'src/build/common.dart'; |
| 90 |
| 89 import 'transformer.dart'; | 91 import 'transformer.dart'; |
| 90 | 92 |
| 91 | 93 |
| 92 /** | 94 /** |
| 93 * Runs the polymer linter on any relevant file in your package, such as any | 95 * Runs the polymer linter on any relevant file in your package, such as any |
| 94 * .html file under 'lib/', 'asset/', and 'web/'. And, if requested, creates a | 96 * .html file under 'lib/', 'asset/', and 'web/'. And, if requested, creates a |
| 95 * directory suitable for deploying a Polymer application to a server. | 97 * directory suitable for deploying a Polymer application to a server. |
| 96 * | 98 * |
| 97 * The [entryPoints] list contains files under web/ that should be treated as | 99 * The [entryPoints] list contains files under web/ that should be treated as |
| 98 * entry points. Each entry on this list is a relative path from the package | 100 * entry points. Each entry on this list is a relative path from the package |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 * passing the [options] argument. | 137 * passing the [options] argument. |
| 136 * | 138 * |
| 137 * The linter needs to know the name of the [currentPackage] and the location | 139 * 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 is | 140 * where to find the code for any package it depends on ([packageDirs]). This is |
| 139 * inferred automatically, but can be overriden if those arguments are provided. | 141 * inferred automatically, but can be overriden if those arguments are provided. |
| 140 */ | 142 */ |
| 141 Future lint({List<String> entryPoints, CommandLineOptions options, | 143 Future lint({List<String> entryPoints, CommandLineOptions options, |
| 142 String currentPackage, Map<String, String> packageDirs}) { | 144 String currentPackage, Map<String, String> packageDirs}) { |
| 143 if (options == null) options = _options; | 145 if (options == null) options = _options; |
| 144 if (currentPackage == null) currentPackage = readCurrentPackageFromPubspec(); | 146 if (currentPackage == null) currentPackage = readCurrentPackageFromPubspec(); |
| 145 var linterOptions = new TransformOptions(currentPackage, entryPoints); | 147 var linterOptions = new TransformOptions(entryPoints); |
| 146 var formatter = options.machineFormat ? jsonFormatter : consoleFormatter; | 148 var formatter = options.machineFormat ? jsonFormatter : consoleFormatter; |
| 147 var linter = new Linter(linterOptions, formatter); | 149 var linter = new Linter(linterOptions, formatter); |
| 148 return runBarback(new BarbackOptions([[linter]], null, | 150 return runBarback(new BarbackOptions([[linter]], null, |
| 149 currentPackage: currentPackage, packageDirs: packageDirs)).then((assets) { | 151 currentPackage: currentPackage, packageDirs: packageDirs)).then((assets) { |
| 150 var messages = {}; | 152 var messages = {}; |
| 151 var futures = []; | 153 var futures = []; |
| 152 for (var asset in assets) { | 154 for (var asset in assets) { |
| 153 var id = asset.id; | 155 var id = asset.id; |
| 154 if (id.package == currentPackage && id.path.endsWith('.messages')) { | 156 if (id.package == currentPackage && id.path.endsWith('.messages')) { |
| 155 futures.add(asset.readAsString().then((content) { | 157 futures.add(asset.readAsString().then((content) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 * The deploy step needs to know the name of the [currentPackage] and the | 194 * The deploy step needs to know the name of the [currentPackage] and the |
| 193 * location where to find the code for any package it depends on | 195 * location where to find the code for any package it depends on |
| 194 * ([packageDirs]). This is inferred automatically, but can be overriden if | 196 * ([packageDirs]). This is inferred automatically, but can be overriden if |
| 195 * those arguments are provided. | 197 * those arguments are provided. |
| 196 */ | 198 */ |
| 197 Future deploy({List<String> entryPoints, CommandLineOptions options, | 199 Future deploy({List<String> entryPoints, CommandLineOptions options, |
| 198 String currentPackage, Map<String, String> packageDirs}) { | 200 String currentPackage, Map<String, String> packageDirs}) { |
| 199 if (options == null) options = _options; | 201 if (options == null) options = _options; |
| 200 if (currentPackage == null) currentPackage = readCurrentPackageFromPubspec(); | 202 if (currentPackage == null) currentPackage = readCurrentPackageFromPubspec(); |
| 201 var barbackOptions = new BarbackOptions( | 203 var barbackOptions = new BarbackOptions( |
| 202 createDeployPhases(new TransformOptions(currentPackage, entryPoints)), | 204 (new PolymerTransformerGroup(new TransformOptions(entryPoints))).phases, |
| 203 options.outDir, currentPackage: currentPackage, | 205 options.outDir, currentPackage: currentPackage, |
| 204 packageDirs: packageDirs); | 206 packageDirs: packageDirs); |
| 205 return runBarback(barbackOptions) | 207 return runBarback(barbackOptions) |
| 206 .then((_) => print('Done! All files written to "${options.outDir}"')); | 208 .then((_) => print('Done! All files written to "${options.outDir}"')); |
| 207 } | 209 } |
| 208 | 210 |
| 209 | 211 |
| 210 /** | 212 /** |
| 211 * Options that may be used either in build.dart or by the linter and deploy | 213 * Options that may be used either in build.dart or by the linter and deploy |
| 212 * tools. | 214 * tools. |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 if (res['help']) { | 285 if (res['help']) { |
| 284 print('A build script that invokes the polymer linter and deploy tools.'); | 286 print('A build script that invokes the polymer linter and deploy tools.'); |
| 285 print('Usage: dart build.dart [options]'); | 287 print('Usage: dart build.dart [options]'); |
| 286 print('\nThese are valid options expected by build.dart:'); | 288 print('\nThese are valid options expected by build.dart:'); |
| 287 print(parser.getUsage()); | 289 print(parser.getUsage()); |
| 288 exit(0); | 290 exit(0); |
| 289 } | 291 } |
| 290 return new CommandLineOptions(res['changed'], res['removed'], res['clean'], | 292 return new CommandLineOptions(res['changed'], res['removed'], res['clean'], |
| 291 res['full'], res['machine'], res['deploy'], res['out']); | 293 res['full'], res['machine'], res['deploy'], res['out']); |
| 292 } | 294 } |
| OLD | NEW |