Chromium Code Reviews| Index: third_party/closure_compiler/js_minify.py |
| diff --git a/third_party/closure_compiler/js_minify.py b/third_party/closure_compiler/js_minify.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..d0f1f8854c47f1de39a5c749328d4e95632a7024 |
| --- /dev/null |
| +++ b/third_party/closure_compiler/js_minify.py |
| @@ -0,0 +1,47 @@ |
| +#!/usr/bin/python |
| +# Copyright 2016 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +import sys |
| +import tempfile |
| +from compile2 import Checker |
| + |
| + |
| +closure_args = [ |
|
Dan Beam
2016/07/25 17:29:16
can we just compose these rather than duplicate th
aberent
2016/07/27 09:46:35
Now using closure_args.gni.
|
| + "compilation_level=WHITESPACE_ONLY", |
| + |
| + "extra_annotation_name=attribute", |
| + "extra_annotation_name=demo", |
| + "extra_annotation_name=element", |
| + "extra_annotation_name=group", |
| + "extra_annotation_name=hero", |
| + "extra_annotation_name=homepage", |
| + "extra_annotation_name=status", |
| + "extra_annotation_name=submodule", |
| + "language_in=ECMASCRIPT6_STRICT", |
| + "language_out=ECMASCRIPT5_STRICT", |
| + |
| + "polymer_pass", |
| + |
| + "source_map_format=V3", |
| +] |
| + |
| + |
| +def Minify(source): |
| + with tempfile.NamedTemporaryFile(suffix='.js') as t1, tempfile.NamedTemporaryFile(suffix='.js', delete=False) as t2: |
|
Dan Beam
2016/07/25 17:29:16
80 col wrap
Dan Beam
2016/07/25 17:29:16
nit: use double quotes (") instead of single quote
Dirk Pranke
2016/07/25 21:12:36
I would actually change everything else to be sing
aberent
2016/07/27 09:46:35
Done. All single quotes.
aberent
2016/07/27 09:46:36
Done.
|
| + t1.write(source) |
| + t1.seek(0) |
| + checker = Checker() |
| + checker.check([t1.name], out_file=t2.name, closure_args=closure_args) |
| + t2.seek(0) |
| + result = t2.read() |
| + return result |
| + |
|
Dan Beam
2016/07/25 17:29:16
this should be 2 blank lines between top-level glo
aberent
2016/07/27 09:46:36
Done.
|
| +if __name__ == "__main__": |
| + orig_stdout = sys.stdout |
|
Dan Beam
2016/07/25 17:29:16
you probably want to wrap this in a try/finally, i
aberent
2016/07/27 09:46:35
Done.
|
| + sys.stdout = sys.stderr |
|
Dan Beam
2016/07/25 17:29:16
why is this stderr/stdout redirection required?
aberent
2016/07/27 09:46:35
In traditional Unix pipeline style (and as I defin
|
| + result = Minify(sys.stdin.read()) |
| + sys.stdout = orig_stdout |
| + print result |
| + |