| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 /// Final phase of the polymer transformation: removes any files that are not | |
| 6 /// needed for deployment. | |
| 7 library polymer.src.build.build_filter; | |
| 8 | |
| 9 import 'dart:async'; | |
| 10 | |
| 11 import 'package:barback/barback.dart'; | |
| 12 import 'package:code_transformers/messages/build_logger.dart'; | |
| 13 import 'common.dart'; | |
| 14 | |
| 15 /// Removes any files not needed for deployment, such as internal build | |
| 16 /// artifacts and non-entry HTML files. | |
| 17 class BuildFilter extends Transformer with PolymerTransformer { | |
| 18 final TransformOptions options; | |
| 19 BuildFilter(this.options); | |
| 20 | |
| 21 isPrimary(AssetId id) { | |
| 22 // nothing is filtered in debug mode | |
| 23 return options.releaseMode && | |
| 24 // TODO(sigmund): remove this exclusion once we have dev_transformers | |
| 25 // (dartbug.com/14187) | |
| 26 !id.path.startsWith('lib/') && | |
| 27 // may filter non-entry HTML files and internal artifacts | |
| 28 (id.extension == '.html' || id.extension == _DATA_EXTENSION) && | |
| 29 // keep any entry points | |
| 30 !options.isHtmlEntryPoint(id); | |
| 31 } | |
| 32 | |
| 33 apply(Transform transform) { | |
| 34 transform.consumePrimary(); | |
| 35 if (transform.primaryInput.id.extension == _DATA_EXTENSION) { | |
| 36 return null; | |
| 37 } | |
| 38 var logger = new BuildLogger(transform, | |
| 39 convertErrorsToWarnings: !options.releaseMode, | |
| 40 detailsUri: 'http://goo.gl/5HPeuP'); | |
| 41 return readPrimaryAsHtml(transform, logger).then((document) { | |
| 42 // Keep .html files that don't use polymer, since the app developer might | |
| 43 // have non-polymer entrypoints. | |
| 44 if (document.querySelectorAll('polymer-element').isEmpty) { | |
| 45 transform.addOutput(transform.primaryInput); | |
| 46 } | |
| 47 }); | |
| 48 } | |
| 49 } | |
| 50 | |
| 51 const String _DATA_EXTENSION = '._data'; | |
| OLD | NEW |