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 /** | 5 /// Final phase of the polymer transformation: removes any files that are not |
6 * Final phase of the polymer transformation: removes any files that are not | 6 /// needed for deployment. |
7 * needed for deployment. | |
8 */ | |
9 library polymer.src.build.build_filter; | 7 library polymer.src.build.build_filter; |
10 | 8 |
11 import 'dart:async'; | 9 import 'dart:async'; |
12 | 10 |
13 import 'package:barback/barback.dart'; | 11 import 'package:barback/barback.dart'; |
14 import 'common.dart'; | 12 import 'common.dart'; |
15 | 13 |
16 /** | 14 /// Removes any files not needed for deployment, such as internal build |
17 * Removes any files not needed for deployment, such as internal build artifacts | 15 /// artifacts and non-entry HTML files. |
18 * and non-entry HTML files. | |
19 */ | |
20 class BuildFilter extends Transformer with PolymerTransformer { | 16 class BuildFilter extends Transformer with PolymerTransformer { |
21 final TransformOptions options; | 17 final TransformOptions options; |
22 BuildFilter(this.options); | 18 BuildFilter(this.options); |
23 | 19 |
24 Future<bool> isPrimary(Asset input) => new Future.value( | 20 Future<bool> isPrimary(Asset input) => new Future.value( |
25 // nothing is filtered in debug mode | 21 // nothing is filtered in debug mode |
26 options.releaseMode && | 22 options.releaseMode && |
27 // TODO(sigmund): remove this exclusion once we have dev_transformers | 23 // TODO(sigmund): remove this exclusion once we have dev_transformers |
28 // (dartbug.com/14187) | 24 // (dartbug.com/14187) |
29 input.id.path.startsWith('web/') && | 25 input.id.path.startsWith('web/') && |
30 // may filter non-entry HTML files and internal artifacts | 26 // may filter non-entry HTML files and internal artifacts |
31 (input.id.extension == '.html' || input.id.extension == '.scriptUrls') && | 27 (input.id.extension == '.html' || input.id.extension == '.scriptUrls') && |
32 // keep any entry points | 28 // keep any entry points |
33 !options.isHtmlEntryPoint(input.id)); | 29 !options.isHtmlEntryPoint(input.id)); |
34 | 30 |
35 Future apply(Transform transform) { | 31 Future apply(Transform transform) { |
36 if (transform.primaryInput.id.extension == '.scriptUrls') { | 32 if (transform.primaryInput.id.extension == '.scriptUrls') { |
37 return new Future.value(null); | 33 return new Future.value(null); |
38 } | 34 } |
39 return readPrimaryAsHtml(transform).then((document) { | 35 return readPrimaryAsHtml(transform).then((document) { |
40 // Keep .html files that don't use polymer, since the app developer might | 36 // Keep .html files that don't use polymer, since the app developer might |
41 // have non-polymer entrypoints. | 37 // have non-polymer entrypoints. |
42 if (document.querySelectorAll('polymer-element').isEmpty) { | 38 if (document.querySelectorAll('polymer-element').isEmpty) { |
43 transform.addOutput(transform.primaryInput); | 39 transform.addOutput(transform.primaryInput); |
44 } | 40 } |
45 }); | 41 }); |
46 } | 42 } |
47 } | 43 } |
OLD | NEW |