|
2 | 2 | description: Initialize development environment for git worktree |
3 | 3 | --- |
4 | 4 |
|
5 | | -Make this worktree a fully functional development environment where all tests pass. |
| 5 | +# Setup Development Environment |
6 | 6 |
|
7 | | -You're in a fresh git worktree. Your job is to get it into the same working state as the |
8 | | -main development directory. After you finish, running the full validation suite should |
9 | | -pass - type checking, linting, unit tests, and integration tests. |
| 7 | +Initialize a git worktree as a fully functional development environment with all |
| 8 | +dependencies, configurations, and validation tools. |
10 | 9 |
|
11 | | -To do this, you'll need to: |
| 10 | +## What This Command Does |
12 | 11 |
|
13 | | -- Install whatever dependencies this project needs |
14 | | -- Run any code generation or build steps required |
15 | | -- Copy environment configuration from the parent directory so integration tests can |
16 | | - connect to databases and services |
| 12 | +You're in a fresh git worktree. This command will: |
17 | 13 |
|
18 | | -Look at what kind of project this is and make intelligent decisions about what needs to |
19 | | -happen. If something fails or seems unusual, investigate and adapt. Report what you're |
20 | | -doing as you go so the user understands the progress. |
| 14 | +1. Install all project dependencies |
| 15 | +2. Copy necessary environment configurations |
| 16 | +3. Set up git hooks (husky/pre-commit) |
| 17 | +4. Run any required build/generation steps |
| 18 | +5. Verify everything works correctly |
21 | 19 |
|
22 | | -The success criteria: after you're done, `pnpm pre-push` (or equivalent validation) |
23 | | -passes completely. No failing tests, no type errors, no missing dependencies. |
| 20 | +## Detection Phase |
| 21 | + |
| 22 | +First, I'll analyze the project structure to understand what needs to be set up: |
| 23 | + |
| 24 | +<detect-project-type> |
| 25 | +Checking for project indicators: |
| 26 | +- package.json → Node.js/JavaScript/TypeScript project |
| 27 | +- requirements.txt/Pipfile → Python project |
| 28 | +- Gemfile → Ruby project |
| 29 | +- go.mod → Go project |
| 30 | +- Cargo.toml → Rust project |
| 31 | +- pom.xml/build.gradle → Java project |
| 32 | +- .csproj → .NET project |
| 33 | +</detect-project-type> |
| 34 | + |
| 35 | +<detect-package-manager> |
| 36 | +For Node.js projects, detecting package manager: |
| 37 | +- pnpm-lock.yaml → pnpm |
| 38 | +- yarn.lock → yarn |
| 39 | +- package-lock.json → npm |
| 40 | +- bun.lockb → bun |
| 41 | +</detect-package-manager> |
| 42 | + |
| 43 | +## Setup Steps |
| 44 | + |
| 45 | +### 1. Install Dependencies |
| 46 | + |
| 47 | +```bash |
| 48 | +# Based on detected package manager |
| 49 | +echo "📦 Installing dependencies..." |
| 50 | + |
| 51 | +# Node.js |
| 52 | +if [ -f "package.json" ]; then |
| 53 | + if [ -f "pnpm-lock.yaml" ]; then |
| 54 | + pnpm install |
| 55 | + elif [ -f "yarn.lock" ]; then |
| 56 | + yarn install |
| 57 | + elif [ -f "bun.lockb" ]; then |
| 58 | + bun install |
| 59 | + else |
| 60 | + npm install |
| 61 | + fi |
| 62 | +fi |
| 63 | + |
| 64 | +# Python |
| 65 | +if [ -f "requirements.txt" ]; then |
| 66 | + pip install -r requirements.txt |
| 67 | +elif [ -f "Pipfile" ]; then |
| 68 | + pipenv install |
| 69 | +fi |
| 70 | + |
| 71 | +# Add other language-specific installations as needed |
| 72 | +``` |
| 73 | + |
| 74 | +### 2. Copy Environment Configuration |
| 75 | + |
| 76 | +```bash |
| 77 | +echo "🔐 Setting up environment configuration..." |
| 78 | + |
| 79 | +# Get the main working directory (parent of .gitworktrees) |
| 80 | +MAIN_DIR=$(git worktree list --porcelain | grep "^worktree" | head -1 | cut -d' ' -f2) |
| 81 | + |
| 82 | +# Copy environment files if they exist |
| 83 | +ENV_FILES=(.env .env.local .env.development .env.test) |
| 84 | +for env_file in "${ENV_FILES[@]}"; do |
| 85 | + if [ -f "$MAIN_DIR/$env_file" ]; then |
| 86 | + echo " Copying $env_file from main directory..." |
| 87 | + cp "$MAIN_DIR/$env_file" "./$env_file" |
| 88 | + fi |
| 89 | +done |
| 90 | + |
| 91 | +# Copy any other config files that aren't in version control |
| 92 | +CONFIG_FILES=(.secrets.json local.config.js config.local.json) |
| 93 | +for config_file in "${CONFIG_FILES[@]}"; do |
| 94 | + if [ -f "$MAIN_DIR/$config_file" ]; then |
| 95 | + echo " Copying $config_file from main directory..." |
| 96 | + cp "$MAIN_DIR/$config_file" "./$config_file" |
| 97 | + fi |
| 98 | +done |
| 99 | +``` |
| 100 | + |
| 101 | +### 3. Setup Git Hooks |
| 102 | + |
| 103 | +```bash |
| 104 | +echo "🪝 Setting up git hooks..." |
| 105 | + |
| 106 | +# Get the main working directory |
| 107 | +MAIN_DIR=$(git worktree list --porcelain | grep "^worktree" | head -1 | cut -d' ' -f2) |
| 108 | + |
| 109 | +# Husky (most common in JS/TS projects) |
| 110 | +if [ -d "$MAIN_DIR/.husky" ] || [ -d ".husky" ]; then |
| 111 | + echo " Installing Husky hooks..." |
| 112 | + npx husky install |
| 113 | + echo " ✓ Husky hooks installed" |
| 114 | +fi |
| 115 | + |
| 116 | +# Pre-commit (Python and multi-language projects) |
| 117 | +if [ -f "$MAIN_DIR/.pre-commit-config.yaml" ] || [ -f ".pre-commit-config.yaml" ]; then |
| 118 | + echo " Installing pre-commit hooks..." |
| 119 | + if command -v pre-commit >/dev/null 2>&1; then |
| 120 | + pre-commit install |
| 121 | + echo " ✓ Pre-commit hooks installed" |
| 122 | + else |
| 123 | + echo " ⚠️ pre-commit not installed, run: pip install pre-commit" |
| 124 | + fi |
| 125 | +fi |
| 126 | + |
| 127 | +# Simple git hooks (legacy projects) |
| 128 | +if [ -d "$MAIN_DIR/.git/hooks" ]; then |
| 129 | + # Check for custom hooks that need copying |
| 130 | + for hook in pre-commit pre-push commit-msg; do |
| 131 | + if [ -f "$MAIN_DIR/.git/hooks/$hook" ] && [ ! -f ".git/hooks/$hook" ]; then |
| 132 | + echo " Copying $hook hook..." |
| 133 | + cp "$MAIN_DIR/.git/hooks/$hook" ".git/hooks/$hook" |
| 134 | + chmod +x ".git/hooks/$hook" |
| 135 | + fi |
| 136 | + done |
| 137 | +fi |
| 138 | + |
| 139 | +echo " ✓ Git hooks configured for this worktree" |
| 140 | +``` |
| 141 | + |
| 142 | +### 4. Run Build/Generation Steps |
| 143 | + |
| 144 | +```bash |
| 145 | +echo "🏗️ Running build and generation steps..." |
| 146 | + |
| 147 | +# Check for code generation needs |
| 148 | +if [ -f "package.json" ]; then |
| 149 | + # Prisma generation |
| 150 | + if grep -q "@prisma/client" package.json; then |
| 151 | + echo " Generating Prisma client..." |
| 152 | + npx prisma generate |
| 153 | + fi |
| 154 | + |
| 155 | + # GraphQL codegen |
| 156 | + if [ -f "codegen.yml" ] || [ -f "codegen.ts" ]; then |
| 157 | + echo " Running GraphQL codegen..." |
| 158 | + npm run codegen || yarn codegen || npx graphql-codegen |
| 159 | + fi |
| 160 | + |
| 161 | + # Build if needed for development |
| 162 | + if grep -q '"prepare"' package.json; then |
| 163 | + echo " Running prepare script..." |
| 164 | + npm run prepare || yarn prepare |
| 165 | + fi |
| 166 | + |
| 167 | + # TypeScript declarations |
| 168 | + if [ -f "tsconfig.json" ] && grep -q '"declaration"' tsconfig.json; then |
| 169 | + echo " Building TypeScript declarations..." |
| 170 | + npx tsc --emitDeclarationOnly || true |
| 171 | + fi |
| 172 | +fi |
| 173 | +``` |
| 174 | + |
| 175 | +### 5. Verify Setup |
| 176 | + |
| 177 | +```bash |
| 178 | +echo "🔍 Verifying environment setup..." |
| 179 | + |
| 180 | +# Run git hooks to verify everything works |
| 181 | +echo "Testing git hooks..." |
| 182 | +if [ -d ".husky" ]; then |
| 183 | + echo " Running Husky pre-commit hooks..." |
| 184 | + npx husky run pre-commit && echo " ✓ Husky hooks working" || echo " ⚠️ Some checks failed (fixing...)" |
| 185 | +elif [ -f ".pre-commit-config.yaml" ]; then |
| 186 | + echo " Running pre-commit hooks..." |
| 187 | + pre-commit run --all-files && echo " ✓ Pre-commit hooks working" || echo " ⚠️ Some checks failed (fixing...)" |
| 188 | +else |
| 189 | + echo " ⚠️ No git hooks configured - consider adding husky or pre-commit" |
| 190 | +fi |
| 191 | + |
| 192 | +# Quick sanity checks |
| 193 | +if [ -f "package.json" ]; then |
| 194 | + echo "Testing build..." |
| 195 | + npm run build 2>/dev/null || yarn build 2>/dev/null || echo " ⚠️ No build script" |
| 196 | +fi |
| 197 | + |
| 198 | +# Check environment files |
| 199 | +if [ -f ".env" ]; then |
| 200 | + echo "✅ Environment configuration present" |
| 201 | +fi |
| 202 | + |
| 203 | +echo "" |
| 204 | +echo "✅ Environment setup complete!" |
| 205 | +echo "" |
| 206 | +echo "This worktree is now ready for development:" |
| 207 | +echo " - All dependencies installed" |
| 208 | +echo " - Environment configured" |
| 209 | +echo " - Git hooks installed and working" |
| 210 | +echo " - Ready for development" |
| 211 | +echo "" |
| 212 | +echo "Your git hooks will handle all validation when you commit." |
| 213 | +``` |
| 214 | + |
| 215 | +## Error Handling |
| 216 | + |
| 217 | +If any step fails, I'll: |
| 218 | + |
| 219 | +1. Identify what went wrong |
| 220 | +2. Attempt to fix common issues automatically |
| 221 | +3. Provide clear guidance on manual fixes if needed |
| 222 | +4. Continue with other steps when safe to do so |
| 223 | + |
| 224 | +## Success Criteria |
| 225 | + |
| 226 | +After setup completes: |
| 227 | + |
| 228 | +- All dependencies are installed |
| 229 | +- Environment variables are configured |
| 230 | +- Git hooks are properly installed and working |
| 231 | +- The worktree is ready for development |
| 232 | + |
| 233 | +The goal is a worktree that's immediately productive - no missing dependencies, no |
| 234 | +failing tests, no configuration issues. Your existing git hooks (husky/pre-commit) |
| 235 | +handle all validation automatically when you commit. |
0 commit comments