我正在使用App Engine,我正在考虑在下一个项目中使用LESS CSS扩展.没有用
Python编写的好的LESS CSS库,所以我继续使用原始的Ruby,它运行良好且开箱即用.在运行开发服务器之前和将文件上传到云之前,我希望App Engine执行lessc ./templates/css/style.less.什么是自动化的最佳方法?我在想:
#run.sh:
lessc ./templates/css/style.less
.gae/dev_appserver.py --use_sqlite .
和
#deploy.sh
lessc ./templates/css/style.less
.gae/appcfg.py update .
我是在正确的道路上还是有一种更优雅的做事方式,也许是在appcfg.py级别?
谢谢.
最佳答案 一种选择是使用Less的javascript版本,因此在浏览器中执行less-to-css转换..只需上传格式较小的文件(有关详细信息,请参阅
http://lesscss.org/).
或者,我在部署脚本中执行转换(首先使用较少的,现在我使用sass),该脚本执行许多操作
>检查我的源代码控件是否没有检出未完成的文件(未经修改的更改)
>将我的.js代码加入并缩小(并在其上运行jslint)到一个文件中
>生成其他内容(包括将源代码控制版本作为版本号标记到某些密钥文件中,并作为某些文件的参数以避免缓存问题)所以我的主页提取带有URL的脚本,例如“allmysource.js?v = 585“..文件可能是静态的,但添加的参数强制缓存失效
>调用appcfg执行上传并检查返回码
>使用wget对真实站点进行一些调用,通过检查它们是否标有预期版本来检查先前生成的文件是否实际返回
>应用另一个源代码控制标记来表示已成功部署预期版本
我的脚本还接受“-preview”标志,在这种情况下,它实际上不会执行上载,但会报告版本控制注释,以了解自上次部署以来更改的内容.
me@here $./deploy -preview
Deployment preview...
Would deploy v596 to the production site (currently v593, previously v587)
594 Fix blah blah blah for X Y Z
595 New feature nah nah nah
596 Update help pages
这非常方便,因为它提醒我需要放入像changelog这样的东西
我还计划扩展它,以便作为源代码控制的一部分,我可以添加任何只在部署时需要运行一次的代码(例如数据库模式更改)并且知道它将在我下次部署新代码时自动运行版.
人们问的下面脚本的本质……它没有显示我的“检查代码,生成,加入和缩小”,因为这是另一个脚本……我意识到原来的问题当然是询问那一步:)但你可以看到你在哪里添加调用来生成CSS等
#!/bin/sh
function abort () {
echo
echo "ERROR: $1"
echo "$2"
exit 99
}
function warn () {
echo
echo "WARNING: $1"
echo "$2"
}
# Overrides the Gentoo eselect mechanism to force the python version the GAE scripts expect
export EPYTHON=python2.5
# names of tags used to label bzr versions
CURR_DTAG=deployed
PREV_DTAG=prevDeployed
# command line options
PREVIEW=0
IGNORE_BZR=0
# These next few vars are set to values to identify my site, insert your own values here...
APPID=your_gae_appid_here
ADMIN_EMAIL=your_admin_email_address_here
SRCDIR=directory_to_deploy
CHECK_URL=url_of_page_to_retrive_that_does_upload_initialisation
for ARG; do
if [[ "$ARG" == "-preview" ]]; then
echo "Deployment preview..."
PREVIEW=1
fi
if [[ "$ARG" == "-force" ]]; then
echo "Ignoring the fact some files may not be committed to bzr..."
IGNORE_BZR=1
fi
done
echo
# check bzr for uncommited changed
BSTATUS=`bzr status`
if [[ "$BSTATUS" != "" ]]; then
if [[ "$IGNORE_BZR" == "0" ]]; then
abort "There are uncommited changes - commit/revert/ignore all files before deploying" "$BSTATUS"
else
warn "There are uncommited changes" "$BSTATUS"
fi
fi
# get version of numbers of last deployed etc
currver=`bzr log -l1 --line | sed -e 's/: .*//'`
lastver=`bzr log -rtag:${CURR_DTAG} --line | sed -e 's/: .*//'`
prevver=`bzr log -rtag:${PREV_DTAG} --line | sed -e 's/: .*//'`
lastlog=`bzr log -l 1 --line gae/changelog | sed -e 's/: .*//'`
RELEASE_NOTES=`bzr log --short --forward -r $lastver..$currver \
| perl -ne '$ver = $1 if /^ {0,4}(\d+) /; print " $ver $_" if ($ver and /^ {5,}\w/)' \
| grep -v "^ *$lastver "`
LOG_NOTES=`bzr log --short --forward -r $lastlog..$currver \
| perl -ne '$ver = $1 if /^ {0,4}(\d+) /; print " $ver $_" if ($ver and /^ {5,}\w/)' \
| grep -v "^ *$lastlog "`
# Crude but old habit - BUGBUGBUG is a marker in the code for things to be fixed before deployment
echo "Checking code for outstanding issues before deployment"
BUGSTATUS=`grep BUGBUGBUG js/*js`
if [[ "$BUGSTATUS" != "" ]]; then
if [[ "$IGNORE_BZR" == "0" ]]; then
abort "There are outstanding BUGBUGBUGs - fix them before deploying" "$BUGSTATUS"
else
warn "There are outstanding BUGBUGBUGs" "$BUGSTATUS"
fi
fi
echo
echo "Deploy v$currver to the production site (currently v$lastver, previously v$prevver)"
echo "$RELEASE_NOTES"
echo
if [[ "$currver" -gt "$lastlog" && "$lastver" -ne "$lastlog" ]]; then
echo "Changes since the changelog was last updated"
echo "$LOG_NOTES"
echo
fi
if [[ "$IGNORE_BZR" == "0" && $lastver -ge $currver ]]; then
abort "There don't appear to be any changes to deploy..."
fi
if [[ "$PREVIEW" == "1" ]]; then
exit 0
fi
$EPYTHON -c "import ssl" \
|| abort "$EPYTHON can't find ssl module for $EPYTHON - download it from pypi and install with the inbuilt setup.py"
# REMOVED - call to my script that calls jslint, generates files and compresses JS etc
# || abort "Generation of code failed"
/opt/google_appengine/appcfg.py --email=$ADMIN_EMAIL -v -A $APPID update $SRCDIR \
|| abort "Appcfg failed - upload presumably incomplete"
# move the tags to show we deployed properly
bzr tag -r $lastver --force ${PREV_DTAG}
bzr tag -r $currver --force ${CURR_DTAG}
echo
echo "Production site updated from v$lastver to v$currver (in turn from v$prevver)"
echo
echo "Now visiting $CHECK_URL to upload the source to the database"
# new version doesn't seem to always be there (may be caching by the webserver etc) to be uploaded into the database.. try again just in case
for cb in $RANDOM $RANDOM $RANDOM $RANDOM ; do
prodver=`wget $CHECK_URL?_cb=$cb -q -O - | perl -ne 'print $1 if /^\s*Rev #(\d+)\s*$/'`
if [[ "$currver" == "$prodver" ]]; then
echo "OK: New version $prodver successfully deployed"
exit 0
fi
echo "Retrying the upload of source to the database"
sleep 5
done
abort "The new source doesn't seem to be loading into the database" "Try 'wget $CHECK_URL?_cb=$RANDOM -q -O -'"
它不是特别大或聪明,但它可以自动完成上传工作