summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCalum Lind <calumlind+deluge@gmail.com>2015-08-09 18:31:28 +0100
committerCalum Lind <calumlind+deluge@gmail.com>2015-08-13 23:04:01 +0100
commit8c4154bc1a22ca2d461f4e819256cb5acc702798 (patch)
treefbb0326ac858c58319831c239ce73819988a8318
parenta391bbd67bcfb2f8be9b726753f047009b52d244 (diff)
downloaddeluge-8c4154bc1a22ca2d461f4e819256cb5acc702798.tar.gz
deluge-8c4154bc1a22ca2d461f4e819256cb5acc702798.tar.bz2
deluge-8c4154bc1a22ca2d461f4e819256cb5acc702798.zip
Fix the output of minify js script
The order of the js files matters when minifying. * Use the '.order' files to put specified files top of the file list. * Sub-directory files inserted in list before root directory files. * Sort everything else alphabetically for consistant ordering.
-rwxr-xr-xminify_web_js.py26
1 files changed, 23 insertions, 3 deletions
diff --git a/minify_web_js.py b/minify_web_js.py
index 9388b52e1..c234d495a 100755
--- a/minify_web_js.py
+++ b/minify_web_js.py
@@ -22,7 +22,7 @@ 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. "
+ print 'Specify a source js directory... e.g. deluge/ui/web/js/deluge-all'
sys.exit(1)
SOURCE_DIR = os.path.abspath(sys.argv[1])
@@ -30,8 +30,28 @@ 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))
+ dirnames.sort(reverse=True)
+ files = fnmatch.filter(filenames, "*.js")
+ files.sort()
+
+ order_file = os.path.join(root, '.order')
+ if os.path.isfile(order_file):
+ with open(order_file, 'r') as f:
+ for line in f:
+ line = line.strip()
+ if not line or line[0] == '#':
+ continue
+ pos, filename = line.split()
+ files.pop(files.index(filename))
+ if pos == '+':
+ files.insert(0, filename)
+
+ if not dirnames:
+ for fnames_ordered in reversed(files):
+ SRC_FILE_LIST.insert(0, os.path.join(root, fnames_ordered))
+ else:
+ for fnames_ordered in files:
+ SRC_FILE_LIST.append(os.path.join(root, fnames_ordered))
if not SRC_FILE_LIST:
print 'No js files found'