Add Go CLI with container expansion parser and development server

- Implement Go-based CLI for build-time HTML enhancement
- Add container expansion: div.insertr auto-expands to viable children
- Create servedev command with live development workflow
- Add Air configuration for automatic rebuilds and serving
- Enable transition from runtime JS to build-time enhancement approach
This commit is contained in:
2025-09-02 22:58:59 +02:00
parent afd4879cef
commit 0e84af98bc
13 changed files with 1429 additions and 1 deletions

71
insertr-cli/cmd/parse.go Normal file
View File

@@ -0,0 +1,71 @@
package cmd
import (
"fmt"
"os"
"path/filepath"
"github.com/insertr/cli/pkg/parser"
"github.com/spf13/cobra"
)
var parseCmd = &cobra.Command{
Use: "parse [input-dir]",
Short: "Parse HTML files and detect editable elements",
Long: `Parse HTML files in the specified directory and detect elements
with the 'insertr' class. This command analyzes the HTML structure
and reports what editable elements would be enhanced.`,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
inputDir := args[0]
if _, err := os.Stat(inputDir); os.IsNotExist(err) {
fmt.Fprintf(os.Stderr, "Error: Directory %s does not exist\n", inputDir)
os.Exit(1)
}
fmt.Printf("🔍 Parsing HTML files in: %s\n\n", inputDir)
p := parser.New()
result, err := p.ParseDirectory(inputDir)
if err != nil {
fmt.Fprintf(os.Stderr, "Error parsing directory: %v\n", err)
os.Exit(1)
}
printParseResults(result)
},
}
func printParseResults(result *parser.ParseResult) {
fmt.Printf("📊 Parse Results:\n")
fmt.Printf(" Files processed: %d\n", result.Stats.FilesProcessed)
fmt.Printf(" Elements found: %d\n", result.Stats.TotalElements)
fmt.Printf(" Existing IDs: %d\n", result.Stats.ExistingIDs)
fmt.Printf(" Generated IDs: %d\n", result.Stats.GeneratedIDs)
if len(result.Stats.TypeBreakdown) > 0 {
fmt.Printf("\n📝 Content Types:\n")
for contentType, count := range result.Stats.TypeBreakdown {
fmt.Printf(" %s: %d\n", contentType, count)
}
}
if len(result.Elements) > 0 {
fmt.Printf("\n🎯 Found Elements:\n")
for _, element := range result.Elements {
fmt.Printf(" %s <%s> id=%s type=%s\n",
filepath.Base(element.FilePath),
element.Tag,
element.ContentID,
element.Type)
}
}
if len(result.Warnings) > 0 {
fmt.Printf("\n⚠ Warnings:\n")
for _, warning := range result.Warnings {
fmt.Printf(" %s\n", warning)
}
}
}