Files
kjol/go/bundler/config.go
2026-07-13 09:17:11 -04:00

97 lines
3.2 KiB
Go

package bundler
import "path/filepath"
// Config tells the bundler where the application tree and the shared kjol web
// tree live. The bundler always runs from the app root, so relative paths are
// resolved against that working directory (absolute paths also work).
//
// When WebDir is empty the bundler runs in single-tree mode: the kit, vendored
// runtime, icons, and styles are expected under AppFrontend (the pre-extraction
// layout). When WebDir points at kjol/web, those come from the shared tree and
// the app supplies only its pages/routes/brand.
type Config struct {
AppFrontend string // app frontend source root (default "frontend")
WebDir string // path to kjol/web; "" => single-tree under AppFrontend
Output string // build output dir (default "wwwroot")
GenGoDir string // dir for generated Go, e.g. public_pages.gen.go (default "internal/handlers")
GenTSDir string // dir for generated TS, e.g. faIcons.ts (default AppFrontend/src/ui/generated)
}
// Package-level resolved configuration. Set once by Configure (called from
// Build / StartDevHMR) and read by every stage. Defaults preserve the original
// single-tree behaviour so nothing breaks before an app opts into the kjol tree.
var (
frontendDir = "frontend"
outputDir = "wwwroot"
webDir = "" // kjol/web; empty => single-tree
genGoDir = "internal/handlers"
genTSDir = filepath.Join("frontend", "src", "ui", "generated")
)
// Configure applies c, filling defaults for empty fields.
func Configure(c Config) {
if c.AppFrontend != "" {
frontendDir = c.AppFrontend
}
if c.Output != "" {
outputDir = c.Output
}
if c.GenGoDir != "" {
genGoDir = c.GenGoDir
}
webDir = c.WebDir
if c.GenTSDir != "" {
genTSDir = c.GenTSDir
} else {
genTSDir = filepath.Join(frontendDir, "src", "ui", "generated")
}
}
// webRoot is the kjol web tree (@kjol/* root), falling back to the app frontend
// in single-tree mode.
func webRoot() string {
if webDir != "" {
return webDir
}
return frontendDir
}
// uikitDir is where the shared Solid component kit lives (@ui/* root).
func uikitDir() string {
if webDir != "" {
return filepath.Join(webDir, "uikit")
}
return filepath.Join(frontendDir, "src", "ui")
}
// iconsDir is the FontAwesome SVG source kit.
func iconsDir() string {
if webDir != "" {
return filepath.Join(webDir, "icons")
}
return filepath.Join(frontendDir, "icons")
}
// vendorDirs lists the vendored-runtime roots in resolution precedence order.
// The kjol runtime comes first so its solid-js wins (a split reactive instance
// silently breaks effect flushing).
func vendorDirs() []string {
if webDir != "" {
return []string{filepath.Join(webDir, "runtime"), filepath.Join(frontendDir, "vendor")}
}
return []string{filepath.Join(frontendDir, "vendor")}
}
// themeCSSPath is the shared Tailwind @theme scaffold prepended to the app's
// brand style.css, or "" in single-tree mode (the app's style.css is complete).
func themeCSSPath() string {
if webDir != "" {
return filepath.Join(webDir, "styles", "theme.css")
}
return ""
}
// faOutPath is where the generated FA registry is written (app-owned).
func faOutPath() string { return filepath.Join(genTSDir, "faIcons.ts") }