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 // TODO(nweiz): This should just take an AssetId when barback <0.13.0 support |
| 21 // is dropped. |
| 22 Future<bool> isPrimary(idOrAsset) { |
| 23 var id = idOrAsset is AssetId ? idOrAsset : idOrAsset.id; |
| 24 return new Future.value( |
21 // nothing is filtered in debug mode | 25 // nothing is filtered in debug mode |
22 options.releaseMode && | 26 options.releaseMode && |
23 // TODO(sigmund): remove this exclusion once we have dev_transformers | 27 // TODO(sigmund): remove this exclusion once we have dev_transformers |
24 // (dartbug.com/14187) | 28 // (dartbug.com/14187) |
25 input.id.path.startsWith('web/') && | 29 id.path.startsWith('web/') && |
26 // may filter non-entry HTML files and internal artifacts | 30 // may filter non-entry HTML files and internal artifacts |
27 (input.id.extension == '.html' || input.id.extension == '.scriptUrls') && | 31 (id.extension == '.html' || id.extension == '.scriptUrls') && |
28 // keep any entry points | 32 // keep any entry points |
29 !options.isHtmlEntryPoint(input.id)); | 33 !options.isHtmlEntryPoint(id)); |
| 34 } |
30 | 35 |
31 Future apply(Transform transform) { | 36 Future apply(Transform transform) { |
32 if (transform.primaryInput.id.extension == '.scriptUrls') { | 37 if (transform.primaryInput.id.extension == '.scriptUrls') { |
33 return new Future.value(null); | 38 return new Future.value(null); |
34 } | 39 } |
35 return readPrimaryAsHtml(transform).then((document) { | 40 return readPrimaryAsHtml(transform).then((document) { |
36 // Keep .html files that don't use polymer, since the app developer might | 41 // Keep .html files that don't use polymer, since the app developer might |
37 // have non-polymer entrypoints. | 42 // have non-polymer entrypoints. |
38 if (document.querySelectorAll('polymer-element').isEmpty) { | 43 if (document.querySelectorAll('polymer-element').isEmpty) { |
39 transform.addOutput(transform.primaryInput); | 44 transform.addOutput(transform.primaryInput); |
40 } | 45 } |
41 }); | 46 }); |
42 } | 47 } |
43 } | 48 } |
OLD | NEW |