feat(dart/transform): Allow multiple transformer entry points
- Allow the user to specify multiple entry points to an app. - Allow the Angular 2 transformer to run without explicit entry points to generate necessary setters & getters on built-in directives like `For` and `If`. Closes #1246
This commit is contained in:
@ -1,35 +1,29 @@
|
||||
library angular2.transform.common.options;
|
||||
|
||||
const ENTRY_POINT_PARAM = 'entry_point';
|
||||
const REFLECTION_ENTRY_POINT_PARAM = 'reflection_entry_point';
|
||||
const ENTRY_POINT_PARAM = 'entry_points';
|
||||
const REFLECTION_ENTRY_POINT_PARAM = 'reflection_entry_points';
|
||||
|
||||
/// Provides information necessary to transform an Angular2 app.
|
||||
class TransformerOptions {
|
||||
/// The path to the file where the application's call to [bootstrap] is.
|
||||
// TODO(kegluneq): Allow multiple entry points.
|
||||
final String entryPoint;
|
||||
/// The path to the files where the application's calls to `bootstrap` are.
|
||||
final List<String> entryPoints;
|
||||
|
||||
/// The reflection entry point, that is, the path to the file where the
|
||||
/// application's [ReflectionCapabilities] are set.
|
||||
final String reflectionEntryPoint;
|
||||
/// The paths to the files where the application's [ReflectionCapabilities]
|
||||
/// are set.
|
||||
final List<String> reflectionEntryPoints;
|
||||
|
||||
/// The `BarbackMode#name` we are running in.
|
||||
final String modeName;
|
||||
|
||||
TransformerOptions._internal(
|
||||
this.entryPoint, this.reflectionEntryPoint, this.modeName);
|
||||
this.entryPoints, this.reflectionEntryPoints, this.modeName);
|
||||
|
||||
factory TransformerOptions(String entryPoint,
|
||||
{String reflectionEntryPoint, String modeName: 'release'}) {
|
||||
if (entryPoint == null) {
|
||||
throw new ArgumentError.notNull(ENTRY_POINT_PARAM);
|
||||
} else if (entryPoint.isEmpty) {
|
||||
throw new ArgumentError.value(entryPoint, 'entryPoint');
|
||||
}
|
||||
if (reflectionEntryPoint == null || entryPoint.isEmpty) {
|
||||
reflectionEntryPoint = entryPoint;
|
||||
factory TransformerOptions(List<String> entryPoints,
|
||||
{List<String> reflectionEntryPoints, String modeName: 'release'}) {
|
||||
if (reflectionEntryPoints == null || reflectionEntryPoints.isEmpty) {
|
||||
reflectionEntryPoints = entryPoints;
|
||||
}
|
||||
return new TransformerOptions._internal(
|
||||
entryPoint, reflectionEntryPoint, modeName);
|
||||
entryPoints, reflectionEntryPoints, modeName);
|
||||
}
|
||||
}
|
||||
|
36
modules/angular2/src/transform/common/options_reader.dart
Normal file
36
modules/angular2/src/transform/common/options_reader.dart
Normal file
@ -0,0 +1,36 @@
|
||||
library angular2.transform.common.options;
|
||||
|
||||
import 'package:barback/barback.dart';
|
||||
import 'options.dart';
|
||||
|
||||
TransformerOptions parseBarbackSettings(BarbackSettings settings) {
|
||||
var config = settings.configuration;
|
||||
var entryPoints = _readFileList(config, ENTRY_POINT_PARAM);
|
||||
var reflectionEntryPoints =
|
||||
_readFileList(config, REFLECTION_ENTRY_POINT_PARAM);
|
||||
return new TransformerOptions(entryPoints,
|
||||
reflectionEntryPoints: reflectionEntryPoints,
|
||||
modeName: settings.mode.name);
|
||||
}
|
||||
|
||||
/// Cribbed from the polymer project.
|
||||
/// [https://github.com/dart-lang/polymer-dart]
|
||||
List<String> _readFileList(Map config, String paramName) {
|
||||
var value = config[paramName];
|
||||
if (value == null) return null;
|
||||
var files = [];
|
||||
bool error = false;
|
||||
if (value is List) {
|
||||
files = value;
|
||||
error = value.any((e) => e is! String);
|
||||
} else if (value is String) {
|
||||
files = [value];
|
||||
error = false;
|
||||
} else {
|
||||
error = true;
|
||||
}
|
||||
if (error) {
|
||||
print('Invalid value for "$paramName" in the Angular 2 transformer.');
|
||||
}
|
||||
return files;
|
||||
}
|
Reference in New Issue
Block a user