Created
April 20, 2012 05:50
-
-
Save neekey/2426413 to your computer and use it in GitHub Desktop.
YUI Compressor Shell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# YUI compressor shell 简单脚本 | |
# params: | |
# -f 需要压缩的文件名 | |
# -o 输出文件名 | |
# -c 压缩编码 | |
# 使用说明: | |
# 在~/.profile 中为本脚本的执行添加一个别名比如: | |
# alias yui="/users/neekey/yuicompressor.sh" | |
# 然后进入需要压缩文件的目录: | |
# yui -f source.js -o source-min.js -c 'gbk' | |
#设置变量 | |
yui_dir='/users/neekey/yuicompressor/yuicompressor-2.4.6.jar' | |
source_name='' | |
output_name='' | |
charset='gb18030' | |
cur_dir=${PWD} | |
suffix='' | |
#获取参数 | |
while getopts 'f:c:o:' options | |
do | |
case $options in | |
f) source_name=${OPTARG} | |
#获取源文件的后缀 | |
suffix=${source_name##*.};; | |
c) charset=${OPTARG};; | |
o) output_name=${OPTARG};; | |
esac | |
done | |
if [ "${output_name}" = "" ] | |
then | |
output_name=${source_name%%.*} | |
fi | |
# run yuicompressor | |
echo '构造执行语句' | |
yuicommand="java -jar ${yui_dir} -o ${cur_dir}/${output_name}-min.${suffix} --charset ${charset} ${cur_dir}/${source_name}" | |
echo '待执行语句:' | |
echo ${yuicommand} | |
echo '开始进行压缩' | |
${yuicommand} | |
echo '压缩完毕' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment