| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 /** Transfomer used for pub-serve and pub-deploy. */ | 5 /** Transfomer used for pub-serve and pub-deploy. */ |
| 6 library polymer.transformer; | 6 library polymer.transformer; |
| 7 | 7 |
| 8 import 'package:barback/barback.dart'; | 8 import 'package:barback/barback.dart'; |
| 9 import 'package:observe/transformer.dart'; | 9 import 'package:observe/transformer.dart'; |
| 10 |
| 11 import 'src/build/build_filter.dart'; |
| 10 import 'src/build/code_extractor.dart'; | 12 import 'src/build/code_extractor.dart'; |
| 13 import 'src/build/common.dart'; |
| 11 import 'src/build/import_inliner.dart'; | 14 import 'src/build/import_inliner.dart'; |
| 15 import 'src/build/polyfill_injector.dart'; |
| 12 import 'src/build/script_compactor.dart'; | 16 import 'src/build/script_compactor.dart'; |
| 13 import 'src/build/polyfill_injector.dart'; | |
| 14 import 'src/build/common.dart'; | |
| 15 | 17 |
| 16 /** | 18 /** |
| 17 * The Polymer transformer, which internally runs several phases that will: | 19 * The Polymer transformer, which internally runs several phases that will: |
| 18 * * Extract inlined script tags into their separate files | 20 * * Extract inlined script tags into their separate files |
| 19 * * Apply the observable transformer on every Dart script. | 21 * * Apply the observable transformer on every Dart script. |
| 20 * * Inline imported html files | 22 * * Inline imported html files |
| 21 * * Combine scripts from multiple files into a single script tag | 23 * * Combine scripts from multiple files into a single script tag |
| 22 * * Inject extra polyfills needed to run on all browsers. | 24 * * Inject extra polyfills needed to run on all browsers. |
| 23 * | 25 * |
| 24 * At the end of these phases, this tranformer produces a single entrypoint HTML | 26 * At the end of these phases, this tranformer produces a single entrypoint HTML |
| 25 * file with a single Dart script that can later be compiled with dart2js. | 27 * file with a single Dart script that can later be compiled with dart2js. |
| 26 */ | 28 */ |
| 27 class PolymerTransformerGroup implements TransformerGroup { | 29 class PolymerTransformerGroup implements TransformerGroup { |
| 28 final Iterable<Iterable> phases; | 30 final Iterable<Iterable> phases; |
| 29 | 31 |
| 30 PolymerTransformerGroup(TransformOptions options) | 32 PolymerTransformerGroup(TransformOptions options) |
| 31 : phases = _createDeployPhases(options); | 33 : phases = _createDeployPhases(options); |
| 32 | 34 |
| 33 PolymerTransformerGroup.asPlugin(BarbackSettings settings) | 35 PolymerTransformerGroup.asPlugin(BarbackSettings settings) |
| 34 : this(_parseSettings(settings)); | 36 : this(_parseSettings(settings)); |
| 35 } | 37 } |
| 36 | 38 |
| 37 TransformOptions _parseSettings(BarbackSettings settings) { | 39 TransformOptions _parseSettings(BarbackSettings settings) { |
| 38 var args = settings.configuration; | 40 var args = settings.configuration; |
| 39 bool release = settings.mode == BarbackMode.RELEASE; | 41 bool releaseMode = settings.mode == BarbackMode.RELEASE; |
| 40 bool jsOption = args['js']; | 42 bool jsOption = args['js']; |
| 41 bool csp = args['csp'] == true; // defaults to false | 43 bool csp = args['csp'] == true; // defaults to false |
| 42 return new TransformOptions( | 44 return new TransformOptions( |
| 43 entryPoints: _readEntrypoints(args['entry_points']), | 45 entryPoints: _readEntrypoints(args['entry_points']), |
| 44 directlyIncludeJS: jsOption == null ? release : jsOption, | 46 directlyIncludeJS: jsOption == null ? releaseMode : jsOption, |
| 45 contentSecurityPolicy: csp); | 47 contentSecurityPolicy: csp, |
| 48 releaseMode: releaseMode); |
| 46 } | 49 } |
| 47 | 50 |
| 48 _readEntrypoints(value) { | 51 _readEntrypoints(value) { |
| 49 if (value == null) return null; | 52 if (value == null) return null; |
| 50 var entryPoints = []; | 53 var entryPoints = []; |
| 51 bool error; | 54 bool error; |
| 52 if (value is List) { | 55 if (value is List) { |
| 53 entryPoints = value; | 56 entryPoints = value; |
| 54 error = value.any((e) => e is! String); | 57 error = value.any((e) => e is! String); |
| 55 } else if (value is String) { | 58 } else if (value is String) { |
| 56 entryPoints = [value]; | 59 entryPoints = [value]; |
| 57 error = false; | 60 error = false; |
| 58 } else { | 61 } else { |
| 59 error = true; | 62 error = true; |
| 60 } | 63 } |
| 61 if (error) { | 64 if (error) { |
| 62 print('Invalid value for "entry_points" in the polymer transformer.'); | 65 print('Invalid value for "entry_points" in the polymer transformer.'); |
| 63 } | 66 } |
| 64 return entryPoints; | 67 return entryPoints; |
| 65 } | 68 } |
| 66 | 69 |
| 67 List<List<Transformer>> _createDeployPhases(TransformOptions options) { | 70 List<List<Transformer>> _createDeployPhases(TransformOptions options) { |
| 68 return [ | 71 return [ |
| 69 [new InlineCodeExtractor(options)], | 72 [new InlineCodeExtractor(options)], |
| 70 [new ObservableTransformer()], | 73 [new ObservableTransformer()], |
| 71 [new ImportInliner(options)], | 74 [new ImportInliner(options)], |
| 72 [new ScriptCompactor(options)], | 75 [new ScriptCompactor(options)], |
| 73 [new PolyfillInjector(options)] | 76 [new PolyfillInjector(options)], |
| 77 [new BuildFilter(options)] |
| 74 ]; | 78 ]; |
| 75 } | 79 } |
| OLD | NEW |