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

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

Issue 569393002: no longer require entry points to be specified in the build.dart file (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: more robust reading of entry points Created 6 years, 3 months 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
« no previous file with comments | « no previous file | pkg/polymer/lib/builder_init.dart » ('j') | pkg/polymer/lib/builder_init.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 /// 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
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:yaml/yaml.dart';
86 87
87 import 'src/build/linter.dart'; 88 import 'src/build/linter.dart';
88 import 'src/build/runner.dart'; 89 import 'src/build/runner.dart';
89 import 'src/build/common.dart'; 90 import 'src/build/common.dart';
90 91
91 import 'transformer.dart'; 92 import 'transformer.dart';
92 93
93 94
94 /// 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
95 /// .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
(...skipping 13 matching lines...) Expand all
109 /// and the location where to find the code for any package it depends on 110 /// 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 111 /// ([packageDirs]). This is inferred automatically, but can be overriden if
111 /// those arguments are provided. 112 /// those arguments are provided.
112 Future build({List<String> entryPoints, CommandLineOptions options, 113 Future build({List<String> entryPoints, CommandLineOptions options,
113 String currentPackage, Map<String, String> packageDirs}) { 114 String currentPackage, Map<String, String> packageDirs}) {
114 if (options == null) { 115 if (options == null) {
115 print('warning: now that main takes arguments, you need to explicitly pass' 116 print('warning: now that main takes arguments, you need to explicitly pass'
116 ' options to build(). Running as if no options were passed.'); 117 ' options to build(). Running as if no options were passed.');
117 options = parseOptions([]); 118 options = parseOptions([]);
118 } 119 }
120 if (entryPoints == null) entryPoints = _parseEntryPointsFromPubspec();
121
119 return options.forceDeploy 122 return options.forceDeploy
120 ? deploy(entryPoints: entryPoints, options: options, 123 ? deploy(entryPoints: entryPoints, options: options,
121 currentPackage: currentPackage, packageDirs: packageDirs) 124 currentPackage: currentPackage, packageDirs: packageDirs)
122 : lint(entryPoints: entryPoints, options: options, 125 : lint(entryPoints: entryPoints, options: options,
123 currentPackage: currentPackage, packageDirs: packageDirs); 126 currentPackage: currentPackage, packageDirs: packageDirs);
124 } 127 }
125 128
126 129
127 /// Runs the polymer linter on any relevant file in your package, 130 /// Runs the polymer linter on any relevant file in your package,
128 /// such as any .html file under 'lib/', 'asset/', and 'web/'. 131 /// such as any .html file under 'lib/', 'asset/', and 'web/'.
129 /// 132 ///
130 /// The [entryPoints] list contains files under web/ that should be treated as 133 /// 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 134 /// 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 135 /// root (for example 'web/index.html'). If null, all files under 'web/' are
133 /// treated as possible entry points. 136 /// treated as possible entry points.
134 /// 137 ///
135 /// Options must be passed by passing the [options] argument. 138 /// Options must be passed by passing the [options] argument.
136 /// 139 ///
137 /// The linter needs to know the name of the [currentPackage] and the location 140 /// 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 141 /// 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. 142 /// is inferred automatically, but can be overriden by passing the arguments.
140 Future lint({List<String> entryPoints, CommandLineOptions options, 143 Future lint({List<String> entryPoints, CommandLineOptions options,
141 String currentPackage, Map<String, String> packageDirs}) { 144 String currentPackage, Map<String, String> packageDirs}) {
142 if (options == null) { 145 if (options == null) {
143 print('warning: now that main takes arguments, you need to explicitly pass' 146 print('warning: now that main takes arguments, you need to explicitly pass'
144 ' options to lint(). Running as if no options were passed.'); 147 ' options to lint(). Running as if no options were passed.');
145 options = parseOptions([]); 148 options = parseOptions([]);
146 } 149 }
147 if (currentPackage == null) currentPackage = readCurrentPackageFromPubspec(); 150 if (currentPackage == null) currentPackage = readCurrentPackageFromPubspec();
151 if (entryPoints == null) entryPoints = _parseEntryPointsFromPubspec();
148 var linterOptions = new TransformOptions(entryPoints: entryPoints); 152 var linterOptions = new TransformOptions(entryPoints: entryPoints);
149 var linter = new Linter(linterOptions); 153 var linter = new Linter(linterOptions);
154
150 return runBarback(new BarbackOptions([[linter]], null, 155 return runBarback(new BarbackOptions([[linter]], null,
151 currentPackage: currentPackage, packageDirs: packageDirs, 156 currentPackage: currentPackage, packageDirs: packageDirs,
152 machineFormat: options.machineFormat)); 157 machineFormat: options.machineFormat));
153 } 158 }
154 159
155 /// Creates a directory suitable for deploying a Polymer application to a 160 /// Creates a directory suitable for deploying a Polymer application to a
156 /// server. 161 /// server.
157 /// 162 ///
158 /// **Note**: this function will be replaced in the future by the `pub deploy` 163 /// **Note**: this function will be replaced in the future by the `pub deploy`
159 /// command. 164 /// command.
(...skipping 10 matching lines...) Expand all
170 /// ([packageDirs]). This is inferred automatically, but can be overriden if 175 /// ([packageDirs]). This is inferred automatically, but can be overriden if
171 /// those arguments are provided. 176 /// those arguments are provided.
172 Future deploy({List<String> entryPoints, CommandLineOptions options, 177 Future deploy({List<String> entryPoints, CommandLineOptions options,
173 String currentPackage, Map<String, String> packageDirs}) { 178 String currentPackage, Map<String, String> packageDirs}) {
174 if (options == null) { 179 if (options == null) {
175 print('warning: now that main takes arguments, you need to explicitly pass' 180 print('warning: now that main takes arguments, you need to explicitly pass'
176 ' options to deploy(). Running as if no options were passed.'); 181 ' options to deploy(). Running as if no options were passed.');
177 options = parseOptions([]); 182 options = parseOptions([]);
178 } 183 }
179 if (currentPackage == null) currentPackage = readCurrentPackageFromPubspec(); 184 if (currentPackage == null) currentPackage = readCurrentPackageFromPubspec();
185 if (entryPoints == null) entryPoints = _parseEntryPointsFromPubspec();
180 186
181 var transformOptions = new TransformOptions( 187 var transformOptions = new TransformOptions(
182 entryPoints: entryPoints, 188 entryPoints: entryPoints,
183 directlyIncludeJS: options.directlyIncludeJS, 189 directlyIncludeJS: options.directlyIncludeJS,
184 contentSecurityPolicy: options.contentSecurityPolicy, 190 contentSecurityPolicy: options.contentSecurityPolicy,
185 releaseMode: options.releaseMode); 191 releaseMode: options.releaseMode);
186 192
187 var phases = new PolymerTransformerGroup(transformOptions).phases; 193 var phases = new PolymerTransformerGroup(transformOptions).phases;
188 var barbackOptions = new BarbackOptions( 194 var barbackOptions = new BarbackOptions(
189 phases, options.outDir, currentPackage: currentPackage, 195 phases, options.outDir, currentPackage: currentPackage,
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 } 317 }
312 if (res['help']) { 318 if (res['help']) {
313 print('A build script that invokes the polymer linter and deploy tools.'); 319 print('A build script that invokes the polymer linter and deploy tools.');
314 showUsage(); 320 showUsage();
315 exit(0); 321 exit(0);
316 } 322 }
317 return new CommandLineOptions(res['changed'], res['removed'], res['clean'], 323 return new CommandLineOptions(res['changed'], res['removed'], res['clean'],
318 res['full'], res['machine'], res['deploy'], res['out'], res['js'], 324 res['full'], res['machine'], res['deploy'], res['out'], res['js'],
319 res['csp'], !res['debug']); 325 res['csp'], !res['debug']);
320 } 326 }
327
328 List<String> _parseEntryPointsFromPubspec() {
329 var entryPoints = [];
330 var pubspec = new File('pubspec.yaml');
331 if (!pubspec.existsSync()) {
Siggi Cherem (dart-lang) 2014/09/15 21:35:20 one option here - instead of using the CWD, use th
jakemac 2014/09/15 22:20:51 Done.
332 print('error: pubspec.yaml file not found, please run this script from '
333 'your package root directory.');
334 return entryPoints;
335 }
336 var transformers = loadYaml(pubspec.readAsStringSync())['transformers'];
337 if (transformers == null) return entryPoints;
338 if (transformers is! List || transformers.any((t) => t is! Map)) {
Siggi Cherem (dart-lang) 2014/09/15 21:35:20 entries in the transformer can actually be strings
jakemac 2014/09/15 22:20:52 Done.
339 print('Unexpected value for transformers, expected a List<Map>.');
340 return entryPoints;
341 }
342
343 transformers.forEach((t) {
344 var polymer = t['polymer'];
345 if (polymer == null) return;
346 var parsedEntryPoints = polymer['entry_points'];
347 if (parsedEntryPoints == null) return;
348
349 var error = false;
350 if (parsedEntryPoints is String) parsedEntryPoints = [parsedEntryPoints];
351 else if (parsedEntryPoints is! List) error = true;
Siggi Cherem (dart-lang) 2014/09/15 21:35:20 style nit: use { } in this and the previous line.
jakemac 2014/09/15 22:20:52 Done.
352 if (parsedEntryPoints.any((e) => e is! String)) error = true;
Siggi Cherem (dart-lang) 2014/09/15 21:35:20 actually - to avoid code duplication, you could ju
jakemac 2014/09/15 22:20:52 Done.
353 if (error) {
354 print('Invalid value for "entry_points" in polymer transformer. Expected '
355 'a String or List<String>.');
356 return;
357 }
358
359 entryPoints.addAll(parsedEntryPoints);
Siggi Cherem (dart-lang) 2014/09/15 21:35:20 also return here? (once we find the polymer sectio
jakemac 2014/09/15 22:20:52 Technically, it works to have multiple different p
360 });
361 return entryPoints;
362 }
OLDNEW
« no previous file with comments | « no previous file | pkg/polymer/lib/builder_init.dart » ('j') | pkg/polymer/lib/builder_init.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698