From 8c4154bc1a22ca2d461f4e819256cb5acc702798 Mon Sep 17 00:00:00 2001 From: Calum Lind Date: Sun, 9 Aug 2015 18:31:28 +0100 Subject: [PATCH] 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. --- minify_web_js.py | 26 +++++++++++++++++++++++--- 1 file 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'