- Rename AutoEnhancer to Discoverer with clear element discovery focus - Implement unified enhancement pipeline in Enhancer: * Phase 1: Element Discovery (configurable, respects existing insertr classes) * Phase 2: ID Generation via engine * Phase 3: Content Injection via engine - Add EnhancementConfig and DiscoveryConfig for flexible configuration - Update all method names and references (discoverNode, DiscoveryResult, etc.) - Support both manual class insertion and automatic discovery - Maintain single enhance command interface while providing unified internal pipeline - Update all constructors to use new configuration-based approach This establishes the clean Discoverer + Enhancer architecture discussed, with discovery as configurable first phase and enhancement as unified pipeline.
85 lines
2.3 KiB
Go
85 lines
2.3 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/spf13/viper"
|
|
|
|
"github.com/insertr/insertr/internal/content"
|
|
"github.com/insertr/insertr/internal/db"
|
|
"github.com/insertr/insertr/internal/engine"
|
|
)
|
|
|
|
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
|
|
)
|
|
|
|
func init() {
|
|
enhanceCmd.Flags().StringVarP(&outputDir, "output", "o", "./dist", "Output directory for enhanced files")
|
|
|
|
// Bind flags to viper
|
|
viper.BindPFlag("cli.output", enhanceCmd.Flags().Lookup("output"))
|
|
}
|
|
|
|
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("cli.site_id")
|
|
outputDir := viper.GetString("cli.output")
|
|
|
|
// Create content client
|
|
var client engine.ContentClient
|
|
if apiURL != "" {
|
|
fmt.Printf("🌐 Using content API: %s\n", apiURL)
|
|
client = content.NewHTTPClient(apiURL, apiKey)
|
|
} else if dbPath != "" {
|
|
fmt.Printf("🗄️ Using database: %s\n", dbPath)
|
|
database, err := db.NewDatabase(dbPath)
|
|
if err != nil {
|
|
log.Fatalf("Failed to initialize database: %v", err)
|
|
}
|
|
defer database.Close()
|
|
client = content.NewDatabaseClient(database)
|
|
} else {
|
|
fmt.Printf("🧪 No database or API configured, using mock content\n")
|
|
client = content.NewMockClient()
|
|
}
|
|
|
|
// Create enhancer
|
|
enhancer := content.NewDefaultEnhancer(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)
|
|
}
|