diff options
author | Calum Lind <calumlind+deluge@gmail.com> | 2014-07-10 14:56:38 +0100 |
---|---|---|
committer | Calum Lind <calumlind+deluge@gmail.com> | 2014-07-10 15:05:52 +0100 |
commit | 98b54e6682ca7c7fb2ad6d9944096648b35872b1 (patch) | |
tree | 45b6a6a2cb7af1c52a154bf3c63c80529b915cea /minify_web_js.py | |
parent | 5eba762a20c5ec377b39b73133d695aeef3bc480 (diff) | |
download | deluge-98b54e6682ca7c7fb2ad6d9944096648b35872b1.tar.gz deluge-98b54e6682ca7c7fb2ad6d9944096648b35872b1.tar.bz2 deluge-98b54e6682ca7c7fb2ad6d9944096648b35872b1.zip |
Rewrite the webui minify js script in python
Also replaced minifier 'yui-compressor' with pure-python 'slimit'.
Diffstat (limited to 'minify_web_js.py')
-rwxr-xr-x | minify_web_js.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/minify_web_js.py b/minify_web_js.py new file mode 100755 index 000000000..41d6c26b7 --- /dev/null +++ b/minify_web_js.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python +import os +import sys +import fileinput +import fnmatch +from slimit import minify + +"""Minifies the Webui JS files + +Usage: python minify_web_js.py deluge/ui/web/js/deluge-all +""" + +if len(sys.argv) != 2: + print "Specify a source js directory... e.g. " + sys.exit(1) + +SOURCE_DIR = os.path.abspath(sys.argv[1]) +BUILD_NAME = os.path.basename(SOURCE_DIR) +BUILD_DIR = os.path.dirname(SOURCE_DIR) +SRC_FILE_LIST = [] +for root, dirnames, filenames in os.walk(SOURCE_DIR): + for filename in fnmatch.filter(filenames, '*.js'): + SRC_FILE_LIST.append(os.path.join(root, filename)) + +if not SRC_FILE_LIST: + print 'No js files found' + sys.exit(1) + +print 'Minifying %s' % BUILD_NAME + +# generate the single file, unminified version +file_dbg_js = os.path.join(BUILD_DIR, BUILD_NAME + '-debug.js') +with open(file_dbg_js, 'w') as _file: + input_lines = fileinput.input(SRC_FILE_LIST) + _file.writelines(input_lines) + +# generate the minified version +fileout_js = os.path.join(BUILD_DIR, BUILD_NAME + '.js') +with open(fileout_js, 'w') as out_file: + with open(file_dbg_js, 'r') as in_file: + out_file.write(minify(in_file.read())) |