mirror of
https://github.com/R0m1k3/Loki.git
synced 2026-10-11 17:26:57 +02:00
- module github.com/R0m1k3/Loki, cmd/loki, internal/loki (package loki) - LOKI_HOME, LOKI_MODEL_DIRS, LOKI_SERVICE, LOKI_DL_CONNS ; /etc/loki ; units loki-engine / loki-ui ; binaire et aide CLI - updateRepo pointe sur R0m1k3/Loki (l'auto-update ne tirera plus les binaires AJEAN amont) Conservé à l'identique : le domaine ajean.link (service de tunnel amont), les littéraux de migration 0.7.x (migrate_07.go), RELEASE_NOTES.md et LICENSE (historique et licence de l'amont). go build/vet/test : verts.
81 lines
2.2 KiB
Go
81 lines
2.2 KiB
Go
// assemble-ui reconstruit internal/loki/ui/index.html à partir des sources
|
|
// internal/loki/ui/src/ (remplace l'ancien ui/assemble.ps1 — multiplateforme).
|
|
//
|
|
// index.html est un fichier GÉNÉRÉ mais committé : go:embed (web_server.go) et
|
|
// loki-app/build-server-ui.ps1 le lisent tel quel. Pour modifier l'UI : éditer
|
|
// ui/src/ (index.tmpl.html, styles.css, js/NN-*.js concaténés dans l'ordre
|
|
// alphabétique, tout en scope global) puis relancer :
|
|
//
|
|
// go generate ./internal/loki (ou : go run ./tools/assemble-ui)
|
|
//
|
|
// Les marqueurs @@CSS@@ / @@JS@@ du template sont remplacés avec LEUR fin de
|
|
// ligne (LF ou CRLF) ; chaque source apporte ses propres fins de ligne.
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"regexp"
|
|
"sort"
|
|
"strings"
|
|
)
|
|
|
|
func main() {
|
|
uiDir := "internal/loki/ui"
|
|
if len(os.Args) > 1 {
|
|
uiDir = os.Args[1]
|
|
}
|
|
if err := run(uiDir); err != nil {
|
|
fmt.Fprintln(os.Stderr, "assemble-ui:", err)
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
func run(uiDir string) error {
|
|
srcDir := filepath.Join(uiDir, "src")
|
|
tmpl, err := os.ReadFile(filepath.Join(srcDir, "index.tmpl.html"))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
css, err := os.ReadFile(filepath.Join(srcDir, "styles.css"))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
entries, err := os.ReadDir(filepath.Join(srcDir, "js"))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
var names []string
|
|
for _, e := range entries {
|
|
if strings.HasSuffix(e.Name(), ".js") {
|
|
names = append(names, e.Name())
|
|
}
|
|
}
|
|
sort.Strings(names)
|
|
var js []byte
|
|
for _, n := range names {
|
|
b, err := os.ReadFile(filepath.Join(srcDir, "js", n))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
js = append(js, b...)
|
|
}
|
|
|
|
html := string(tmpl)
|
|
for marker, content := range map[string]string{"@@CSS@@": string(css), "@@JS@@": string(js)} {
|
|
re := regexp.MustCompile(regexp.QuoteMeta(marker) + "\r?\n")
|
|
if !re.MatchString(html) {
|
|
return fmt.Errorf("marqueur %s introuvable dans index.tmpl.html", marker)
|
|
}
|
|
html = re.ReplaceAllStringFunc(html, func(string) string { return content })
|
|
}
|
|
|
|
dst := filepath.Join(uiDir, "index.html")
|
|
if err := os.WriteFile(dst, []byte(html), 0o644); err != nil {
|
|
return err
|
|
}
|
|
fmt.Printf("OK -> %s (%d octets)\n", dst, len(html))
|
|
return nil
|
|
}
|