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.
This commit is contained in:
Calum Lind 2015-08-09 18:31:28 +01:00
parent a391bbd67b
commit 8c4154bc1a
1 changed files with 23 additions and 3 deletions

View File

@ -22,7 +22,7 @@ Usage: python minify_web_js.py deluge/ui/web/js/deluge-all
""" """
if len(sys.argv) != 2: 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) sys.exit(1)
SOURCE_DIR = os.path.abspath(sys.argv[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) BUILD_DIR = os.path.dirname(SOURCE_DIR)
SRC_FILE_LIST = [] SRC_FILE_LIST = []
for root, dirnames, filenames in os.walk(SOURCE_DIR): for root, dirnames, filenames in os.walk(SOURCE_DIR):
for filename in fnmatch.filter(filenames, '*.js'): dirnames.sort(reverse=True)
SRC_FILE_LIST.append(os.path.join(root, filename)) 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: if not SRC_FILE_LIST:
print 'No js files found' print 'No js files found'