git commit -m "feat: initial release of Strata framework v0.1.0
- Static compiler with STRC pattern (Static Template Resolution with
Compartmentalized Layers)
- Template syntax: { } interpolation, { s-for }, { s-if/s-elif/s-else
}
- File types: .strata, .compiler.sts, .service.sts, .api.sts, .sts,
.scss
- CLI tools: strata dev, strata build, strata g (generators)
- create-strata scaffolding CLI with Pokemon API example
- Dev server with WebSocket HMR (Hot Module Replacement)
- Documentation: README, ARCHITECTURE, CHANGELOG, CONTRIBUTING,
LICENSE
This commit is contained in:
96
compiler/cmd/strata/dev.go
Normal file
96
compiler/cmd/strata/dev.go
Normal file
@@ -0,0 +1,96 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
||||
"github.com/CarGDev/strata/internal/server"
|
||||
"github.com/CarGDev/strata/internal/watcher"
|
||||
)
|
||||
|
||||
func startDevServer(port int, open bool) {
|
||||
// Get current working directory
|
||||
cwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to get working directory: %v", err)
|
||||
}
|
||||
|
||||
// Check if this is a Strata project
|
||||
configPath := filepath.Join(cwd, "strataconfig.ts")
|
||||
if _, err := os.Stat(configPath); os.IsNotExist(err) {
|
||||
log.Fatal("Not a Strata project. strataconfig.ts not found.")
|
||||
}
|
||||
|
||||
// Create dev server
|
||||
devServer := server.NewDevServer(port, cwd)
|
||||
|
||||
// Create file watcher
|
||||
srcDir := filepath.Join(cwd, "src")
|
||||
fileWatcher, err := watcher.New(srcDir, func(event watcher.ChangeEvent) {
|
||||
fmt.Printf(" Changed: %s\n", event.Path)
|
||||
|
||||
// Rebuild the project
|
||||
if err := devServer.Rebuild(); err != nil {
|
||||
fmt.Printf(" Rebuild error: %v\n", err)
|
||||
}
|
||||
|
||||
// Determine change type for HMR
|
||||
changeType := "reload"
|
||||
switch event.Type {
|
||||
case watcher.FileTypeSCSS:
|
||||
changeType = "css"
|
||||
case watcher.FileTypeStrata:
|
||||
changeType = "component"
|
||||
case watcher.FileTypeConfig:
|
||||
changeType = "reload"
|
||||
}
|
||||
|
||||
devServer.NotifyChange(changeType, event.Path)
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to create watcher: %v", err)
|
||||
}
|
||||
|
||||
// Start watcher in background
|
||||
go func() {
|
||||
if err := fileWatcher.Start(); err != nil {
|
||||
log.Printf("Watcher error: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
// Open browser if requested
|
||||
if open {
|
||||
openBrowser(fmt.Sprintf("http://localhost:%d", port))
|
||||
}
|
||||
|
||||
// Start server (blocks)
|
||||
if err := devServer.Start(); err != nil {
|
||||
log.Fatalf("Server error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func openBrowser(url string) {
|
||||
var cmd *exec.Cmd
|
||||
|
||||
switch runtime.GOOS {
|
||||
case "darwin":
|
||||
cmd = exec.Command("open", url)
|
||||
case "linux":
|
||||
cmd = exec.Command("xdg-open", url)
|
||||
case "windows":
|
||||
cmd = exec.Command("cmd", "/c", "start", url)
|
||||
default:
|
||||
fmt.Printf(" Open manually: %s\n", url)
|
||||
return
|
||||
}
|
||||
|
||||
if err := cmd.Start(); err != nil {
|
||||
fmt.Printf(" Could not open browser: %v\n", err)
|
||||
fmt.Printf(" Open manually: %s\n", url)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user