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 'package:code_transformers/messages/build_logger.dart'; |
12 import 'common.dart'; | 13 import 'common.dart'; |
13 | 14 |
14 /// Removes any files not needed for deployment, such as internal build | 15 /// Removes any files not needed for deployment, such as internal build |
15 /// artifacts and non-entry HTML files. | 16 /// artifacts and non-entry HTML files. |
16 class BuildFilter extends Transformer with PolymerTransformer { | 17 class BuildFilter extends Transformer with PolymerTransformer { |
17 final TransformOptions options; | 18 final TransformOptions options; |
18 BuildFilter(this.options); | 19 BuildFilter(this.options); |
19 | 20 |
20 // TODO(nweiz): This should just take an AssetId when barback <0.13.0 support | 21 // TODO(nweiz): This should just take an AssetId when barback <0.13.0 support |
21 // is dropped. | 22 // is dropped. |
22 Future<bool> isPrimary(idOrAsset) { | 23 Future<bool> isPrimary(idOrAsset) { |
23 var id = idOrAsset is AssetId ? idOrAsset : idOrAsset.id; | 24 var id = idOrAsset is AssetId ? idOrAsset : idOrAsset.id; |
24 return new Future.value( | 25 return new Future.value( |
25 // nothing is filtered in debug mode | 26 // nothing is filtered in debug mode |
26 options.releaseMode && | 27 options.releaseMode && |
27 // TODO(sigmund): remove this exclusion once we have dev_transformers | 28 // TODO(sigmund): remove this exclusion once we have dev_transformers |
28 // (dartbug.com/14187) | 29 // (dartbug.com/14187) |
29 id.path.startsWith('web/') && | 30 id.path.startsWith('web/') && |
30 // may filter non-entry HTML files and internal artifacts | 31 // may filter non-entry HTML files and internal artifacts |
31 (id.extension == '.html' || id.extension == '.scriptUrls') && | 32 (id.extension == '.html' || id.extension == '.scriptUrls') && |
32 // keep any entry points | 33 // keep any entry points |
33 !options.isHtmlEntryPoint(id)); | 34 !options.isHtmlEntryPoint(id)); |
34 } | 35 } |
35 | 36 |
36 Future apply(Transform transform) { | 37 Future apply(Transform transform) { |
37 if (transform.primaryInput.id.extension == '.scriptUrls') { | 38 if (transform.primaryInput.id.extension == '.scriptUrls') { |
38 return new Future.value(null); | 39 return new Future.value(null); |
39 } | 40 } |
40 return readPrimaryAsHtml(transform).then((document) { | 41 var logger = new BuildLogger(transform, |
| 42 convertErrorsToWarnings: !options.releaseMode); |
| 43 return readPrimaryAsHtml(transform, logger).then((document) { |
41 // Keep .html files that don't use polymer, since the app developer might | 44 // Keep .html files that don't use polymer, since the app developer might |
42 // have non-polymer entrypoints. | 45 // have non-polymer entrypoints. |
43 if (document.querySelectorAll('polymer-element').isEmpty) { | 46 if (document.querySelectorAll('polymer-element').isEmpty) { |
44 transform.addOutput(transform.primaryInput); | 47 transform.addOutput(transform.primaryInput); |
45 } | 48 } |
46 }); | 49 }); |
47 } | 50 } |
48 } | 51 } |
OLD | NEW |