diff --git a/README.md b/README.md index 75842c4..748ce37 100644 --- a/README.md +++ b/README.md @@ -1,38 +1,76 @@ -# sv +# jnss-web -Everything you need to build a Svelte project, powered by [`sv`](https://github.com/sveltejs/cli). +Static website for jnss.me - built with SvelteKit and deployed via Caddy. -## Creating a project +## Project Structure -If you're seeing this, you've probably already done this step. Congrats! +This project uses a **two-branch deployment strategy**: +- **`main` branch**: Source code and development + - Contains all source files, configuration, and build tooling + - `build/` directory is gitignored +- **`deploy` branch**: Orphan branch with build outputs only + - Contains only the static build artifacts (index.html, _app/, etc.) + - No source code or build dependencies + - Used by Ansible/Caddy for serving the site + +## Development + +Install dependencies: ```sh -# create a new project in the current directory -npx sv create - -# create a new project in my-app -npx sv create my-app +bun install ``` -## Developing - -Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server: - +Start development server: ```sh -npm run dev +bun run dev -# or start the server and open the app in a new browser tab -npm run dev -- --open +# or open in browser automatically +bun run dev -- --open ``` ## Building -To create a production version of your app: - +Build the static site: ```sh -npm run build +bun run build ``` -You can preview the production build with `npm run preview`. +Preview the production build locally: +```sh +bun run preview +``` -> To deploy your app, you may need to install an [adapter](https://svelte.dev/docs/kit/adapters) for your target environment. +## Deployment + +This project uses an automated deployment script that builds and pushes to the `deploy` branch: + +```sh +# Deploy with auto-generated timestamp commit message +./deploy.sh + +# Deploy with custom commit message +./deploy.sh "Add new feature X" +``` + +**What the script does:** +1. Builds the site on the `main` branch (`bun run build`) +2. Switches to the `deploy` branch +3. Clears old build files +4. Moves new build output to the root of `deploy` branch +5. Commits and pushes to `origin/deploy` +6. Switches back to `main` branch + +**For rick-infra:** +The Ansible role clones the `deploy` branch to get production-ready static files: +```sh +git clone -b deploy git@jnss.me:joakim/jnss-web.git +``` + +## Tech Stack + +- **Framework**: SvelteKit 2.x with static adapter +- **Build Tool**: Vite 7.x +- **Package Manager**: Bun +- **Deployment**: Two-branch strategy (main โ†’ source, deploy โ†’ build artifacts) +- **Hosting**: Caddy (configured via rick-infra) diff --git a/deploy.sh b/deploy.sh new file mode 100755 index 0000000..d6c72dd --- /dev/null +++ b/deploy.sh @@ -0,0 +1,59 @@ +#!/usr/bin/env bash +# deploy.sh - Build and deploy to orphan deploy branch +# Usage: ./deploy.sh [commit-message] + +set -e + +COMMIT_MSG="${1:-Deploy: $(date +'%Y-%m-%d %H:%M:%S')}" + +echo "๐Ÿ“ฆ Building site on main branch..." +bun run build + +if [ ! -d "build" ]; then + echo "โŒ Build failed - build directory not found" + exit 1 +fi + +echo "โœ… Build successful" +echo "" +echo "๐Ÿ”„ Switching to deploy branch..." +git checkout deploy + +echo "๐Ÿงน Cleaning deploy branch (keeping .git and .gitignore)..." +# Remove all tracked files except .gitignore +git ls-files | grep -v "^\.gitignore$" | xargs -r git rm -f +# Remove any untracked files/directories except build/, node_modules/, and .svelte-kit/ +find . -mindepth 1 -maxdepth 1 ! -name 'build' ! -name 'node_modules' ! -name '.svelte-kit' ! -name '.git' ! -name '.gitignore' -exec rm -rf {} + + +echo "๐Ÿ“‹ Copying build output to root..." +if [ -d "build" ]; then + mv build/* . + rm -rf build/ + echo "โœ… Build files copied to deploy branch root" +else + echo "โš ๏ธ No build directory found (this is expected on deploy branch)" +fi + +echo "๐Ÿ“ Staging changes..." +git add -A + +# Check if there are any changes to commit +if git diff --staged --quiet; then + echo "โ„น๏ธ No changes to deploy" + git checkout main + exit 0 +fi + +echo "๐Ÿ’พ Committing build artifacts..." +git commit -m "$COMMIT_MSG" + +echo "๐Ÿš€ Pushing to origin/deploy..." +git push origin deploy + +echo "โœ… Switching back to main..." +git checkout main + +echo "" +echo "โœจ Deployment complete!" +echo " Deploy branch commit: $(git rev-parse --short deploy)" +echo " Main branch commit: $(git rev-parse --short main)"