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