forked from deluge-torrent/deluge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
minify_web_js.py
executable file
·41 lines (33 loc) · 1.13 KB
/
minify_web_js.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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()))