OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 /// Transformer used for pub serve and pub build | 5 /// Transformer used for pub serve and pub build |
6 library web_components.build.web_components; | 6 library web_components.build.web_components; |
7 | 7 |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 import 'package:barback/barback.dart'; | 9 import 'package:barback/barback.dart'; |
10 import 'package:code_transformers/assets.dart'; | 10 import 'package:code_transformers/assets.dart'; |
11 import 'package:code_transformers/messages/build_logger.dart'; | 11 import 'package:code_transformers/messages/build_logger.dart'; |
12 import 'package:code_transformers/resolver.dart'; | 12 import 'package:code_transformers/resolver.dart'; |
| 13 import 'package:code_transformers/src/dart_sdk.dart' as dart_sdk; |
13 import 'package:html5lib/dom.dart' as dom; | 14 import 'package:html5lib/dom.dart' as dom; |
14 import 'package:initialize/transformer.dart' show generateBootstrapFile; | 15 import 'package:initialize/transformer.dart' show generateBootstrapFile; |
15 import 'package:initialize/build/initializer_plugin.dart'; | 16 import 'package:initialize/build/initializer_plugin.dart'; |
16 import 'package:path/path.dart' as path; | 17 import 'package:path/path.dart' as path; |
17 import 'package:web_components/transformer.dart'; | 18 import 'package:web_components/transformer.dart'; |
18 import 'common.dart'; | 19 import 'common.dart'; |
19 | 20 |
20 /// Public method that can be used inside any [Transformer] which already has a | 21 /// Public method that can be used inside any [Transformer] which already has a |
21 /// [Resolver] and [Transform] to generate a bootstrap file for the | 22 /// [Resolver] and [Transform] to generate a bootstrap file for the |
22 /// web_components package. | 23 /// web_components package. |
(...skipping 21 matching lines...) Expand all Loading... |
44 | 45 |
45 return initializeBootstrap; | 46 return initializeBootstrap; |
46 } | 47 } |
47 | 48 |
48 /// A [Transformer] which runs the `initialize` transformer with | 49 /// A [Transformer] which runs the `initialize` transformer with |
49 /// some special plugins and also inlines the html imports. | 50 /// some special plugins and also inlines the html imports. |
50 class WebComponentsTransformer extends Transformer { | 51 class WebComponentsTransformer extends Transformer { |
51 final Resolvers _resolvers; | 52 final Resolvers _resolvers; |
52 TransformOptions options; | 53 TransformOptions options; |
53 | 54 |
54 WebComponentsTransformer(this.options) : _resolvers = new Resolvers.fromMock({ | 55 WebComponentsTransformer(this.options) |
55 // The list of types below is derived from: | 56 : _resolvers = new Resolvers.fromMock(dart_sdk.mockSdkSources); |
56 // * types that are used internally by the resolver (see | |
57 // _initializeFrom in resolver.dart). | |
58 // TODO(jakemac): Move this into code_transformers so it can be shared. | |
59 'dart:core': ''' | |
60 library dart.core; | |
61 class Object {} | |
62 class Function {} | |
63 class StackTrace {} | |
64 class Symbol {} | |
65 class Type {} | |
66 | |
67 class String extends Object {} | |
68 class bool extends Object {} | |
69 class num extends Object {} | |
70 class int extends num {} | |
71 class double extends num {} | |
72 class DateTime extends Object {} | |
73 class Null extends Object {} | |
74 | |
75 class Deprecated extends Object { | |
76 final String expires; | |
77 const Deprecated(this.expires); | |
78 } | |
79 const Object deprecated = const Deprecated("next release"); | |
80 class _Override { const _Override(); } | |
81 const Object override = const _Override(); | |
82 class _Proxy { const _Proxy(); } | |
83 const Object proxy = const _Proxy(); | |
84 | |
85 class List<V> extends Object {} | |
86 class Map<K, V> extends Object {} | |
87 ''', | |
88 'dart:html': ''' | |
89 library dart.html; | |
90 class HtmlElement {} | |
91 ''', | |
92 'dart:async': ''' | |
93 library dart.async; | |
94 class Future<T> {} | |
95 ''', | |
96 }); | |
97 | 57 |
98 bool isPrimary(AssetId id) { | 58 bool isPrimary(AssetId id) { |
99 if (options.entryPoints != null) { | 59 if (options.entryPoints != null) { |
100 return options.entryPoints.contains(id.path); | 60 return options.entryPoints.contains(id.path); |
101 } | 61 } |
102 if (id.path == 'web/index.bootstrap.dart') return true; | 62 if (id.path == 'web/index.bootstrap.dart') return true; |
103 // If no entry point is supplied, then any html file under web/ or test/ is | 63 // If no entry point is supplied, then any html file under web/ or test/ is |
104 // an entry point. | 64 // an entry point. |
105 return (id.path.startsWith('web/') || id.path.startsWith('test/')) && | 65 return (id.path.startsWith('web/') || id.path.startsWith('test/')) && |
106 id.path.endsWith('.html'); | 66 id.path.endsWith('.html'); |
(...skipping 21 matching lines...) Expand all Loading... |
128 from: path.url.dirname(primaryInput.id.path)); | 88 from: path.url.dirname(primaryInput.id.path)); |
129 | 89 |
130 // Output the new document and bootstrap file. | 90 // Output the new document and bootstrap file. |
131 transform | 91 transform |
132 .addOutput(new Asset.fromString(primaryInput.id, doc.outerHtml)); | 92 .addOutput(new Asset.fromString(primaryInput.id, doc.outerHtml)); |
133 transform.addOutput(bootstrap); | 93 transform.addOutput(bootstrap); |
134 }); | 94 }); |
135 }); | 95 }); |
136 } | 96 } |
137 } | 97 } |
OLD | NEW |