| 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 /** This library is deprecated. Please use `build_helper.dart` instead. */ | 
| 6  * Common logic to make it easy to create a `build.dart` for your project. | 6 @deprecated | 
| 7  * |  | 
| 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 |  | 
| 10  * (where pubspec.yaml lives) and should be named exactly 'build.dart'. |  | 
| 11  * |  | 
| 12  * A common `build.dart` would look as follows: |  | 
| 13  * |  | 
| 14  *     import 'dart:io'; |  | 
| 15  *     import 'package:polymer/component_build.dart'; |  | 
| 16  * |  | 
| 17  *     main() => build(new Options().arguments, ['web/index.html']); |  | 
| 18  */ |  | 
| 19 library build_utils; | 7 library build_utils; | 
| 20 | 8 | 
| 21 import 'dart:async'; | 9 import 'package:meta/meta.dart'; | 
| 22 import 'dart:convert'; |  | 
| 23 import 'dart:io'; |  | 
| 24 import 'package:args/args.dart'; |  | 
| 25 | 10 | 
| 26 import 'dwc.dart' as dwc; | 11 import 'build_helper.dart'; | 
| 27 import 'src/utils.dart'; |  | 
| 28 import 'src/compiler_options.dart'; |  | 
| 29 | 12 | 
| 30 /** | 13 /** | 
| 31  * Set up 'build.dart' to compile with the dart web components compiler every | 14  * This function is deprecated. Please use `lint` from `build_helper.dart` | 
| 32  * [entryPoints] listed. On clean commands, the directory where [entryPoints] | 15  * instead. | 
| 33  * live will be scanned for generated files to delete them. |  | 
| 34  */ | 16  */ | 
| 35 Future<List<dwc.AnalysisResults>> build(List<String> arguments, | 17 @deprecated | 
| 36     List<String> entryPoints, | 18 Future build(List<String> arguments, List<String> entryPoints, | 
| 37     {bool printTime: true, bool shouldPrint: true}) { | 19     {bool printTime: true, bool shouldPrint: true}) { | 
| 38   bool useColors = stdioType(stdout) == StdioType.TERMINAL; | 20   return lint(entrypoints: entryPoints, options: parseOptions(arguments)); | 
| 39   return asyncTime('Total time', () { |  | 
| 40     var args = _processArgs(arguments); |  | 
| 41     var tasks = new FutureGroup(); |  | 
| 42     var lastTask = new Future.value(null); |  | 
| 43     tasks.add(lastTask); |  | 
| 44 |  | 
| 45     var changedFiles = args["changed"]; |  | 
| 46     var removedFiles = args["removed"]; |  | 
| 47     var cleanBuild = args["clean"]; |  | 
| 48     var machineFormat = args["machine"]; |  | 
| 49     // Also trigger a full build if the script was run from the command line |  | 
| 50     // with no arguments |  | 
| 51     var fullBuild = args["full"] || (!machineFormat && changedFiles.isEmpty && |  | 
| 52         removedFiles.isEmpty && !cleanBuild); |  | 
| 53 |  | 
| 54     var options = CompilerOptions.parse(args.rest, checkUsage: false); |  | 
| 55 |  | 
| 56     if (fullBuild || !changedFiles.isEmpty || !removedFiles.isEmpty) { |  | 
| 57       for (var file in entryPoints) { |  | 
| 58         var dwcArgs = new List.from(args.rest); |  | 
| 59         if (machineFormat) dwcArgs.add('--json_format'); |  | 
| 60         if (!useColors) dwcArgs.add('--no-colors'); |  | 
| 61         dwcArgs.add(file); |  | 
| 62         // Chain tasks to that we run one at a time. |  | 
| 63         lastTask = lastTask.then((_) => dwc.run(dwcArgs, printTime: printTime, |  | 
| 64             shouldPrint: shouldPrint)); |  | 
| 65         if (machineFormat) { |  | 
| 66           lastTask = lastTask.then((res) { |  | 
| 67             appendMessage(Map jsonMessage) { |  | 
| 68               var message = JSON.encode([jsonMessage]); |  | 
| 69               if (shouldPrint) print(message); |  | 
| 70               res.messages.add(message); |  | 
| 71             } |  | 
| 72             return res; |  | 
| 73           }); |  | 
| 74         } |  | 
| 75         tasks.add(lastTask); |  | 
| 76       } |  | 
| 77     } |  | 
| 78     return tasks.future.then((r) => r.where((v) => v != null)); |  | 
| 79   }, printTime: printTime, useColors: useColors); |  | 
| 80 } | 21 } | 
| 81 |  | 
| 82 /** Process the command-line arguments. */ |  | 
| 83 ArgResults _processArgs(List<String> arguments) { |  | 
| 84   var parser = new ArgParser() |  | 
| 85     ..addOption("changed", help: "the file has changed since the last build", |  | 
| 86         allowMultiple: true) |  | 
| 87     ..addOption("removed", help: "the file was removed since the last build", |  | 
| 88         allowMultiple: true) |  | 
| 89     ..addFlag("clean", negatable: false, help: "currently a noop, may be used " |  | 
| 90         "in the future to remove any build artifacts") |  | 
| 91     ..addFlag("full", negatable: false, help: "perform a full build") |  | 
| 92     ..addFlag("machine", negatable: false, |  | 
| 93         help: "produce warnings in a machine parseable format") |  | 
| 94     ..addFlag("help", abbr: 'h', |  | 
| 95         negatable: false, help: "displays this help and exit"); |  | 
| 96   var args = parser.parse(arguments); |  | 
| 97   if (args["help"]) { |  | 
| 98     print('A build script that invokes the web-ui compiler (dwc).'); |  | 
| 99     print('Usage: dart build.dart [options] [-- [dwc-options]]'); |  | 
| 100     print('\nThese are valid options expected by build.dart:'); |  | 
| 101     print(parser.getUsage()); |  | 
| 102     print('\nThese are valid options expected by dwc:'); |  | 
| 103     dwc.run(['-h']).then((_) => exit(0)); |  | 
| 104   } |  | 
| 105   return args; |  | 
| 106 } |  | 
| OLD | NEW | 
|---|