| 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 | 10 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 PolymerTransformerGroup.asPlugin(BarbackSettings settings) | 33 PolymerTransformerGroup.asPlugin(BarbackSettings settings) |
| 34 : this(_parseSettings(settings)); | 34 : this(_parseSettings(settings)); |
| 35 } | 35 } |
| 36 | 36 |
| 37 TransformOptions _parseSettings(BarbackSettings settings) { | 37 TransformOptions _parseSettings(BarbackSettings settings) { |
| 38 var args = settings.configuration; | 38 var args = settings.configuration; |
| 39 bool releaseMode = settings.mode == BarbackMode.RELEASE; | 39 bool releaseMode = settings.mode == BarbackMode.RELEASE; |
| 40 bool jsOption = args['js']; | 40 bool jsOption = args['js']; |
| 41 bool csp = args['csp'] == true; // defaults to false | 41 bool csp = args['csp'] == true; // defaults to false |
| 42 bool lint = args['lint'] != false; // defaults to true |
| 42 return new TransformOptions( | 43 return new TransformOptions( |
| 43 entryPoints: _readEntrypoints(args['entry_points']), | 44 entryPoints: _readEntrypoints(args['entry_points']), |
| 44 directlyIncludeJS: jsOption == null ? releaseMode : jsOption, | 45 directlyIncludeJS: jsOption == null ? releaseMode : jsOption, |
| 45 contentSecurityPolicy: csp, | 46 contentSecurityPolicy: csp, |
| 46 releaseMode: releaseMode); | 47 releaseMode: releaseMode, |
| 48 lint: lint); |
| 47 } | 49 } |
| 48 | 50 |
| 49 _readEntrypoints(value) { | 51 _readEntrypoints(value) { |
| 50 if (value == null) return null; | 52 if (value == null) return null; |
| 51 var entryPoints = []; | 53 var entryPoints = []; |
| 52 bool error; | 54 bool error; |
| 53 if (value is List) { | 55 if (value is List) { |
| 54 entryPoints = value; | 56 entryPoints = value; |
| 55 error = value.any((e) => e is! String); | 57 error = value.any((e) => e is! String); |
| 56 } else if (value is String) { | 58 } else if (value is String) { |
| 57 entryPoints = [value]; | 59 entryPoints = [value]; |
| 58 error = false; | 60 error = false; |
| 59 } else { | 61 } else { |
| 60 error = true; | 62 error = true; |
| 61 } | 63 } |
| 62 if (error) { | 64 if (error) { |
| 63 print('Invalid value for "entry_points" in the polymer transformer.'); | 65 print('Invalid value for "entry_points" in the polymer transformer.'); |
| 64 } | 66 } |
| 65 return entryPoints; | 67 return entryPoints; |
| 66 } | 68 } |
| 67 | 69 |
| 68 /// Create deploy phases for Polymer. Note that inlining HTML Imports | 70 /// Create deploy phases for Polymer. Note that inlining HTML Imports |
| 69 /// comes first (other than linter, if [options.linter] is enabled), which | 71 /// comes first (other than linter, if [options.linter] is enabled), which |
| 70 /// allows the rest of the HTML-processing phases to operate only on HTML that | 72 /// allows the rest of the HTML-processing phases to operate only on HTML that |
| 71 /// is actually imported. | 73 /// is actually imported. |
| 72 List<List<Transformer>> createDeployPhases( | 74 List<List<Transformer>> createDeployPhases( |
| 73 TransformOptions options, {String sdkDir}) { | 75 TransformOptions options, {String sdkDir}) { |
| 76 // TODO(sigmund): this should be done differently. We should lint everything |
| 77 // that is reachable and have the option to lint the rest (similar to how |
| 78 // dart2js can analyze reachable code or entire libraries). |
| 74 var phases = options.lint ? [[new Linter(options)]] : []; | 79 var phases = options.lint ? [[new Linter(options)]] : []; |
| 75 return phases..addAll([ | 80 return phases..addAll([ |
| 76 [new ImportInliner(options)], | 81 [new ImportInliner(options)], |
| 77 [new ObservableTransformer()], | 82 [new ObservableTransformer()], |
| 78 [new ScriptCompactor(options, sdkDir: sdkDir)], | 83 [new ScriptCompactor(options, sdkDir: sdkDir)], |
| 79 [new PolyfillInjector(options)], | 84 [new PolyfillInjector(options)], |
| 80 [new BuildFilter(options)] | 85 [new BuildFilter(options)] |
| 81 ]); | 86 ]); |
| 82 } | 87 } |
| OLD | NEW |