| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 /// Transformer used for pub serve and pub build | 5 /// Transformer used for pub serve and pub build |
| 6 library web_components.transformer; | 6 library web_components.transformer; |
| 7 | 7 |
| 8 import 'package:barback/barback.dart'; | 8 import 'package:barback/barback.dart'; |
| 9 | 9 |
| 10 export 'build/html_import_annotation_recorder.dart'; | 10 export 'build/html_import_annotation_recorder.dart'; |
| 11 import 'build/import_inliner.dart'; | 11 import 'build/import_inliner.dart'; |
| 12 export 'build/import_inliner.dart'; | 12 export 'build/import_inliner.dart'; |
| 13 import 'build/script_compactor.dart'; | 13 import 'build/script_compactor.dart'; |
| 14 export 'build/script_compactor.dart'; | 14 export 'build/script_compactor.dart'; |
| 15 import 'build/test_compatibility.dart'; |
| 16 export 'build/test_compatibility.dart'; |
| 15 import 'build/web_components.dart'; | 17 import 'build/web_components.dart'; |
| 16 export 'build/web_components.dart'; | 18 export 'build/web_components.dart'; |
| 17 | 19 |
| 18 /// The Web Components transformer group, which internally runs several phases | 20 /// The Web Components transformer group, which internally runs several phases |
| 19 /// that: | 21 /// that: |
| 20 /// * Extract inlined script tags into separate files. | 22 /// * Extract inlined script tags into separate files. |
| 21 /// * Extract script tags from entry points and all html imports and add them | 23 /// * Extract script tags from entry points and all html imports and add them |
| 22 /// as dart imports in a new *.bootstrap.dart file. | 24 /// as dart imports in a new *.bootstrap.dart file. |
| 23 /// * Run the `initialize` transformer. | 25 /// * Run the `initialize` transformer. |
| 24 /// * Inlines @HtmlImport annotations as html imports into the entry point. | 26 /// * Inlines @HtmlImport annotations as html imports into the entry point. |
| 25 /// * Inline imported html files and remove all but the main dart script tag. | 27 /// * Inline imported html files and remove all but the main dart script tag. |
| 26 /// | 28 /// |
| 27 /// At the end of these phases, this tranformer produces a single entrypoint | 29 /// At the end of these phases, this tranformer produces a single entrypoint |
| 28 /// HTML file with a single Dart script that can later be compiled with dart2js. | 30 /// HTML file with a single Dart script that can later be compiled with dart2js. |
| 29 class WebComponentsTransformerGroup implements TransformerGroup { | 31 class WebComponentsTransformerGroup implements TransformerGroup { |
| 30 final Iterable<Iterable> phases; | 32 final Iterable<Iterable> phases; |
| 31 | 33 |
| 32 WebComponentsTransformerGroup(TransformOptions options) | 34 WebComponentsTransformerGroup(TransformOptions options) |
| 33 : phases = createDeployPhases(options); | 35 : phases = createDeployPhases(options); |
| 34 | 36 |
| 35 WebComponentsTransformerGroup.asPlugin(BarbackSettings settings) | 37 WebComponentsTransformerGroup.asPlugin(BarbackSettings settings) |
| 36 : this(_parseSettings(settings)); | 38 : this(_parseSettings(settings)); |
| 37 } | 39 } |
| 38 | 40 |
| 39 /// Create deploy phases for web_components. | 41 /// Create deploy phases for web_components. |
| 40 List<List<Transformer>> createDeployPhases(TransformOptions options, | 42 List<List<Transformer>> createDeployPhases(TransformOptions options, |
| 41 {String sdkDir}) { | 43 {String sdkDir}) { |
| 42 var phases = []; | 44 var phases = []; |
| 43 | 45 |
| 46 /// Must happen first, temporarily rewrites <link rel="x-dart-test"> tags to |
| 47 /// <script type="application/dart" _was_test></script> tags. |
| 48 phases.add([new RewriteXDartTestToScript(options.entryPoints)]); |
| 49 |
| 44 // Must happen before the WebComponents transformer, grabs all dart scripts | 50 // Must happen before the WebComponents transformer, grabs all dart scripts |
| 45 // and combines them into one bootstrap file. | 51 // and combines them into one bootstrap file. |
| 46 phases.add([new ScriptCompactorTransformer(options.entryPoints)]); | 52 phases.add([new ScriptCompactorTransformer(options.entryPoints)]); |
| 47 | 53 |
| 48 // Runs the customized version of the `initialize` transformer and inlines | 54 // Runs the customized version of the `initialize` transformer and inlines |
| 49 // @HtmlImport annotations. | 55 // @HtmlImport annotations. |
| 50 phases.add([new WebComponentsTransformer(options)]); | 56 phases.add([new WebComponentsTransformer(options)]); |
| 51 | 57 |
| 52 // Inlines all html imports and removes all dart script tags in the process. | 58 // Inlines all html imports and removes all dart script tags in the process. |
| 53 phases.add([new ImportInlinerTransformer(options.entryPoints)]); | 59 phases.add([new ImportInlinerTransformer(options.entryPoints)]); |
| 60 |
| 61 /// Must happen last, rewrites |
| 62 /// <script type="application/dart" _was_test></script> tags to |
| 63 /// <link rel="x-dart-test"> tags. |
| 64 phases.add([new RewriteScriptToXDartTest(options.entryPoints)]); |
| 54 return phases; | 65 return phases; |
| 55 } | 66 } |
| 56 | 67 |
| 57 /// Options used by web_components transformers | 68 /// Options used by web_components transformers |
| 58 class TransformOptions { | 69 class TransformOptions { |
| 59 /// List of entrypoints paths. The paths are relative to the package root and | 70 /// List of entrypoints paths. The paths are relative to the package root and |
| 60 /// are represented using posix style, which matches the representation used | 71 /// are represented using posix style, which matches the representation used |
| 61 /// in asset ids in barback. If null, any html file under 'web/' or 'test/' is | 72 /// in asset ids in barback. If null, any html file under 'web/' or 'test/' is |
| 62 /// considered an entry point. | 73 /// considered an entry point. |
| 63 final List<String> entryPoints; | 74 final List<String> entryPoints; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 error = false; | 113 error = false; |
| 103 } else { | 114 } else { |
| 104 error = true; | 115 error = true; |
| 105 } | 116 } |
| 106 if (error) { | 117 if (error) { |
| 107 print('Bad value for "entry_points" in the web_components transformer. ' | 118 print('Bad value for "entry_points" in the web_components transformer. ' |
| 108 'Expected either one String or a list of Strings.'); | 119 'Expected either one String or a list of Strings.'); |
| 109 } | 120 } |
| 110 return files; | 121 return files; |
| 111 } | 122 } |
| OLD | NEW |