Automates the deployment of a Nuxt.js static site to GitHub Pages. It handles branch creation (gh-pages), configuration injection (cdnURL), build, and push.
Main Features
Checks for uncommitted changes
Orphan branch creation: Creates gh-pages if it doesn’t exist.
Config Injection: Dynamically sets cdnURL and buildAssetsDir based on the repository name.
Safe Cleanup: Removes build artifacts but keeps node_modules.
Source Code
Terminal window
# If has not commited changes - stopr script
if [ -n"$(git status --porcelain)" ]; then
echo"Please commit your changes before deploying"
exit1
fi
# If has no node_modules - install it
if [ !-d"node_modules" ]; then
buninstall
fi
# Checkout to gh-pages branch
if [ -n"$(git branch --list gh-pages)" ]; then
gitcheckoutgh-pages--force
else# If has not gh-pages branch - create it
gitcheckout--orphangh-pages
find.-maxdepth1\
!-name'node_modules'\
!-name'.git'\
!-name'.'\
-execrm-rf{}\;
echo"node_modules">.gitignore
gitadd.gitignore
gitcommit-m"Initial commit"
fi
gitcheckoutmaster--.
# Recover .gitignore
gitcheckoutgh-pages--.gitignore
# Prepare project with adding baseUrl to nuxt.config.ts using repository name as baseUrl