← back to Claude Webdev Accelerator

scripts/new-project.sh

52 lines

#!/bin/bash
# Scaffold a new gitified client project that honors the house rules.
# Usage: scripts/new-project.sh <slug> [port]
set -euo pipefail
SLUG="${1:?usage: new-project.sh <slug> [port]}"
PORT="${2:-0}"   # 0 = let the OS pick a free port at runtime
ROOT="$HOME/Projects/$SLUG"
if [ -e "$ROOT/.git" ]; then echo "refusing: $ROOT already a git repo (sacred)"; exit 2; fi
mkdir -p "$ROOT/public"
TPL="$(cd "$(dirname "$0")/.." && pwd)/templates"

# .gitignore per the standing rule
cat > "$ROOT/.gitignore" <<'EOF'
node_modules/
.env*
tmp/
*.log
.DS_Store
dist/
build/
.next/
EOF

# seed the brief
cat > "$ROOT/BRIEF.md" <<EOF
# $SLUG — brief
- Client:
- Outcome / "high value":
- Constraints (brand, domain, deadline):
- Reference / competitor URLs:
EOF

# copy starter server + grid if present, else drop minimal ones
if [ -d "$TPL" ]; then cp -R "$TPL/." "$ROOT/" 2>/dev/null || true; fi
[ -f "$ROOT/server.js" ] || cat > "$ROOT/server.js" <<'EOF'
// minimal static server; PORT=0 picks a free port. Replace with the real build.
const http=require('http'),fs=require('fs'),path=require('path');
const PORT=parseInt(process.env.PORT||'0',10);
http.createServer((req,res)=>{const f=req.url==='/'?'index.html':req.url.split('?')[0].replace(/^\//,'');
  const fp=path.join(__dirname,'public',path.basename(f));
  if(fs.existsSync(fp)){res.writeHead(200,{'Content-Type':f.endsWith('.html')?'text/html':'text/plain'});return res.end(fs.readFileSync(fp));}
  res.writeHead(404);res.end('not found');
}).listen(PORT,function(){console.log('['+require('path').basename(__dirname)+'] http://localhost:'+this.address().port);});
EOF
[ -f "$ROOT/public/index.html" ] || printf '<!doctype html><meta charset=utf-8><title>%s</title><h1>%s — scaffolded</h1><p>Wire the grid (sort + density) and content here.</p>\n' "$SLUG" "$SLUG" > "$ROOT/public/index.html"

cd "$ROOT"
git init -q
git add -A
git -c user.email=steve@designerwallcoverings.com -c user.name=Steve commit -q -m "initial scaffold ($SLUG) via web-dev accelerator"
echo "scaffolded $ROOT (port $PORT) — next: fill BRIEF.md, then build per ACCELERATOR.md"