Files
insertr/justfile
Joakim e28000fd33 refactor: implement unified binary architecture
🏗️ **Major Architecture Refactoring: Separate CLI + Server → Unified Binary**

**Key Changes:**
 **Unified Binary**: Single 'insertr' binary with subcommands (enhance, serve)
 **Preserved Database Architecture**: Maintained sophisticated sqlc multi-DB setup
 **Smart Configuration**: Viper + YAML config with CLI flag precedence
 **Updated Build System**: Unified justfile, Air, and npm scripts

**Command Structure:**
- `insertr enhance [input-dir]` - Build-time content injection
- `insertr serve` - HTTP API server (dev + production modes)
- `insertr --config insertr.yaml` - YAML configuration support

**Architecture Benefits:**
- **Shared Database Layer**: Single source of truth for content models
- **Flexible Workflows**: Local DB for dev, remote API for production
- **Simple Deployment**: One binary for all use cases
- **Better UX**: Consistent configuration across build and runtime

**Preserved Features:**
- Multi-database support (SQLite + PostgreSQL)
- sqlc code generation and type safety
- Version control system with rollback
- Professional API endpoints
- Content enhancement pipeline

**Development Workflow:**
- `just dev` - Full-stack development (API server + demo site)
- `just serve` - API server only
- `just enhance` - Build-time content injection
- `air` - Hot reload unified binary

**Migration:** Consolidated insertr-cli/ and insertr-server/ → unified root structure
2025-09-09 00:39:35 +02:00

186 lines
5.5 KiB
Makefile

# Insertr Development Commands
# Use `just <command>` to run any of these tasks
# Default recipe - show available commands
default:
@just --list
# Install all dependencies (root + lib)
install:
npm install
cd lib && npm install
# Start full-stack development (primary workflow)
dev: build-lib build
#!/usr/bin/env bash
echo "🚀 Starting Full-Stack Insertr Development..."
echo "================================================"
echo ""
echo "📝 Unified logs below (API server + Demo site):"
echo "🔌 [SERVER] = API server logs"
echo "🌐 [DEMO] = Demo site logs"
echo ""
# Function to cleanup background processes
cleanup() {
echo ""
echo "🛑 Shutting down servers..."
kill $SERVER_PID $DEMO_PID 2>/dev/null || true
wait $SERVER_PID $DEMO_PID 2>/dev/null || true
echo "✅ Shutdown complete"
exit 0
}
trap cleanup SIGINT SIGTERM
# Start API server with prefixed output
echo "🔌 Starting API server (localhost:8080)..."
./insertr serve --dev-mode --db ./dev.db 2>&1 | sed 's/^/🔌 [SERVER] /' &
SERVER_PID=$!
# Wait for server startup
echo "⏳ Waiting for API server startup..."
sleep 3
# Check server health
if curl -s http://localhost:8080/health > /dev/null 2>&1; then
echo "✅ API server ready!"
else
echo "⚠️ API server may not be ready yet"
fi
echo ""
echo "🌐 Starting demo site (localhost:3000)..."
echo "📝 Full-stack ready - edit content with real-time persistence!"
echo ""
# Start demo site with prefixed output (this will block) - use local installation
cd {{justfile_directory()}} && npx --prefer-offline live-server demo-site --port=3000 --host=localhost --open=/index.html 2>&1 | sed 's/^/🌐 [DEMO] /' &
DEMO_PID=$!
# Wait for both processes
wait $DEMO_PID $SERVER_PID
# Demo site only (for specific use cases)
demo-only:
@echo "🌐 Starting demo site only (no API server)"
@echo "⚠️ Content edits will not persist without API server"
npx --prefer-offline live-server demo-site --port=3000 --host=localhost --open=/index.html
# Start development server for about page
dev-about: build-lib build
#!/usr/bin/env bash
echo "🚀 Starting full-stack development (about page)..."
./insertr serve --dev-mode --db ./dev.db &
SERVER_PID=$!
sleep 3
npx --prefer-offline live-server demo-site --port=3000 --host=localhost --open=/about.html
kill $SERVER_PID 2>/dev/null || true
# Check project status and validate setup
check:
npm run check
# Show demo instructions
demo:
npm run demo
# Build the entire project (library + unified binary)
build:
npm run build
# Build only the JavaScript library
build-lib:
npm run build:lib
# Watch library files for changes (auto-rebuild)
watch:
cd lib && npm run dev
# Start Air hot-reload for unified binary development
air:
air
# Build unified binary only
build-insertr:
go build -o insertr .
# Run insertr help
help:
./insertr --help
# Parse demo site with CLI
parse:
./insertr enhance demo-site/ --output ./dist --mock
# Enhance demo site (build-time content injection)
enhance input="demo-site" output="dist":
./insertr enhance {{input}} --output {{output}} --mock
# === Content API Server Commands ===
# Start content API server (default port 8080)
serve port="8080":
./insertr serve --port {{port}} --dev-mode --db ./dev.db
# Start API server in production mode
serve-prod port="8080" db="./insertr.db":
./insertr serve --port {{port}} --db {{db}}
# Start API server with auto-restart on Go file changes
serve-dev port="8080":
find . -name "*.go" | entr -r ./insertr serve --port {{port}} --dev-mode --db ./dev.db
# Check API server health
health port="8080":
@echo "🔍 Checking API server health..."
@curl -s http://localhost:{{port}}/health | jq . || echo "❌ Server not responding at localhost:{{port}}"
# Clean all build artifacts
clean:
rm -rf lib/dist
rm -rf insertr
rm -rf tmp
rm -rf dist
rm -rf node_modules
rm -rf lib/node_modules
rm -f dev.db
rm -f insertr.db
# Lint code (placeholder for now)
lint:
npm run lint
# Run tests (placeholder for now)
test:
npm run test
# Development workflow: install deps, build lib, start dev server
dev-setup: install build-lib dev
# Production workflow: install deps, build everything
prod-build: install build
# Show project status
status:
@echo "🏗️ Insertr Project Status"
@echo "========================="
@echo "📁 Root files:"
@ls -la package.json justfile go.mod insertr.yaml 2>/dev/null || echo " Missing files"
@echo "\n📚 Library files:"
@ls -la lib/package.json lib/src lib/dist 2>/dev/null || echo " Missing library components"
@echo "\n🔧 Unified binary:"
@ls -la insertr main.go cmd/ internal/ 2>/dev/null || echo " Missing unified binary components"
@echo "\n🌐 Demo site:"
@ls -la demo-site/index.html demo-site/about.html 2>/dev/null || echo " Missing demo files"
@echo ""
@echo "🚀 Development Commands:"
@echo " just dev - Full-stack development (recommended)"
@echo " just demo-only - Demo site only (no persistence)"
@echo " just serve - API server only (localhost:8080)"
@echo " just enhance - Build-time content injection"
@echo ""
@echo "🔍 Check server: just health"
# Generate sqlc code (for database schema changes)
sqlc:
sqlc generate