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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/polymer/lib/builder_init.dart » ('j') | pkg/polymer/lib/builder_init.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/polymer/lib/builder.dart
diff --git a/pkg/polymer/lib/builder.dart b/pkg/polymer/lib/builder.dart
index a2eb80fe467c3650be771424b07168ece67e90f2..e85217d1fea7454757068407844416a014c60ff0 100644
--- a/pkg/polymer/lib/builder.dart
+++ b/pkg/polymer/lib/builder.dart
@@ -83,6 +83,7 @@ import 'dart:async';
import 'dart:io';
import 'package:args/args.dart';
+import 'package:yaml/yaml.dart';
import 'src/build/linter.dart';
import 'src/build/runner.dart';
@@ -116,6 +117,8 @@ Future build({List<String> entryPoints, CommandLineOptions options,
' options to build(). Running as if no options were passed.');
options = parseOptions([]);
}
+ if (entryPoints == null) entryPoints = _parseEntryPointsFromPubspec();
+
return options.forceDeploy
? deploy(entryPoints: entryPoints, options: options,
currentPackage: currentPackage, packageDirs: packageDirs)
@@ -145,8 +148,10 @@ Future lint({List<String> entryPoints, CommandLineOptions options,
options = parseOptions([]);
}
if (currentPackage == null) currentPackage = readCurrentPackageFromPubspec();
+ if (entryPoints == null) entryPoints = _parseEntryPointsFromPubspec();
var linterOptions = new TransformOptions(entryPoints: entryPoints);
var linter = new Linter(linterOptions);
+
return runBarback(new BarbackOptions([[linter]], null,
currentPackage: currentPackage, packageDirs: packageDirs,
machineFormat: options.machineFormat));
@@ -177,6 +182,7 @@ Future deploy({List<String> entryPoints, CommandLineOptions options,
options = parseOptions([]);
}
if (currentPackage == null) currentPackage = readCurrentPackageFromPubspec();
+ if (entryPoints == null) entryPoints = _parseEntryPointsFromPubspec();
var transformOptions = new TransformOptions(
entryPoints: entryPoints,
@@ -318,3 +324,39 @@ CommandLineOptions parseOptions([List<String> args]) {
res['full'], res['machine'], res['deploy'], res['out'], res['js'],
res['csp'], !res['debug']);
}
+
+List<String> _parseEntryPointsFromPubspec() {
+ var entryPoints = [];
+ var pubspec = new File('pubspec.yaml');
+ 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.
+ print('error: pubspec.yaml file not found, please run this script from '
+ 'your package root directory.');
+ return entryPoints;
+ }
+ var transformers = loadYaml(pubspec.readAsStringSync())['transformers'];
+ if (transformers == null) return entryPoints;
+ 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.
+ print('Unexpected value for transformers, expected a List<Map>.');
+ return entryPoints;
+ }
+
+ transformers.forEach((t) {
+ var polymer = t['polymer'];
+ if (polymer == null) return;
+ var parsedEntryPoints = polymer['entry_points'];
+ if (parsedEntryPoints == null) return;
+
+ var error = false;
+ if (parsedEntryPoints is String) parsedEntryPoints = [parsedEntryPoints];
+ 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.
+ 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.
+ if (error) {
+ print('Invalid value for "entry_points" in polymer transformer. Expected '
+ 'a String or List<String>.');
+ return;
+ }
+
+ 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
+ });
+ return entryPoints;
+}
« 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