GeSHi Source Viewer: minify.batView Raw


  1. @echo off
  2.  
  3. rem nodejs is required for some functions of this script, as well as the following npm modules (global):
  4. rem uglify-js@3 clean-css-cli html-minifier json-minify
  5.  
  6. if NOT "%1" == "" ( 
  7. 	goto %1
  8. ) else (
  9. 	goto all
  10. )
  11.  
  12. :clean
  13. goto do_clean
  14.  
  15. :loader
  16. call :do_js loader.out.js .
  17. if "%1" == "loader" goto cleanup   
  18.  
  19. :all
  20.  
  21. :patch_howler
  22. call :do_diff howler.orig.js howler.js howler.diff.txt
  23. if "%1" == "patch_howler" goto cleanup
  24.  
  25. :patch_wavesurfer
  26. call :do_diff wavesurfer.orig.js wavesurfer.js wavesurfer.diff.txt
  27. if "%1" == "patch_wavesurfer" goto cleanup
  28.  
  29.  
  30. :get_jquery_version
  31. for /F "tokens=* USEBACKQ" %%a in (`sync_sftp.bat jquery_version`) do set jquery_version=%%a
  32. if "%1" == "get_jquery_version" goto :eof 
  33.  
  34. :javascript
  35. :js
  36. rem if "%jquery_version" == "" goto get_jquery_version
  37.  
  38. call :do_js jquery-ui.js .
  39. call :do_js wavesurfer.js .
  40. call :do_js howler.js .
  41. call :do_js loopplayer.html5.core.js . "--mangle reserved=[z_urlp,dm,offline]"
  42. if "%1" == "js" goto cleanup 
  43. if "%1" == "javascript" goto cleanup
  44.  
  45. :json
  46. :conf
  47. call :do_json audio.conf.js
  48. call :do_json audiosecret.conf.js
  49. if "%1" == "conf" goto cleanup
  50. if "%1" == "json" goto cleanup
  51.  
  52. :html
  53. call :do_html index.desktop.out.html
  54. call :do_html index.mobile.out.html
  55. if "%1" == "html" goto cleanup
  56.  
  57. :css
  58. call :do_css style.common.css
  59. call :do_css style.desktop.css
  60. call :do_css style.mobile.css
  61. call :do_css jquery-ui.css
  62. call :do_css jquery-ui.theme.css
  63. call :do_css jquery-ui.structure.css
  64. call :do_css geshi.css
  65. goto cleanup
  66. rem if "%1" == "css" goto cleanup
  67.  
  68.  
  69. :failed
  70. echo This stage of the batch script failed
  71. call :cleanup
  72. exit /B 1
  73.  
  74. :cleanup
  75. exit /B 0
  76.  
  77. :do_css
  78. echo Minifying %1
  79. if exist "%~n1.min.css" del "%~n1.min.css"
  80. call cleancss -O2 -o "%~n1.min.css" "%~n1.css"
  81. if not exist "%~n1.min.css" goto failed
  82. goto :eof
  83.  
  84. :do_html
  85. echo Minifying %1
  86. if exist "%~n1.min.html" del "%~n1.min.html"
  87. 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"
  88. if not exist "%~n1.min.html" goto failed
  89. goto :eof
  90.  
  91. :do_js
  92. rem Okay this is a pain so I'll explain it a little. ztmp_comarg stores the
  93. rem default uglifyjs compression args we use
  94. set ztmp_comparg=--compress drop_console,toplevel,passes=10
  95. set ztmp_jsargs=--toplevel 
  96.  
  97. rem If the second arg passed to this subroutine is not a period (we cant set ""),
  98. rem then add the contents of the second param
  99. if NOT "%2" == "." set ztmp_comparg=%ztmp_comparg%,%2
  100.  
  101. rem If the second arg passed to this subroutine is a dash,
  102. rem then don't use any compression args, nor the mangle option.
  103. if "%2" == "-" (
  104. 	set "ztmp_comparg="
  105. 	set "ztmp_jsargs="
  106. )
  107.  
  108. rem Here is where it gets tricky. any override args we want to pass go in the 3rd var
  109. rem so for example "--mangle reserved=[myVarName]" would normally be the third and fourth
  110. rem vars, but since its in quotes it counts as only the third. HOWEVER
  111. rem for some reason Windows also passes the quotes themselves in the var, so we need
  112. rem to remove them for more sane applications, such as uglifyjs. This bit below does that.
  113. rem Another catch is, if there is no third param, it will set the var to "= .. so we need
  114. rem to check against THAT as well, and unset it if that is the case
  115.  
  116. set ztmp_jsargs_override=%3
  117. set ztmp_jsargs_override=%ztmp_jsargs_override:"=%
  118. if not "%ztmp_jsargs:~1,1%" == "=" (
  119. 	if not "%ztmp_jsargs_override:~1,1%" == "=" set "ztmp_jsargs=%ztmp_jsargs_override%"
  120. )
  121.  
  122.  
  123. echo Minifying %1
  124. if exist "%~n1.min.js" del "%~n1.min.js"
  125. call uglifyjs "%1" %ztmp_comparg% %ztmp_jsargs% --comments -o %~n1.min.js 
  126. set "ztmp_xtra="
  127. set "ztmp_jsargs="
  128. set "ztmp_comparg="
  129. if not exist "%~n1.min.js" goto failed
  130. goto :eof
  131.  
  132. :do_json
  133. echo Minifying %1
  134. if exist "%~n1.min.js" del "%~n1.min.js"
  135. call json-minify "%1" > "%~n1.min.js"
  136. goto :eof
  137.  
  138. :do_diff
  139. echo Creating %3
  140. if exist "%3" del "%3"
  141. diff -Naur "%1" "%2" > "%3"
  142. if not exist "%3" goto failed
  143. goto :eof
  144.  
  145. :do_clean
  146. if exist "howler.patch.txt" del howler.patch.txt
  147. if exist "*.min.*" del *.min.*
  148. goto :eof
  149.  
  150. :eof