@echo off rem nodejs is required for some functions of this script, as well as the following npm modules (global): rem uglify-js@3 clean-css-cli html-minifier json-minify if NOT "%1" == "" ( goto %1 ) else ( goto all ) :clean goto do_clean :loader call :do_js loader.out.js . if "%1" == "loader" goto cleanup :all :patch_howler call :do_diff howler.orig.js howler.js howler.diff.txt if "%1" == "patch_howler" goto cleanup :patch_wavesurfer call :do_diff wavesurfer.orig.js wavesurfer.js wavesurfer.diff.txt if "%1" == "patch_wavesurfer" goto cleanup :get_jquery_version for /F "tokens=* USEBACKQ" %%a in (`sync_sftp.bat jquery_version`) do set jquery_version=%%a if "%1" == "get_jquery_version" goto :eof :javascript :js rem if "%jquery_version" == "" goto get_jquery_version call :do_js jquery-ui.js . call :do_js wavesurfer.js . call :do_js howler.js . call :do_js loopplayer.html5.core.js . "--mangle reserved=[z_urlp,dm,offline]" if "%1" == "js" goto cleanup if "%1" == "javascript" goto cleanup :json :conf call :do_json audio.conf.js call :do_json audiosecret.conf.js if "%1" == "conf" goto cleanup if "%1" == "json" goto cleanup :html call :do_html index.desktop.out.html call :do_html index.mobile.out.html if "%1" == "html" goto cleanup :css call :do_css style.common.css call :do_css style.desktop.css call :do_css style.mobile.css call :do_css jquery-ui.css call :do_css jquery-ui.theme.css call :do_css jquery-ui.structure.css call :do_css geshi.css goto cleanup rem if "%1" == "css" goto cleanup :failed echo This stage of the batch script failed call :cleanup exit /B 1 :cleanup exit /B 0 :do_css echo Minifying %1 if exist "%~n1.min.css" del "%~n1.min.css" call cleancss -O2 -o "%~n1.min.css" "%~n1.css" if not exist "%~n1.min.css" goto failed goto :eof :do_html echo Minifying %1 if exist "%~n1.min.html" del "%~n1.min.html" call html-minifier --html5 --collapse-boolean-attributes --collapse-inline-tag-whitespace --collapse-whitespace --conservative-collapse --remove-comments --remove-empty-attributes --remove-optional-tags --remove-redundant-attributes --remove-script-type-attributes --remove-style-link-type-attributes --remove-attribute-quotes -o "%~n1.min.html" "%~n1.html" if not exist "%~n1.min.html" goto failed goto :eof :do_js rem Okay this is a pain so I'll explain it a little. ztmp_comarg stores the rem default uglifyjs compression args we use set ztmp_comparg=--compress drop_console,toplevel,passes=10 set ztmp_jsargs=--toplevel rem If the second arg passed to this subroutine is not a period (we cant set ""), rem then add the contents of the second param if NOT "%2" == "." set ztmp_comparg=%ztmp_comparg%,%2 rem If the second arg passed to this subroutine is a dash, rem then don't use any compression args, nor the mangle option. if "%2" == "-" ( set "ztmp_comparg=" set "ztmp_jsargs=" ) rem Here is where it gets tricky. any override args we want to pass go in the 3rd var rem so for example "--mangle reserved=[myVarName]" would normally be the third and fourth rem vars, but since its in quotes it counts as only the third. HOWEVER rem for some reason Windows also passes the quotes themselves in the var, so we need rem to remove them for more sane applications, such as uglifyjs. This bit below does that. rem Another catch is, if there is no third param, it will set the var to "= .. so we need rem to check against THAT as well, and unset it if that is the case set ztmp_jsargs_override=%3 set ztmp_jsargs_override=%ztmp_jsargs_override:"=% if not "%ztmp_jsargs:~1,1%" == "=" ( if not "%ztmp_jsargs_override:~1,1%" == "=" set "ztmp_jsargs=%ztmp_jsargs_override%" ) echo Minifying %1 if exist "%~n1.min.js" del "%~n1.min.js" call uglifyjs "%1" %ztmp_comparg% %ztmp_jsargs% --comments -o %~n1.min.js set "ztmp_xtra=" set "ztmp_jsargs=" set "ztmp_comparg=" if not exist "%~n1.min.js" goto failed goto :eof :do_json echo Minifying %1 if exist "%~n1.min.js" del "%~n1.min.js" call json-minify "%1" > "%~n1.min.js" goto :eof :do_diff echo Creating %3 if exist "%3" del "%3" diff -Naur "%1" "%2" > "%3" if not exist "%3" goto failed goto :eof :do_clean if exist "howler.patch.txt" del howler.patch.txt if exist "*.min.*" del *.min.* goto :eof :eof