diff --git a/package.json b/package.json index 13aa047..f324577 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "prepare": "husky", "build": "pnpm -r run build", "check": "biome check .", - "format": "biome format --write ." + "format": "biome format --write .", + "link:dev": "bash scripts/link-dev.sh" }, "devDependencies": { "@biomejs/biome": "^1.9.0", diff --git a/scripts/link-dev.sh b/scripts/link-dev.sh new file mode 100755 index 0000000..25847a6 --- /dev/null +++ b/scripts/link-dev.sh @@ -0,0 +1,66 @@ +#!/usr/bin/env bash +# +# link-dev.sh — Switch ~/.uncaged-nerve to use the local monorepo packages. +# +# What it does: +# 1. Build all packages (pnpm -r build) +# 2. Link the CLI globally (nerve command → local build) +# 3. Link all @uncaged/* packages into ~/.uncaged-nerve/ +# 4. Restart the daemon if it was running +# +# Usage: +# pnpm run link:dev # from monorepo root +# bash scripts/link-dev.sh # or directly + +set -euo pipefail + +NERVE_ROOT="${NERVE_ROOT:-$HOME/.uncaged-nerve}" +REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)" + +# ── Colors ── +bold="\033[1m" +green="\033[32m" +yellow="\033[33m" +reset="\033[0m" + +info() { printf "${bold}${green}✓${reset} %s\n" "$1"; } +warn() { printf "${bold}${yellow}⚠${reset} %s\n" "$1"; } + +# ── 1. Build ── +printf "\n${bold}Building all packages…${reset}\n" +cd "$REPO_ROOT" +pnpm -r run build + +# ── 2. Global link (CLI → nerve command) ── +printf "\n${bold}Linking CLI globally…${reset}\n" +cd "$REPO_ROOT/packages/cli" +pnpm link --global +info "nerve CLI linked globally" + +# ── 3. Link all @uncaged/* packages into workspace ── +if [ ! -d "$NERVE_ROOT" ]; then + warn "$NERVE_ROOT does not exist. Run 'nerve init' first, then re-run this script." + exit 1 +fi + +printf "\n${bold}Linking packages into ${NERVE_ROOT}…${reset}\n" +cd "$NERVE_ROOT" +for pkg_dir in "$REPO_ROOT"/packages/*/; do + pkg_name=$(node -e "console.log(require('${pkg_dir}package.json').name)" 2>/dev/null) || continue + # Only link @uncaged/* packages + if [[ "$pkg_name" == @uncaged/* ]]; then + pnpm link "$pkg_dir" + info "$pkg_name → $(basename "$pkg_dir")" + fi +done + +# ── 4. Restart daemon if running ── +printf "\n${bold}Restarting daemon…${reset}\n" +if nerve daemon status >/dev/null 2>&1; then + nerve daemon restart + info "Daemon restarted with local packages" +else + warn "Daemon not running — skipping restart. Use 'nerve daemon start' when ready." +fi + +printf "\n${bold}${green}Done!${reset} All packages linked to local monorepo build.\n"