Skip to content

Commit

Permalink
Fix the output of minify js script
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cas-- committed Aug 13, 2015
1 parent a391bbd commit 8c4154b
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions minify_web_js.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,36 @@
"""

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])
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'
Expand Down

0 comments on commit 8c4154b

Please sign in to comment.