diff options
author | Calum Lind <calumlind+deluge@gmail.com> | 2015-08-09 19:31:28 +0200 |
---|---|---|
committer | Calum Lind <calumlind+deluge@gmail.com> | 2015-08-14 00:04:01 +0200 |
commit | 8c4154bc1a22ca2d461f4e819256cb5acc702798 (patch) | |
tree | fbb0326ac858c58319831c239ce73819988a8318 /minify_web_js.py | |
parent | Workaround for js files generating warnings with generate_pot script (diff) | |
download | deluge-8c4154bc1a22ca2d461f4e819256cb5acc702798.tar.xz 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.
Diffstat (limited to 'minify_web_js.py')
-rwxr-xr-x | minify_web_js.py | 26 |
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' |