| 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 library polymer.src.build.polymer_bootstrap; | |
| 5 | |
| 6 import 'dart:async'; | |
| 7 | |
| 8 import 'package:barback/barback.dart'; | |
| 9 import 'package:code_transformers/messages/build_logger.dart'; | |
| 10 import 'package:code_transformers/assets.dart'; | |
| 11 import 'package:code_transformers/resolver.dart'; | |
| 12 import 'package:code_transformers/src/dart_sdk.dart' as dart_sdk; | |
| 13 import 'package:path/path.dart' as path; | |
| 14 import 'package:web_components/build/web_components.dart'; | |
| 15 | |
| 16 import 'common.dart'; | |
| 17 import 'messages.dart'; | |
| 18 import 'polymer_smoke_generator.dart'; | |
| 19 | |
| 20 /// The primary polymer transformer that handles everything which requires a | |
| 21 /// [Resolver] so they can share it. | |
| 22 // Note: This is effectively tested in `all_phases_test.dart` as it doesn't | |
| 23 // really deserve its own unit test. | |
| 24 class PolymerBootstrapTransformer extends Transformer with PolymerTransformer { | |
| 25 final Resolvers resolvers; | |
| 26 final TransformOptions options; | |
| 27 | |
| 28 PolymerBootstrapTransformer(this.options, {String sdkDir}) | |
| 29 // TODO(sigmund): consider restoring here a resolver that uses the real | |
| 30 // SDK once the analyzer is lazy and only an resolves what it needs: | |
| 31 //: resolvers = new Resolvers(sdkDir != null ? sdkDir : dartSdkDirectory); | |
| 32 : resolvers = new Resolvers.fromMock(dart_sdk.mockSdkSources); | |
| 33 | |
| 34 /// Only run on entry point .html files. | |
| 35 bool isPrimary(AssetId id) => options.isHtmlEntryPoint(id); | |
| 36 | |
| 37 Future apply(Transform transform) { | |
| 38 var logger = new BuildLogger(transform, | |
| 39 convertErrorsToWarnings: !options.releaseMode, | |
| 40 detailsUri: 'http://goo.gl/5HPeuP'); | |
| 41 var primaryId = transform.primaryInput.id; | |
| 42 return readPrimaryAsHtml(transform, logger).then((document) { | |
| 43 var script = document.querySelector('script[type="application/dart"]'); | |
| 44 if (script == null) { | |
| 45 logger.warning(NO_DART_SCRIPT.create({'url': primaryId.path})); | |
| 46 return null; | |
| 47 } | |
| 48 | |
| 49 var entryScriptId = uriToAssetId( | |
| 50 primaryId, script.attributes['src'], logger, script.sourceSpan); | |
| 51 | |
| 52 return resolvers.get(transform, [entryScriptId]).then((resolver) { | |
| 53 var webComponentsBootstrapId = | |
| 54 primaryId.changeExtension('.web_components.bootstrap.dart'); | |
| 55 var webComponentsBootstrap = generateWebComponentsBootstrap(resolver, | |
| 56 transform, document, entryScriptId, webComponentsBootstrapId); | |
| 57 transform.addOutput(webComponentsBootstrap); | |
| 58 | |
| 59 var polymerBootstrapId = | |
| 60 primaryId.addExtension('.polymer.bootstrap.dart'); | |
| 61 script.attributes['src'] = path.basename(polymerBootstrapId.path); | |
| 62 | |
| 63 return generatePolymerBootstrap(transform, resolver, | |
| 64 webComponentsBootstrapId, polymerBootstrapId, document, options, | |
| 65 resolveFromId: entryScriptId).then((polymerBootstrap) { | |
| 66 transform.addOutput(polymerBootstrap); | |
| 67 transform | |
| 68 .addOutput(new Asset.fromString(primaryId, document.outerHtml)); | |
| 69 resolver.release(); | |
| 70 }); | |
| 71 }); | |
| 72 }); | |
| 73 } | |
| 74 } | |
| OLD | NEW |