Skip to content

Commit

Permalink
Cleanup up minify js script
Browse files Browse the repository at this point in the history
 - The slimit package is now widely available so make the script
   only rely on it and closure. Keeping closure as it makes the most
   compact and lints the javascript but it is not as easy to install
   as slimit.
  • Loading branch information
cas-- committed Nov 28, 2016
1 parent 7468078 commit a48c01c
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions minify_web_js.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import fileinput
import fnmatch
import os
import subprocess
import sys


Expand All @@ -35,21 +36,16 @@ def module_exists(module_name):
# Imports sorted by resulting file size.
if module_exists('closure'):
def minify_closure(file_in, file_out):
import subprocess
try:
subprocess.check_call(['closure', '-W', 'QUIET',
'--js', file_in, '--js_output_file', file_out])
return True
except subprocess.CalledProcessError:
return False
elif module_exists('slimit'):
elif module_exists('sslimit'):
from slimit import minify
elif module_exists('jsmin'):
from jsmin import jsmin as minify
elif module_exists('rjsmin'):
from rjsmin import jsmin as minify
else:
raise ImportError('Minifying WebUI JS requires slimit, jsmin or rjsmin')
raise ImportError('Requires "slimit" package for minifying WebUI files.')


def source_files_list(source_dir):
Expand Down Expand Up @@ -105,9 +101,8 @@ def minify_js_dir(source_dir):
return

concat_src_files(source_files, file_debug_js)
if minify_file(file_debug_js, file_minified_js):
print('Minified %s' % source_dir)
else:
print('Minifying %s' % source_dir)
if not minify_file(file_debug_js, file_minified_js):
print('Error minifying %s' % source_dir)


Expand Down

0 comments on commit a48c01c

Please sign in to comment.