Skip to content

Commit a9bbb8a

Browse files
chore: add worktree prepare script (#1798)
* chore: add worktree prepare script Adds a scripts/worktree-prepare.sh that automates setting up a git worktree: installs deps, links the Vercel project, and copies .env.development.local from the main worktree. Exposed as pnpm worktree:prepare. * fix: skip env copy when running from primary worktree cp fails on self-copy under set -e when the main worktree is also the current directory. Guard the copy step with a path comparison.
1 parent c311669 commit a9bbb8a

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"test:e2e:debug": "playwright test --debug",
3333
"promo": "pnpm -s script src/scripts/encrypt-promo-codes.ts",
3434
"dev:discord-gateway-cron": "tsx dev/discord-gateway-cron.ts",
35+
"worktree:prepare": "bash scripts/worktree-prepare.sh"
3536
"dev:start": "tsx --tsconfig tsconfig.scripts.json dev/local/cli.ts up",
3637
"dev:stop": "tsx --tsconfig tsconfig.scripts.json dev/local/cli.ts stop",
3738
"dev:env": "tsx --tsconfig tsconfig.scripts.json dev/local/cli.ts env"

scripts/worktree-prepare.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
# Prepares a git worktree by installing dependencies, linking the Vercel
4+
# project, and copying .env.development.local from the main worktree.
5+
6+
MAIN_WORKTREE="$(git worktree list --porcelain | head -1 | sed 's/^worktree //')"
7+
ENV_FILE=".env.development.local"
8+
9+
if command -v nvm &>/dev/null || [ -s "${NVM_DIR:-$HOME/.nvm}/nvm.sh" ]; then
10+
echo "==> Switching to correct Node version…"
11+
# nvm is a shell function, not a binary — source it if needed
12+
if ! command -v nvm &>/dev/null; then
13+
source "${NVM_DIR:-$HOME/.nvm}/nvm.sh"
14+
fi
15+
nvm use
16+
fi
17+
18+
echo "==> Installing dependencies…"
19+
pnpm install
20+
21+
echo "==> Linking Vercel project…"
22+
vercel link --yes --project kilocode-app --scope kilocode
23+
24+
if [ "$(cd "$MAIN_WORKTREE" && pwd -P)" = "$(pwd -P)" ]; then
25+
echo "==> Skipping $ENV_FILE copy (already in primary worktree)"
26+
elif [ -f "$MAIN_WORKTREE/$ENV_FILE" ]; then
27+
echo "==> Copying $ENV_FILE from main worktree…"
28+
cp "$MAIN_WORKTREE/$ENV_FILE" "./$ENV_FILE"
29+
fi
30+
31+
echo "==> Worktree ready."

0 commit comments

Comments
 (0)