| 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 that combines multiple dart script tags into a single one. */ | 5 /** Transfomer that combines multiple dart script tags into a single one. */ |
| 6 library polymer.src.build.script_compactor; | 6 library polymer.src.build.script_compactor; |
| 7 | 7 |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 import 'dart:convert'; | 9 import 'dart:convert'; |
| 10 | 10 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 if (mainScriptTag == null) { | 74 if (mainScriptTag == null) { |
| 75 // We didn't find any main library, nothing to do. | 75 // We didn't find any main library, nothing to do. |
| 76 transform.addOutput(transform.primaryInput); | 76 transform.addOutput(transform.primaryInput); |
| 77 return null; | 77 return null; |
| 78 } | 78 } |
| 79 | 79 |
| 80 var bootstrapId = id.addExtension('_bootstrap.dart'); | 80 var bootstrapId = id.addExtension('_bootstrap.dart'); |
| 81 mainScriptTag.attributes['src'] = | 81 mainScriptTag.attributes['src'] = |
| 82 path.url.basename(bootstrapId.path); | 82 path.url.basename(bootstrapId.path); |
| 83 | 83 |
| 84 // TODO(sigmund): stop renaming the file (see dartbug.com/14554) | 84 libraries.add(mainLibraryId); |
| 85 var modifiedMainId = mainLibraryId.addExtension('_modified.dart'); | |
| 86 | |
| 87 libraries.add(modifiedMainId); | |
| 88 var urls = libraries.map((id) => assetUrlFor(id, bootstrapId, logger)) | 85 var urls = libraries.map((id) => assetUrlFor(id, bootstrapId, logger)) |
| 89 .where((url) => url != null).toList(); | 86 .where((url) => url != null).toList(); |
| 90 var buffer = new StringBuffer()..writeln(MAIN_HEADER); | 87 var buffer = new StringBuffer()..writeln(MAIN_HEADER); |
| 91 int i = 0; | 88 int i = 0; |
| 92 for (; i < urls.length; i++) { | 89 for (; i < urls.length; i++) { |
| 93 buffer.writeln("import '${urls[i]}' as i$i;"); | 90 buffer.writeln("import '${urls[i]}' as i$i;"); |
| 94 } | 91 } |
| 95 | 92 |
| 96 buffer..write('\n') | 93 buffer..write('\n') |
| 97 ..writeln('void main() {') | 94 ..writeln('void main() {') |
| 98 ..writeln(' configureForDeployment([') | 95 ..writeln(' configureForDeployment([') |
| 99 ..writeAll(urls.map((url) => " '$url',\n")) | 96 ..writeAll(urls.map((url) => " '$url',\n")) |
| 100 ..writeln(' ]);') | 97 ..writeln(' ]);') |
| 101 ..writeln(' i${i - 1}.polymerMainWrapper();') | 98 ..writeln(' i${i - 1}.main();') |
| 102 ..writeln('}'); | 99 ..writeln('}'); |
| 103 | 100 |
| 104 transform.addOutput(new Asset.fromString( | 101 transform.addOutput(new Asset.fromString( |
| 105 bootstrapId, buffer.toString())); | 102 bootstrapId, buffer.toString())); |
| 106 transform.addOutput(new Asset.fromString(id, document.outerHtml)); | 103 transform.addOutput(new Asset.fromString(id, document.outerHtml)); |
| 107 | |
| 108 return transform.readInputAsString(mainLibraryId).then((contents) { | |
| 109 transform.addOutput(new Asset.fromString(modifiedMainId, | |
| 110 '$contents\n\npolymerMainWrapper() => main();\n')); | |
| 111 }); | |
| 112 }); | 104 }); |
| 113 }); | 105 }); |
| 114 } | 106 } |
| 115 } | 107 } |
| 116 | 108 |
| 117 const MAIN_HEADER = """ | 109 const MAIN_HEADER = """ |
| 118 library app_bootstrap; | 110 library app_bootstrap; |
| 119 | 111 |
| 120 import 'package:polymer/polymer.dart'; | 112 import 'package:polymer/polymer.dart'; |
| 121 """; | 113 """; |
| OLD | NEW |