mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-11 02:48:39 +00:00
Update javascript minifying script
- When both minifying modules are missing, creating a copy of the debug file is not actually desirable, a missing file is more obvious than a copy. WebUI can handle a missing 'normal' script and fallback to 'debug' script so modified script to skip and warn instead.
This commit is contained in:
parent
ee354eb107
commit
80178f7310
1 changed files with 36 additions and 36 deletions
|
@ -22,27 +22,23 @@ import fnmatch
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
from distutils.spawn import find_executable
|
||||||
|
|
||||||
|
closure_cmd = None
|
||||||
|
for cmd in ['closure-compiler', 'closure']:
|
||||||
|
if find_executable(cmd):
|
||||||
|
closure_cmd = cmd
|
||||||
|
break
|
||||||
|
|
||||||
|
|
||||||
def module_exists(module_name):
|
def minify_closure(file_in, file_out):
|
||||||
try:
|
|
||||||
__import__(module_name)
|
|
||||||
except ImportError:
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
# Imports sorted by resulting file size.
|
|
||||||
if module_exists('closure'):
|
|
||||||
|
|
||||||
def minify_closure(file_in, file_out):
|
|
||||||
try:
|
try:
|
||||||
subprocess.check_call(
|
subprocess.check_call(
|
||||||
[
|
[
|
||||||
'closure',
|
closure_cmd,
|
||||||
'-W',
|
'--warning_level',
|
||||||
'QUIET',
|
'QUIET',
|
||||||
|
'--language_in=ECMASCRIPT5',
|
||||||
'--js',
|
'--js',
|
||||||
file_in,
|
file_in,
|
||||||
'--js_output_file',
|
'--js_output_file',
|
||||||
|
@ -54,13 +50,17 @@ if module_exists('closure'):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
elif module_exists('slimit'):
|
# Closure outputs smallest files but it is a java-based command, so have slimit
|
||||||
from slimit import minify
|
# as a python-only fallback.
|
||||||
else:
|
#
|
||||||
print('WARNING: Unable to minify js files. They will be copied as is.')
|
# deluge-all.js: Closure 127K, Slimit: 143K, JSMin: 162K
|
||||||
|
#
|
||||||
def minify(text):
|
if not closure_cmd:
|
||||||
return text
|
try:
|
||||||
|
from slimit import minify as minify
|
||||||
|
except ImportError:
|
||||||
|
print('Warning: No minifying command found.')
|
||||||
|
minify = None
|
||||||
|
|
||||||
|
|
||||||
def source_files_list(source_dir):
|
def source_files_list(source_dir):
|
||||||
|
@ -95,9 +95,9 @@ def concat_src_files(file_list, fileout_path):
|
||||||
|
|
||||||
|
|
||||||
def minify_file(file_debug, file_minified):
|
def minify_file(file_debug, file_minified):
|
||||||
try:
|
if closure_cmd:
|
||||||
return minify_closure(file_debug, file_minified)
|
return minify_closure(file_debug, file_minified)
|
||||||
except NameError:
|
elif minify:
|
||||||
with open(file_minified, 'w') as file_out:
|
with open(file_minified, 'w') as file_out:
|
||||||
with open(file_debug, 'r') as file_in:
|
with open(file_debug, 'r') as file_in:
|
||||||
file_out.write(minify(file_in.read()))
|
file_out.write(minify(file_in.read()))
|
||||||
|
@ -118,7 +118,7 @@ def minify_js_dir(source_dir):
|
||||||
concat_src_files(source_files, file_debug_js)
|
concat_src_files(source_files, file_debug_js)
|
||||||
print('Minifying %s' % source_dir)
|
print('Minifying %s' % source_dir)
|
||||||
if not minify_file(file_debug_js, file_minified_js):
|
if not minify_file(file_debug_js, file_minified_js):
|
||||||
print('Error minifying %s' % source_dir)
|
print('Warning: Failed minifying files %s, debug only' % source_dir)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue