Skip to content

Instantly share code, notes, and snippets.

@ycrao
Created September 14, 2014 02:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ycrao/bd9a9f45e453f6aa2c72 to your computer and use it in GitHub Desktop.
Save ycrao/bd9a9f45e453f6aa2c72 to your computer and use it in GitHub Desktop.
YuiCompressorGUI.ahk
#SingleInstance force
#NoTrayIcon
yuic_path = %A_ScriptDir%\javabin\yuicompressor-2.4.7.jar
batfilename=yuic.bat
IfNotExist, %yuic_path%
{
Msgbox, YuiCompressor文件缺失,请确保javabin子目录下有yuicompressor-2.4.7.jar文件
ExitApp
}
IfExist, %yuic_path%
{
RegExMatch(yuic_path, "[^\w_\\\:``~#@\$%\^&\(\);,=\+-\[\]\{\}]+", _ExistChinese)
if _ExistChinese
{
MsgBox, 本程序不支持在中文名路径下运行,请转移程序文件到英文名目录下再使用本软件
ExitApp
}
}
FileDelete, err.txt
RunWait, %comspec% /c java>>err.txt, , Hide UseErrorLevel
;>>err.txt
;MsgBox, %A_LastError% %ErrorLeveL%
if ErrorLevel
{
MsgBox, 4, 是否继续, Java运行环境似乎没有安装,请到http://java.com/zh_CN/download/manual.jsp下载JRE;`r`n如果您确定已经安装JRE,点击是按钮继续运行,否按钮直接退出程序
IfMsgBox No
ExitApp
else return
}
Gui, Add, Text, x50 y30 w200 h20, 点击文件按钮来选定待压缩文件:
Gui, Add, Edit, x50 y50 w180 h20 vFilePath
Gui, Add, Button, x240 y50 w60 h20 gImportFile, 文件...
Gui, Add, Text, x50 y80 w35 h20, 编码:
Gui, Add, DropDownList, x85 y75 w75 h50 vFileEncoding, ansi|utf-8
Gui, Add, Button, x240 y75 w60 h20 gCompress, 压缩
Gui, Add, Text, x50 y120 w300 h80, 友情提示:YUICompressor需要Java运行环境`r`n请确保您的电脑已经安装JRE`r`n不知YUICompressor者,请找度娘和谷叔
; Generated using SmartGUI Creator for SciTE
Gui, Show, w350 h170, YUICompressor GUI版 QQ:837454876
return
ImportFile:
FileSelectFile,import_filename, , , ,Text(*.js;*.css)
if import_filename
GuiControl,,FilePath,% import_filename
return
Compress:
Gui,Submit,nohide
;MsgBox, %FilePath% %FileEncoding%
if ((FilePath="") OR (FileEncoding=""))
MsgBox, 操作错误,检查文件路径、类型和编码是否正确或选定
else
{
RegExMatch(FilePath, "[^\w_\\\:\s``~#@\$%\^&\(\);,=\+-\[\]\{\}]+", _isChinese)
if _isChinese
MsgBox, 抱歉,待压缩的JS或CSS文件路径包含有中文名或空格名,无法正常使用YuiCompressor来压缩,`r`n请转移JS/CSS文件到不含空格的英文目录下再使用本软件
else{
SplitPath, FilePath, file_name, file_dir, file_ext, file_name_no_ext
if(FileEncoding="uft-8")
{
bat=java -jar %yuic_path% --type %file_ext% --charset utf-8 %FilePath% -o %file_dir%\%file_name_no_ext%_min.%file_ext%
IfExist %batfilename%
FileDelete %batfilename%
FileAppend, %bat%, %batfilename%
Run, %batfilename%, , Hide UseErrorLevel
if !ErrorLevel
MsgBox, 压缩完成
else
MsgBox, 压缩失败,请检查Java运行环境或JS/CSS文件
}
else
{
bat=java -jar %yuic_path% --type %file_ext% %FilePath% -o %file_dir%\%file_name_no_ext%_min.%file_ext%
IfExist %batfilename%
FileDelete %batfilename%
FileAppend, %bat%, %batfilename%
Run, %batfilename%, , Hide UseErrorLevel
if !ErrorLevel
MsgBox, 压缩完成
else
MsgBox, 压缩失败,请检查Java运行环境或JS/CSS文件
}
}
FileDelete, %batfilename%
}
/*
YUICompressor使用示例:
java -jar D:\yuicompressor-2.4.2\build\yuicompressor-2.4.2.jar --charset UTF-8 D:\my.js -o D:\my-min.js
java -jar D:\yuicompressor-2.4.2\build\yuicompressor-2.4.2.jar --charset UTF-8 D:\my.css -o D:\my-min.css
//压缩JS
java -jar yuicompressor-2.4.7.jar --type js --charset utf-8 -v src.js > packed.js
//压缩CSS
java -jar yuicompressor-2.4.7.jar --type css --charset utf-8 -v src.css > packed.css
*/
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment