Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: pkg/polymer/lib/builder.dart

Issue 112843004: Add linter by default for polymer's pub-build, also cleans up the linter code. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 21 matching lines...) Expand all
32 * lint(); 32 * lint();
33 * } 33 * }
34 * 34 *
35 * **Example 2**: Runs the linter and creates a deployable version of the app 35 * **Example 2**: Runs the linter and creates a deployable version of the app
36 * every time. 36 * every time.
37 * 37 *
38 * import 'dart:io'; 38 * import 'dart:io';
39 * import 'package:polymer/builder.dart'; 39 * import 'package:polymer/builder.dart';
40 * 40 *
41 * main() { 41 * main() {
42 * lint().then((_) => deploy()); 42 * deploy(); // deploy also calls the linter internally.
43 * } 43 * }
44 * 44 *
45 * **Example 3**: Runs the linter, but conditionally does the deploy step. See 45 * **Example 3**: Always run the linter, but conditionally build a deployable
46 * [parseOptions] for a description of options parsed automatically by this 46 * version. See [parseOptions] for a description of options parsed automatically
47 * helper library. 47 * by this helper library.
48 * 48 *
49 * import 'dart:io'; 49 * import 'dart:io';
50 * import 'package:polymer/builder.dart'; 50 * import 'package:polymer/builder.dart';
51 * 51 *
52 * main(args) { 52 * main(args) {
53 * var options = parseOptions(args); 53 * var options = parseOptions(args);
54 * lint().then((_) { 54 * if (options.forceDeploy) {
55 * if (options.forceDeploy) deploy(); 55 * deploy();
56 * }); 56 * } else {
57 * lint();
58 * }
57 * } 59 * }
58 * 60 *
59 * **Example 4**: Same as above, but uses [build] (which internally calls [lint] 61 * **Example 4**: Same as above, but uses [build] (which internally calls either
60 * and optionally calls [deploy]). 62 * [lint] or [deploy]).
61 * 63 *
62 * import 'dart:io'; 64 * import 'dart:io';
63 * import 'package:polymer/builder.dart'; 65 * import 'package:polymer/builder.dart';
64 * 66 *
65 * main(args) { 67 * main(args) {
66 * build(options: parseOptions(args)); 68 * build(options: parseOptions(args));
67 * } 69 * }
68 * 70 *
69 * **Example 5**: Like the previous example, but indicates to the linter and 71 * **Example 5**: Like the previous example, but indicates to the linter and
70 * deploy tool which files are actually used as entry point files. See the 72 * deploy tool which files are actually used as entry point files. See the
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 * ([packageDirs]). This is inferred automatically, but can be overriden if 113 * ([packageDirs]). This is inferred automatically, but can be overriden if
112 * those arguments are provided. 114 * those arguments are provided.
113 */ 115 */
114 Future build({List<String> entryPoints, CommandLineOptions options, 116 Future build({List<String> entryPoints, CommandLineOptions options,
115 String currentPackage, Map<String, String> packageDirs}) { 117 String currentPackage, Map<String, String> packageDirs}) {
116 if (options == null) { 118 if (options == null) {
117 print('warning: now that main takes arguments, you need to explicitly pass' 119 print('warning: now that main takes arguments, you need to explicitly pass'
118 ' options to build(). Running as if no options were passed.'); 120 ' options to build(). Running as if no options were passed.');
119 options = parseOptions([]); 121 options = parseOptions([]);
120 } 122 }
121 return lint(entryPoints: entryPoints, options: options, 123 return options.forceDeploy
122 currentPackage: currentPackage, packageDirs: packageDirs).then((res) { 124 ? deploy(entryPoints: entryPoints, options: options,
123 if (options.forceDeploy) { 125 currentPackage: currentPackage, packageDirs: packageDirs)
124 return deploy(entryPoints: entryPoints, options: options, 126 : lint(entryPoints: entryPoints, options: options,
125 currentPackage: currentPackage, packageDirs: packageDirs); 127 currentPackage: currentPackage, packageDirs: packageDirs);
126 }
127 });
128 } 128 }
129 129
130 130
131 /** 131 /**
132 * Runs the polymer linter on any relevant file in your package, 132 * Runs the polymer linter on any relevant file in your package,
133 * such as any .html file under 'lib/', 'asset/', and 'web/'. 133 * such as any .html file under 'lib/', 'asset/', and 'web/'.
134 * 134 *
135 * The [entryPoints] list contains files under web/ that should be treated as 135 * The [entryPoints] list contains files under web/ that should be treated as
136 * entry points. Each entry on this list is a relative path from the package 136 * entry points. Each entry on this list is a relative path from the package
137 * root (for example 'web/index.html'). If null, all files under 'web/' are 137 * root (for example 'web/index.html'). If null, all files under 'web/' are
138 * treated as possible entry points. 138 * treated as possible entry points.
139 * 139 *
140 * Options must be passed by passing the [options] argument. 140 * Options must be passed by passing the [options] argument.
141 * 141 *
142 * The linter needs to know the name of the [currentPackage] and the location 142 * The linter needs to know the name of the [currentPackage] and the location
143 * where to find the code for any package it depends on ([packageDirs]). This is 143 * where to find the code for any package it depends on ([packageDirs]). This is
144 * inferred automatically, but can be overriden if those arguments are provided. 144 * inferred automatically, but can be overriden if those arguments are provided.
145 */ 145 */
146 Future lint({List<String> entryPoints, CommandLineOptions options, 146 Future lint({List<String> entryPoints, CommandLineOptions options,
147 String currentPackage, Map<String, String> packageDirs}) { 147 String currentPackage, Map<String, String> packageDirs}) {
148 if (options == null) { 148 if (options == null) {
149 print('warning: now that main takes arguments, you need to explicitly pass' 149 print('warning: now that main takes arguments, you need to explicitly pass'
150 ' options to lint(). Running as if no options were passed.'); 150 ' options to lint(). Running as if no options were passed.');
151 options = parseOptions([]); 151 options = parseOptions([]);
152 } 152 }
153 if (currentPackage == null) currentPackage = readCurrentPackageFromPubspec(); 153 if (currentPackage == null) currentPackage = readCurrentPackageFromPubspec();
154 var linterOptions = new TransformOptions(entryPoints: entryPoints); 154 var linterOptions = new TransformOptions(entryPoints: entryPoints);
155 var formatter = options.machineFormat ? jsonFormatter : consoleFormatter; 155 var linter = new Linter(linterOptions);
156 var linter = new Linter(linterOptions, formatter);
157 return runBarback(new BarbackOptions([[linter]], null, 156 return runBarback(new BarbackOptions([[linter]], null,
158 currentPackage: currentPackage, packageDirs: packageDirs)).then((assets) { 157 currentPackage: currentPackage, packageDirs: packageDirs,
159 var messages = {}; 158 machineFormat: options.machineFormat));
160 var futures = [];
161 for (var asset in assets) {
162 var id = asset.id;
163 if (id.package == currentPackage && id.path.endsWith('.messages')) {
164 futures.add(asset.readAsString().then((content) {
165 if (content.isEmpty) return;
166 messages[id] = content;
167 }));
168 }
169 }
170
171 return Future.wait(futures).then((_) {
172 // Print messages sorting by package and filepath.
173 var orderedKeys = messages.keys.toList();
174 orderedKeys.sort((a, b) {
175 int packageCompare = a.package.compareTo(b.package);
176 if (packageCompare != 0) return packageCompare;
177 return a.path.compareTo(b.path);
178 });
179
180 for (var key in orderedKeys) {
181 print(messages[key]);
182 }
183 });
184 });
185 } 159 }
186 160
187 /** 161 /**
188 * Creates a directory suitable for deploying a Polymer application to a server. 162 * Creates a directory suitable for deploying a Polymer application to a server.
189 * 163 *
190 * **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`
191 * command. 165 * command.
192 * 166 *
193 * The [entryPoints] list contains files under web/ that should be treated as 167 * The [entryPoints] list contains files under web/ that should be treated as
194 * entry points. Each entry on this list is a relative path from the package 168 * entry points. Each entry on this list is a relative path from the package
(...skipping 18 matching lines...) Expand all
213 187
214 var transformOptions = new TransformOptions( 188 var transformOptions = new TransformOptions(
215 entryPoints: entryPoints, 189 entryPoints: entryPoints,
216 directlyIncludeJS: options.directlyIncludeJS, 190 directlyIncludeJS: options.directlyIncludeJS,
217 contentSecurityPolicy: options.contentSecurityPolicy, 191 contentSecurityPolicy: options.contentSecurityPolicy,
218 releaseMode: options.releaseMode); 192 releaseMode: options.releaseMode);
219 193
220 var barbackOptions = new BarbackOptions( 194 var barbackOptions = new BarbackOptions(
221 new PolymerTransformerGroup(transformOptions).phases, 195 new PolymerTransformerGroup(transformOptions).phases,
222 options.outDir, currentPackage: currentPackage, 196 options.outDir, currentPackage: currentPackage,
223 packageDirs: packageDirs); 197 packageDirs: packageDirs, machineFormat: options.machineFormat);
224 return runBarback(barbackOptions) 198 return runBarback(barbackOptions)
225 .then((_) => print('Done! All files written to "${options.outDir}"')); 199 .then((_) => print('Done! All files written to "${options.outDir}"'));
226 } 200 }
227 201
228 202
229 /** 203 /**
230 * Options that may be used either in build.dart or by the linter and deploy 204 * Options that may be used either in build.dart or by the linter and deploy
231 * tools. 205 * tools.
232 */ 206 */
233 class CommandLineOptions { 207 class CommandLineOptions {
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 } 324 }
351 if (res['help']) { 325 if (res['help']) {
352 print('A build script that invokes the polymer linter and deploy tools.'); 326 print('A build script that invokes the polymer linter and deploy tools.');
353 showUsage(); 327 showUsage();
354 exit(0); 328 exit(0);
355 } 329 }
356 return new CommandLineOptions(res['changed'], res['removed'], res['clean'], 330 return new CommandLineOptions(res['changed'], res['removed'], res['clean'],
357 res['full'], res['machine'], res['deploy'], res['out'], res['js'], 331 res['full'], res['machine'], res['deploy'], res['out'], res['js'],
358 res['csp'], !res['debug']); 332 res['csp'], !res['debug']);
359 } 333 }
OLDNEW
« no previous file with comments | « no previous file | pkg/polymer/lib/src/build/build_filter.dart » ('j') | pkg/polymer/lib/src/build/build_filter.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698