-
Notifications
You must be signed in to change notification settings - Fork 0
/
compiler.cmd
121 lines (109 loc) · 2.57 KB
/
compiler.cmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
@echo off
echo *******************************************************************************
echo *
echo * Closure/Packer/YUI Compiler 压缩JS/CSS文件
echo *
echo * 生成文件名后加“-min” 如 filename.(js/css) -^> filename-min.(js/css)
REM 过滤文件后缀,只压缩 js/css文件
if "%~x1" NEQ ".js" (
if "%~x1" NEQ ".css" (
echo *
echo *
echo * 错误:请选择 .js 或 .css 文件!
echo *
goto End
)
)
if "%~x1" EQU ".js" (
goto JS
)
if "%~x1" EQU ".css" (
goto CSS
)
:JS
set RESULT_FILE=%~n1-min%~x1
set RESULT_FILE_SIZE=%~z1
cd "%~dp1"
%~d1
"%~dp0compiler.jar" --js "%~nx1" --js_output_file "%RESULT_FILE%"
if %ERRORLEVEL% == 0 (
echo *
echo *
echo * Closure 压缩文件%~nx1到%RESULT_FILE%成功!
echo *
for %%a in ("%RESULT_FILE%") do (
echo * 文件大小从 %~z1 bytes 压缩到 %%~za bytes
set RESULT_FILE_SIZE=%%~za
)
) else (
echo *
echo *
echo * Closure :文件 %~nx1 中有写法错误,请仔细检查
echo *
goto End
)
"%~dp0packer.exe" "%RESULT_FILE%"
if %ERRORLEVEL% == 0 (
echo *
echo *
echo * Packer 压缩文件%RESULT_FILE%到%RESULT_FILE% 成功!
echo *
for %%a in ("%RESULT_FILE%") do (
echo * 文件大小从 %RESULT_FILE_SIZE% bytes 压缩到 %%~za bytes
if %RESULT_FILE_SIZE% LSS %%~za ( goto GG )
)
echo *
) else (
echo *
echo *
echo * Packer :文件 %~nx1 中有写法错误,请仔细检查
echo *
goto End
)
goto End
:CSS
cd "%~dp1"
%~d1
set RESULT_FILE=%~n1-min%~x1
"%~dp0yuicompressor-2.4.2.jar" --charset UTF-8 "%~nx1" -o "%RESULT_FILE%"
if %ERRORLEVEL% == 0 (
echo *
echo *
echo * YUICompressor 压缩文件%~nx1到%RESULT_FILE%成功!
echo *
for %%a in ("%RESULT_FILE%") do (
echo * 文件大小从 %~z1 bytes 压缩到 %%~za bytes
)
echo *
) else (
echo *
echo *
echo * YUICompressor :文件 %~nx1 中有写法错误,请仔细检查
echo *
goto End
)
goto End
:GG
"%~dp0compiler.jar" --js "%~nx1" --js_output_file "%RESULT_FILE%"
if %ERRORLEVEL% == 0 (
echo *
echo *
echo * Closure 重新压缩文件%~nx1到%RESULT_FILE%成功!
echo *
for %%a in ("%RESULT_FILE%") do (
echo * 文件大小从 %~z1 bytes 压缩到 %%~za bytes
)
echo *
) else (
echo *
echo *
echo * 文件 %~nx1 中有写法错误,请仔细检查
echo *
goto End
)
goto End
:End
echo *******************************************************************************
echo.
ENDLOCAL
pause