Skip to content

Instantly share code, notes, and snippets.

@benjamintanweihao
Forked from xaviershay/build_frontend.sh
Created October 7, 2013 00:32
Show Gist options
  • Select an option

  • Save benjamintanweihao/6860906 to your computer and use it in GitHub Desktop.

Select an option

Save benjamintanweihao/6860906 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -ex
BUILD_ENV=$1
rm -Rf public
mkdir -p public/styles
function bower_components() {
cat app/index.html | \
grep bower_components | \
cut -d '"' -f 2 | \
sed -e 's/^/app/'
}
coffee -o public/scripts -c app/scripts
node-sass --include-path app/bower_components/foundation/scss \
app/styles/main.scss public/styles/main.css
cp app/index.html public
cp -r app/views public/views
cp -r app/fonts public/fonts
if [ $BUILD_ENV == 'production' ]; then
find public/scripts -type f | xargs cat | ngmin | yuicompressor --type js > public/all.js
ALL_SHA=$(md5 -q public/all.js)
mv public/all.js public/$ALL_SHA.js
rm -Rf public/scripts
bower_components |
xargs cat > \
public/vendor.js
VENDOR_SHA=$(md5 -q public/vendor.js)
mv public/vendor.js public/$VENDOR_SHA.js
sed -e "/<script src=\"\/scripts/d" -i '' public/index.html
sed -e "/<script src=\"\/bower_components/d" -i '' public/index.html
sed -e "s/<\/body>/<script src=\"\/$VENDOR_SHA.js\"><\/script><script src=\"\/$ALL_SHA.js\"><\/script><\/body>/" \
-i '' public/index.html
else
mkdir -p public/bower_components
for f in $(bower_components); do
cp $f public/bower_components
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment