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:
82
cmd/enhance.go
Normal file
82
cmd/enhance.go
Normal file
@@ -0,0 +1,82 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"github.com/insertr/insertr/internal/content"
|
||||
)
|
||||
|
||||
var enhanceCmd = &cobra.Command{
|
||||
Use: "enhance [input-dir]",
|
||||
Short: "Enhance HTML files by injecting content from database",
|
||||
Long: `Enhance processes HTML files and injects latest content from the database
|
||||
while adding editing capabilities. This is the core build-time enhancement
|
||||
process that transforms static HTML into an editable CMS.`,
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: runEnhance,
|
||||
}
|
||||
|
||||
var (
|
||||
outputDir string
|
||||
mockContent bool
|
||||
)
|
||||
|
||||
func init() {
|
||||
enhanceCmd.Flags().StringVarP(&outputDir, "output", "o", "./dist", "Output directory for enhanced files")
|
||||
enhanceCmd.Flags().BoolVar(&mockContent, "mock", true, "Use mock content for development")
|
||||
|
||||
// Bind flags to viper
|
||||
viper.BindPFlag("build.output", enhanceCmd.Flags().Lookup("output"))
|
||||
viper.BindPFlag("mock_content", enhanceCmd.Flags().Lookup("mock"))
|
||||
}
|
||||
|
||||
func runEnhance(cmd *cobra.Command, args []string) {
|
||||
inputDir := args[0]
|
||||
|
||||
// Validate input directory
|
||||
if _, err := os.Stat(inputDir); os.IsNotExist(err) {
|
||||
log.Fatalf("Input directory does not exist: %s", inputDir)
|
||||
}
|
||||
|
||||
// Get configuration values
|
||||
dbPath := viper.GetString("database.path")
|
||||
apiURL := viper.GetString("api.url")
|
||||
apiKey := viper.GetString("api.key")
|
||||
siteID := viper.GetString("site_id")
|
||||
mockContent := viper.GetBool("mock_content")
|
||||
|
||||
// Create content client
|
||||
var client content.ContentClient
|
||||
if mockContent || (apiURL == "" && dbPath == "") {
|
||||
fmt.Printf("🧪 Using mock content for development\n")
|
||||
client = content.NewMockClient()
|
||||
} else if apiURL != "" {
|
||||
fmt.Printf("🌐 Using content API: %s\n", apiURL)
|
||||
client = content.NewHTTPClient(apiURL, apiKey)
|
||||
} else {
|
||||
fmt.Printf("🗄️ Using database: %s\n", dbPath)
|
||||
// TODO: Implement database client for direct DB access
|
||||
fmt.Printf("⚠️ Direct database access not yet implemented, using mock content\n")
|
||||
client = content.NewMockClient()
|
||||
}
|
||||
|
||||
// Create enhancer
|
||||
enhancer := content.NewEnhancer(client, siteID)
|
||||
|
||||
fmt.Printf("🚀 Starting enhancement process...\n")
|
||||
fmt.Printf("📁 Input: %s\n", inputDir)
|
||||
fmt.Printf("📁 Output: %s\n", outputDir)
|
||||
fmt.Printf("🏷️ Site ID: %s\n\n", siteID)
|
||||
|
||||
// Enhance directory
|
||||
if err := enhancer.EnhanceDirectory(inputDir, outputDir); err != nil {
|
||||
log.Fatalf("Enhancement failed: %v", err)
|
||||
}
|
||||
|
||||
fmt.Printf("\n✅ Enhancement complete! Enhanced files available in: %s\n", outputDir)
|
||||
}
|
||||
Reference in New Issue
Block a user