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 isPrimary(AssetId id) { | 21 isPrimary(AssetId id) { |
21 // nothing is filtered in debug mode | 22 // nothing is filtered in debug mode |
22 return options.releaseMode && | 23 return options.releaseMode && |
23 // TODO(sigmund): remove this exclusion once we have dev_transformers | 24 // TODO(sigmund): remove this exclusion once we have dev_transformers |
24 // (dartbug.com/14187) | 25 // (dartbug.com/14187) |
25 !id.path.startsWith('lib/') && | 26 !id.path.startsWith('lib/') && |
26 // may filter non-entry HTML files and internal artifacts | 27 // may filter non-entry HTML files and internal artifacts |
27 (id.extension == '.html' || id.extension == _DATA_EXTENSION) && | 28 (id.extension == '.html' || id.extension == _DATA_EXTENSION) && |
28 // keep any entry points | 29 // keep any entry points |
29 !options.isHtmlEntryPoint(id); | 30 !options.isHtmlEntryPoint(id); |
30 } | 31 } |
31 | 32 |
32 apply(Transform transform) { | 33 apply(Transform transform) { |
33 transform.consumePrimary(); | 34 transform.consumePrimary(); |
34 if (transform.primaryInput.id.extension == _DATA_EXTENSION) { | 35 if (transform.primaryInput.id.extension == _DATA_EXTENSION) { |
35 return null; | 36 return null; |
36 } | 37 } |
37 return readPrimaryAsHtml(transform).then((document) { | 38 var logger = new BuildLogger(transform, |
| 39 convertErrorsToWarnings: !options.releaseMode); |
| 40 return readPrimaryAsHtml(transform, logger).then((document) { |
38 // 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 |
39 // have non-polymer entrypoints. | 42 // have non-polymer entrypoints. |
40 if (document.querySelectorAll('polymer-element').isEmpty) { | 43 if (document.querySelectorAll('polymer-element').isEmpty) { |
41 transform.addOutput(transform.primaryInput); | 44 transform.addOutput(transform.primaryInput); |
42 } | 45 } |
43 }); | 46 }); |
44 } | 47 } |
45 } | 48 } |
46 | 49 |
47 const String _DATA_EXTENSION = '._data'; | 50 const String _DATA_EXTENSION = '._data'; |
OLD | NEW |