Index: tools/grit/grit/format/minifier.py |
diff --git a/tools/grit/grit/format/minifier.py b/tools/grit/grit/format/minifier.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a451b2a9ec4afb646a7f5db88417176ef4da63cf |
--- /dev/null |
+++ b/tools/grit/grit/format/minifier.py |
@@ -0,0 +1,32 @@ |
+# Copyright (c) 2016 The Chromium Authors. All rights reserved. |
Lei Zhang
2016/08/02 16:47:48
no (c)
aberent
2016/08/02 20:27:42
Done.
|
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+'''Framework for stripping whitespace and comments from resource files''' |
+ |
+import re |
Lei Zhang
2016/08/02 16:47:47
Not used
aberent
2016/08/02 20:27:41
Done.
|
+import subprocess |
+ |
+__js_minifier = None |
+ |
+def SetJsMinifier(minifier): |
+ global __js_minifier |
+ __js_minifier = minifier.split() |
+ |
+ |
+def Minify(source, file_type): |
+ if file_type == '.js' and __js_minifier: |
Lei Zhang
2016/08/02 16:47:48
Not that you really need it, but you can negate th
aberent
2016/08/02 20:27:41
Done.
|
+ p = subprocess.Popen(__js_minifier, |
+ stdin=subprocess.PIPE, |
+ stdout=subprocess.PIPE, |
+ stderr=subprocess.PIPE) |
+ (stdout,stderr) = p.communicate(source) |
Lei Zhang
2016/08/02 16:47:47
space after comma
aberent
2016/08/02 20:27:41
Done.
|
+ if stderr: |
+ print stderr |
Lei Zhang
2016/08/02 16:47:48
Is this useful as is? Maybe only do it if the retu
aberent
2016/08/02 20:27:41
Probably useful. It prints warnings from the compi
|
+ if p.returncode != 0: |
+ print "Minification failed, using original source" |
+ return source |
+ return stdout |
+ else: |
+ return source |
+ |