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
This commit is contained in:
@@ -1,15 +1,15 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Build script for Insertr library and CLI integration
|
||||
* This ensures the CLI always has the latest library version embedded
|
||||
* Build script for Insertr unified binary
|
||||
* This ensures the unified binary always has the latest library version embedded
|
||||
*/
|
||||
|
||||
import { execSync } from 'child_process';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
console.log('🔨 Building Insertr library and CLI...\n');
|
||||
console.log('🔨 Building Insertr unified binary...\n');
|
||||
|
||||
// 1. Build the library
|
||||
console.log('📦 Building JavaScript library...');
|
||||
@@ -21,10 +21,10 @@ try {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// 2. Copy built library to CLI assets
|
||||
console.log('📁 Copying library to CLI assets...');
|
||||
// 2. Copy built library to unified binary assets
|
||||
console.log('📁 Copying library to unified binary assets...');
|
||||
const srcDir = './lib/dist';
|
||||
const destDir = './insertr-cli/pkg/content/assets';
|
||||
const destDir = './internal/content/assets';
|
||||
|
||||
// Ensure destination directory exists
|
||||
fs.mkdirSync(destDir, { recursive: true });
|
||||
@@ -40,32 +40,21 @@ files.forEach(file => {
|
||||
|
||||
console.log('📁 Assets copied successfully\n');
|
||||
|
||||
// 3. Build the CLI
|
||||
console.log('🔧 Building Go CLI...');
|
||||
// 3. Build the unified binary
|
||||
console.log('🔧 Building unified Insertr binary...');
|
||||
try {
|
||||
execSync('go build -o insertr', { cwd: './insertr-cli', stdio: 'inherit' });
|
||||
console.log('✅ CLI built successfully\n');
|
||||
execSync('go build -o insertr .', { stdio: 'inherit' });
|
||||
console.log('✅ Unified binary built successfully\n');
|
||||
} catch (error) {
|
||||
console.error('❌ CLI build failed:', error.message);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// 4. Build the API Server
|
||||
console.log('🔌 Building API Server...');
|
||||
try {
|
||||
execSync('go build -o insertr-server ./cmd/server', { cwd: './insertr-server', stdio: 'inherit' });
|
||||
console.log('✅ API Server built successfully\n');
|
||||
} catch (error) {
|
||||
console.error('❌ API Server build failed:', error.message);
|
||||
console.error('❌ Unified binary build failed:', error.message);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log('🎉 Build complete!\n');
|
||||
console.log('📋 What was built:');
|
||||
console.log(' • JavaScript library (lib/dist/)');
|
||||
console.log(' • Go CLI with embedded library (insertr-cli/insertr)');
|
||||
console.log(' • Content API server (insertr-server/insertr-server)');
|
||||
console.log(' • Unified Insertr binary with embedded library (./insertr)');
|
||||
console.log('\n🚀 Ready to use:');
|
||||
console.log(' just dev # Full-stack development');
|
||||
console.log(' just server # API server only');
|
||||
console.log(' cd insertr-cli && ./insertr --help # CLI tools');
|
||||
console.log(' just serve # API server only');
|
||||
console.log(' ./insertr --help # See all commands');
|
||||
Reference in New Issue
Block a user