Skip to content

Instantly share code, notes, and snippets.

@simonwep
Created December 27, 2019 15:21
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 simonwep/0b3082185192dd634ce57efdae2205a5 to your computer and use it in GitHub Desktop.
Save simonwep/0b3082185192dd634ce57efdae2205a5 to your computer and use it in GitHub Desktop.
Builds your app and moves all production files to the gh-pages branch
#!/bin/bash
BRANCH="gh-pages"
echo "[DGP] Deploying to github-pages (branch $BRANCH)..."
# Check if there are current changes
if [[ "$(git status --porcelain --untracked-files=no)" ]]; then
echo "[DPG] Please undo your current changes."
exit
fi
# Building dist files
echo "[DGP] Building dist files..."
npm run build
# Stage files
echo "[DGP] Staging files..."
git stash --include-untracked
# Delete existing branch
if git show-ref --quiet refs/heads/"$BRANCH"; then
echo "[DGP] $BRANCH found, deleting it..."
git branch -d "$BRANCH"
fi
# Create new orphan branch
echo "[DGP] Creating new orphan branch..."
git checkout --orphan "$BRANCH"
# Unstage everything
git reset
# Stage dist files and gitignore
git add .gitignore
git clean -d -f
# Get stash, move dist file up and stage everything
git stash pop
mv ./dist/* .
git add .
# Commit and push
git commit -m "Update"
git push --set-upstream origin "$BRANCH" -f
# Switch back to master
git checkout master -f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment