Skip to content

Instantly share code, notes, and snippets.

@TravisMullen
Last active October 10, 2019 22:06
Show Gist options
  • Save TravisMullen/0b70ad17adfc738c908122c0102e626a to your computer and use it in GitHub Desktop.
Save TravisMullen/0b70ad17adfc738c908122c0102e626a to your computer and use it in GitHub Desktop.
Generate static files for a vue cli repo.
bin/bash -e
DOMAIN=example.org
BUILD_DIR=/tmp/www-build
PRODUCTION_DIR=/var/www/html/$DOMAIN
OWNER=TravisMullen
REPO=TravisMullen-Vue
APP_TITLE="'Travis Mullen Brochure'"
# start ====
if test -d "$BUILD_DIR/.git"
then
cd $BUILD_DIR
else
git clone "https://github.com/$OWNER/$REPO.git" $BUILD_DIR
cd $BUILD_DIR
fi
# save commit hash as app/server version
git fetch
# override any funny business
git reset --hard origin/master
# check local repo (after pulling changes)
VUE_APP_RELEASE=$(git rev-parse --verify HEAD)
# check .env from last build
if [[ -f .env ]]; then
if [[ $(grep VUE_APP_RELEASE .env | cut -d '=' -f2) == $VUE_APP_RELEASE ]]
then
# tee /var/git-update-required
echo 'release is up to date!'
echo $VUE_APP_RELEASE
exit 0
fi
fi
echo 'release is out of sync with remote. time to rebuild...'
VUE_APP_TITLE=$APP_TITLE
# https://cli.vuejs.org/guide/mode-and-env.html#using-env-variables-in-client-side-code
echo 'BASE_URL=/' | tee $BUILD_DIR/.env
echo 'NODE_ENV=production' | tee --append $BUILD_DIR/.env
echo "VUE_APP_TITLE=$VUE_APP_TITLE" | tee --append $BUILD_DIR/.env
echo "VUE_APP_RELEASE=$VUE_APP_RELEASE" | tee --append $BUILD_DIR/.env
# build with dependencies
npm i
# https://cli.vuejs.org/guide/browser-compatibility.html#modern-mode
npm run build
mkdir -p $PRODUCTION_DIR
# backup existing
tar -zcvf "app.$(date +%s).tar.gz" $PRODUCTION_DIR
rm -r $PRODUCTION_DIR
mkdir -p $PRODUCTION_DIR
mv dist/* $PRODUCTION_DIR
# clean up after ourselves
# cd /
# rm -rf $BUILD_DIR
echo "release updated to: $VUE_APP_RELEASE"
systemctl restart nginx
echo $VUE_APP_RELEASE
exit 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment