Back to Deck
Terminal window
[workflow]
Nuxt -> GH Pages Deploy
ИСХОДНИК Shell
ВЕРСИЯ 1.0
АВТОР Cododel
Автоматизирует развертывание статического сайта Nuxt.js на GitHub Pages. Обрабатывает создание ветки (gh-pages), внедрение конфигурации (cdnURL), сборку и push.
Основные возможности
- Проверка незакоммиченных изменений
- Создание Orphan ветки: Создает
gh-pages, если она не существует. - Инъекция конфига: Динамически устанавливает
cdnURLиbuildAssetsDirна основе имени репозитория. - Безопасная очистка: Удаляет артефакты сборки, но сохраняет
node_modules.
Исходный код
# If has not commited changes - stopr scriptif [ -n "$(git status --porcelain)" ]; then echo "Please commit your changes before deploying" exit 1fi
# If has no node_modules - install itif [ ! -d "node_modules" ]; then bun installfi
# Checkout to gh-pages branchif [ -n "$(git branch --list gh-pages)" ]; then git checkout gh-pages --forceelse # If has not gh-pages branch - create it git checkout --orphan gh-pages find . -maxdepth 1 \ ! -name 'node_modules' \ ! -name '.git' \ ! -name '.' \ -exec rm -rf {} \; echo "node_modules" > .gitignore git add .gitignore git commit -m "Initial commit"fi
git checkout master -- .
# Recover .gitignoregit checkout gh-pages -- .gitignore
# Prepare project with adding baseUrl to nuxt.config.ts using repository name as baseUrlREPOSITORY_NAME=$(git remote get-url origin | sed 's/.*\/\([^/]*\)\.git/\1/')REPOSITORY_OWNER=$(git remote get-url origin | sed 's/.*github.com\/\([^/]*\)\/.*/\1/')
# Insert baseurl after export "default defineNuxtConfig({" linesed "s/\(export default defineNuxtConfig({\)/\1\n app: {cdnURL: 'https:\/\/$REPOSITORY_OWNER.github.io\/$REPOSITORY_NAME', buildAssetsDir: 'app'},\n router: { options: {hashMode: true} },/" nuxt.config.ts > nuxt.config.ts.tmpmv nuxt.config.ts.tmp nuxt.config.ts
# Build projectbun run generate
# Remove all files except dist and node_modulesfind . -maxdepth 1 \ ! -name 'dist' \ ! -name '.output' \ ! -name '.gitignore' \ ! -name 'node_modules' \ ! -name '.git' \ ! -name '.' \ -exec rm -rf {} \;
# Move dist files to rootmv dist/* .rm -rf dist .output
# Commit and push to gh-pagesgit add .git commit -m "Deploy to gh-pages"git push origin gh-pages
# Checkout to mastergit checkout master