| 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 create a `build.dart` for your project. | 6 * Common logic to make it easy to create a `build.dart` for your project. |
| 7 * | 7 * |
| 8 * The `build.dart` script is invoked automatically by the Editor whenever a | 8 * The `build.dart` script is invoked automatically by the Editor whenever a |
| 9 * file in the project changes. It must be placed in the root of a project | 9 * file in the project changes. It must be placed in the root of a project |
| 10 * (where pubspec.yaml lives) and should be named exactly 'build.dart'. | 10 * (where pubspec.yaml lives) and should be named exactly 'build.dart'. |
| 11 * | 11 * |
| 12 * A common `build.dart` would look as follows: | 12 * A common `build.dart` would look as follows: |
| 13 * | 13 * |
| 14 * import 'dart:io'; | 14 * import 'dart:io'; |
| 15 * import 'package:polymer/component_build.dart'; | 15 * import 'package:polymer/component_build.dart'; |
| 16 * | 16 * |
| 17 * main() => build(new Options().arguments, ['web/index.html']); | 17 * main() => build(new Options().arguments, ['web/index.html']); |
| 18 */ | 18 */ |
| 19 library build_utils; | 19 library build_utils; |
| 20 | 20 |
| 21 import 'dart:async'; | 21 import 'dart:async'; |
| 22 import 'dart:convert'; |
| 22 import 'dart:io'; | 23 import 'dart:io'; |
| 23 import 'dart:json' as json; | |
| 24 import 'package:args/args.dart'; | 24 import 'package:args/args.dart'; |
| 25 | 25 |
| 26 import 'dwc.dart' as dwc; | 26 import 'dwc.dart' as dwc; |
| 27 import 'src/utils.dart'; | 27 import 'src/utils.dart'; |
| 28 import 'src/compiler_options.dart'; | 28 import 'src/compiler_options.dart'; |
| 29 | 29 |
| 30 /** | 30 /** |
| 31 * Set up 'build.dart' to compile with the dart web components compiler every | 31 * Set up 'build.dart' to compile with the dart web components compiler every |
| 32 * [entryPoints] listed. On clean commands, the directory where [entryPoints] | 32 * [entryPoints] listed. On clean commands, the directory where [entryPoints] |
| 33 * live will be scanned for generated files to delete them. | 33 * live will be scanned for generated files to delete them. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 // We'll set 'out/' as the out folder, unless an output directory was | 77 // We'll set 'out/' as the out folder, unless an output directory was |
| 78 // already specified in the command line. | 78 // already specified in the command line. |
| 79 if (options.outputDir == null) dwcArgs.addAll(['-o', _outDir(file)]); | 79 if (options.outputDir == null) dwcArgs.addAll(['-o', _outDir(file)]); |
| 80 dwcArgs.add(file); | 80 dwcArgs.add(file); |
| 81 // Chain tasks to that we run one at a time. | 81 // Chain tasks to that we run one at a time. |
| 82 lastTask = lastTask.then((_) => dwc.run(dwcArgs, printTime: printTime, | 82 lastTask = lastTask.then((_) => dwc.run(dwcArgs, printTime: printTime, |
| 83 shouldPrint: shouldPrint)); | 83 shouldPrint: shouldPrint)); |
| 84 if (machineFormat) { | 84 if (machineFormat) { |
| 85 lastTask = lastTask.then((res) { | 85 lastTask = lastTask.then((res) { |
| 86 appendMessage(Map jsonMessage) { | 86 appendMessage(Map jsonMessage) { |
| 87 var message = json.stringify([jsonMessage]); | 87 var message = JSON.encode([jsonMessage]); |
| 88 if (shouldPrint) print(message); | 88 if (shouldPrint) print(message); |
| 89 res.messages.add(message); | 89 res.messages.add(message); |
| 90 } | 90 } |
| 91 // Print for the Editor messages about mappings and generated files | 91 // Print for the Editor messages about mappings and generated files |
| 92 res.outputs.forEach((out, input) { | 92 res.outputs.forEach((out, input) { |
| 93 if (out.endsWith(".html") && input != null) { | 93 if (out.endsWith(".html") && input != null) { |
| 94 appendMessage({ | 94 appendMessage({ |
| 95 "method": "mapping", | 95 "method": "mapping", |
| 96 "params": {"from": input, "to": out}, | 96 "params": {"from": input, "to": out}, |
| 97 }); | 97 }); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 if (args["help"]) { | 157 if (args["help"]) { |
| 158 print('A build script that invokes the web-ui compiler (dwc).'); | 158 print('A build script that invokes the web-ui compiler (dwc).'); |
| 159 print('Usage: dart build.dart [options] [-- [dwc-options]]'); | 159 print('Usage: dart build.dart [options] [-- [dwc-options]]'); |
| 160 print('\nThese are valid options expected by build.dart:'); | 160 print('\nThese are valid options expected by build.dart:'); |
| 161 print(parser.getUsage()); | 161 print(parser.getUsage()); |
| 162 print('\nThese are valid options expected by dwc:'); | 162 print('\nThese are valid options expected by dwc:'); |
| 163 dwc.run(['-h']).then((_) => exit(0)); | 163 dwc.run(['-h']).then((_) => exit(0)); |
| 164 } | 164 } |
| 165 return args; | 165 return args; |
| 166 } | 166 } |
| OLD | NEW |