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 /// Transfomer used for pub-serve and pub-deploy. | 5 /// Transfomer used for pub-serve and pub-deploy. |
6 library polymer.transformer; | 6 library polymer.transformer; |
7 | 7 |
8 import 'package:barback/barback.dart'; | 8 import 'package:barback/barback.dart'; |
9 import 'package:observe/transformer.dart'; | 9 import 'package:observe/transformer.dart'; |
10 import 'package:path/path.dart' as path; | 10 import 'package:path/path.dart' as path; |
(...skipping 24 matching lines...) Expand all Loading... |
35 | 35 |
36 PolymerTransformerGroup.asPlugin(BarbackSettings settings) | 36 PolymerTransformerGroup.asPlugin(BarbackSettings settings) |
37 : this(_parseSettings(settings)); | 37 : this(_parseSettings(settings)); |
38 } | 38 } |
39 | 39 |
40 TransformOptions _parseSettings(BarbackSettings settings) { | 40 TransformOptions _parseSettings(BarbackSettings settings) { |
41 var args = settings.configuration; | 41 var args = settings.configuration; |
42 bool releaseMode = settings.mode == BarbackMode.RELEASE; | 42 bool releaseMode = settings.mode == BarbackMode.RELEASE; |
43 bool jsOption = args['js']; | 43 bool jsOption = args['js']; |
44 bool csp = args['csp'] == true; // defaults to false | 44 bool csp = args['csp'] == true; // defaults to false |
45 bool lint = args['lint'] != false; // defaults to true | |
46 bool injectBuildLogs = | 45 bool injectBuildLogs = |
47 !releaseMode && args['inject_build_logs_in_output'] != false; | 46 !releaseMode && args['inject_build_logs_in_output'] != false; |
48 bool injectPlatformJs = args['inject_platform_js'] != false; | 47 bool injectPlatformJs = args['inject_platform_js'] != false; |
49 return new TransformOptions( | 48 return new TransformOptions( |
50 entryPoints: readEntrypoints(args['entry_points']), | 49 entryPoints: readFileList(args['entry_points']), |
51 inlineStylesheets: _readInlineStylesheets(args['inline_stylesheets']), | 50 inlineStylesheets: _readInlineStylesheets(args['inline_stylesheets']), |
52 directlyIncludeJS: jsOption == null ? releaseMode : jsOption, | 51 directlyIncludeJS: jsOption == null ? releaseMode : jsOption, |
53 contentSecurityPolicy: csp, | 52 contentSecurityPolicy: csp, |
54 releaseMode: releaseMode, | 53 releaseMode: releaseMode, |
55 lint: lint, | 54 lint: _parseLintOption(args['lint']), |
56 injectBuildLogsInOutput: injectBuildLogs, | 55 injectBuildLogsInOutput: injectBuildLogs, |
57 injectPlatformJs: injectPlatformJs); | 56 injectPlatformJs: injectPlatformJs); |
58 } | 57 } |
59 | 58 |
60 readEntrypoints(value) { | 59 // Lint option can be empty (all files), false, true, or a map indicating |
| 60 // include/exclude files. |
| 61 _parseLintOption(value) { |
| 62 var lint = null; |
| 63 if (value == null || value == true) return new LintOptions(); |
| 64 if (value == false) return new LintOptions.disabled(); |
| 65 if (value is Map && value.length == 1) { |
| 66 var key = value.keys.single; |
| 67 var files = readFileList(value[key]); |
| 68 if (key == 'include') { |
| 69 return new LintOptions.include(files); |
| 70 } else if (key == 'exclude') { |
| 71 return new LintOptions.exclude(files); |
| 72 } |
| 73 } |
| 74 |
| 75 // Any other case it is an error: |
| 76 print('Invalid value for "lint" in the polymer transformer. ' |
| 77 'Expected one of the following: \n' |
| 78 ' lint: true # or\n' |
| 79 ' lint: false # or\n' |
| 80 ' lint: \n' |
| 81 ' include: \n' |
| 82 ' - file1 \n' |
| 83 ' - file2 # or \n' |
| 84 ' lint: \n' |
| 85 ' exclude: \n' |
| 86 ' - file1 \n' |
| 87 ' - file2 \n'); |
| 88 return new LintOptions(); |
| 89 } |
| 90 |
| 91 readFileList(value) { |
61 if (value == null) return null; | 92 if (value == null) return null; |
62 var entryPoints = []; | 93 var files = []; |
63 bool error; | 94 bool error; |
64 if (value is List) { | 95 if (value is List) { |
65 entryPoints = value; | 96 files = value; |
66 error = value.any((e) => e is! String); | 97 error = value.any((e) => e is! String); |
67 } else if (value is String) { | 98 } else if (value is String) { |
68 entryPoints = [value]; | 99 files = [value]; |
69 error = false; | 100 error = false; |
70 } else { | 101 } else { |
71 error = true; | 102 error = true; |
72 } | 103 } |
73 if (error) { | 104 if (error) { |
74 print('Invalid value for "entry_points" in the polymer transformer.'); | 105 print('Invalid value for "entry_points" in the polymer transformer.'); |
75 } | 106 } |
76 return entryPoints; | 107 return files; |
77 } | 108 } |
78 | 109 |
79 Map<String, bool> _readInlineStylesheets(settingValue) { | 110 Map<String, bool> _readInlineStylesheets(settingValue) { |
80 if (settingValue == null) return null; | 111 if (settingValue == null) return null; |
81 var inlineStylesheets = {}; | 112 var inlineStylesheets = {}; |
82 bool error = false; | 113 bool error = false; |
83 if (settingValue is Map) { | 114 if (settingValue is Map) { |
84 settingValue.forEach((key, value) { | 115 settingValue.forEach((key, value) { |
85 if (value is! bool || key is! String) { | 116 if (value is! bool || key is! String) { |
86 error = true; | 117 error = true; |
(...skipping 26 matching lines...) Expand all Loading... |
113 | 144 |
114 /// Create deploy phases for Polymer. Note that inlining HTML Imports | 145 /// Create deploy phases for Polymer. Note that inlining HTML Imports |
115 /// comes first (other than linter, if [options.linter] is enabled), which | 146 /// comes first (other than linter, if [options.linter] is enabled), which |
116 /// allows the rest of the HTML-processing phases to operate only on HTML that | 147 /// allows the rest of the HTML-processing phases to operate only on HTML that |
117 /// is actually imported. | 148 /// is actually imported. |
118 List<List<Transformer>> createDeployPhases( | 149 List<List<Transformer>> createDeployPhases( |
119 TransformOptions options, {String sdkDir}) { | 150 TransformOptions options, {String sdkDir}) { |
120 // TODO(sigmund): this should be done differently. We should lint everything | 151 // TODO(sigmund): this should be done differently. We should lint everything |
121 // that is reachable and have the option to lint the rest (similar to how | 152 // that is reachable and have the option to lint the rest (similar to how |
122 // dart2js can analyze reachable code or entire libraries). | 153 // dart2js can analyze reachable code or entire libraries). |
123 var phases = options.lint ? [[new Linter(options)]] : []; | 154 var phases = options.lint.enabled ? [[new Linter(options)]] : []; |
124 phases.addAll([ | 155 phases.addAll([ |
125 [new ImportInliner(options)], | 156 [new ImportInliner(options)], |
126 [new ObservableTransformer()], | 157 [new ObservableTransformer()], |
127 [new ScriptCompactor(options, sdkDir: sdkDir)], | 158 [new ScriptCompactor(options, sdkDir: sdkDir)], |
128 [new PolyfillInjector(options)], | 159 [new PolyfillInjector(options)], |
129 [new BuildFilter(options)], | 160 [new BuildFilter(options)], |
130 [new BuildLogCombiner(options)], | 161 [new BuildLogCombiner(options)], |
131 ]); | 162 ]); |
132 if (!options.releaseMode) { | 163 if (!options.releaseMode) { |
133 phases.add([new IndexPageBuilder(options)]); | 164 phases.add([new IndexPageBuilder(options)]); |
134 } | 165 } |
135 return phases; | 166 return phases; |
136 } | 167 } |
137 | 168 |
138 final RegExp _PACKAGE_PATH_REGEX = new RegExp(r'packages\/([^\/]+)\/(.*)'); | 169 final RegExp _PACKAGE_PATH_REGEX = new RegExp(r'packages\/([^\/]+)\/(.*)'); |
OLD | NEW |