Chromium Code Reviews| Index: chrome/browser/resources/vulcanize_gn.py |
| diff --git a/chrome/browser/resources/vulcanize_gn.py b/chrome/browser/resources/vulcanize_gn.py |
| index 309ab32be4bb53533003a2116b68bdb96f1cee12..7db93bc9974744c4425001d8355b0a5d113d9ce0 100755 |
| --- a/chrome/browser/resources/vulcanize_gn.py |
| +++ b/chrome/browser/resources/vulcanize_gn.py |
| @@ -158,25 +158,44 @@ def _vulcanize(in_folder, args): |
| # that by adding a <base> tag to the (post-processed) generated output. |
| output = output.replace('<head>', '<head>' + args.insert_in_head) |
| - with tempfile.NamedTemporaryFile(mode='wt+', delete=False) as tmp: |
| - tmp.write(output) |
| + crisper_input = tempfile.NamedTemporaryFile(mode='wt+', delete=False) |
| + crisper_input.write(output) |
| + crisper_input.close() |
| + |
| + crisper_output = tempfile.NamedTemporaryFile(mode='wt+', delete=False) |
| + crisper_output.close() |
| try: |
| node.RunNode([node_modules.PathToCrisper(), |
| - '--source', tmp.name, |
| + '--source', crisper_input.name, |
| '--script-in-head', 'false', |
| + '--only-split', |
| '--html', html_out_path, |
| - '--js', js_out_path]) |
| - |
| - # Create an empty JS file if crisper did not create one. |
| - if not os.path.isfile(js_out_path): |
| - open(js_out_path, 'w').close() |
| - |
| - node.RunNode([node_modules.PathToUglifyJs(), js_out_path, |
| + '--js', crisper_output.name]) |
| + |
| + # Crisper by default inserts a <script> tag with the name of the --js file, |
| + # but since we are using a temporary file, need to manually insert a |
| + # <script> tag with the correct final filename (in combination with |
| + # --only-split flag). There is no way currently to manually specify the |
| + # <script> tag's path, see https://github.com/PolymerLabs/crisper/issues/46. |
| + with open(html_out_path, "r+") as f: |
|
Dan Beam
2017/06/06 19:09:27
nit: rest of this file uses ' instead of "
dpapad
2017/06/06 19:30:46
Done.
|
| + data = f.read() |
| + newData = data.replace( |
|
Dan Beam
2017/06/06 19:09:27
python_vars_like_this
dpapad
2017/06/06 19:30:46
Done.
|
| + '</body></html>', |
| + '<script src="' + args.js_out_file + '"></script></body></html>') |
| + assert newData != data, 'Expected to find </body></html> token.' |
| + f.seek(0) |
| + f.write(newData) |
| + f.truncate() |
| + |
| + node.RunNode([node_modules.PathToUglifyJs(), crisper_output.name, |
| '--comments', '"/Copyright|license|LICENSE|\<\/?if/"', |
| '--output', js_out_path]) |
| finally: |
| - os.remove(tmp.name) |
| + if os.path.exists(crisper_input.name): |
| + os.remove(crisper_input.name) |
| + if os.path.exists(crisper_output.name): |
| + os.remove(crisper_output.name) |
| def main(argv): |