summaryrefslogtreecommitdiffstats
path: root/internal/builder/importmap.go
diff options
context:
space:
mode:
authorivar <i@oiee.no>2026-04-04 16:34:46 +0200
committerivar <i@oiee.no>2026-04-04 16:34:46 +0200
commita6355e7a6530af3335c4cd8af05f1e9c8b978169 (patch)
treec9d920d1e996ef1c42d3455825731598df6b56c2 /internal/builder/importmap.go
parent8a093aacd162d3fd9f142b53aab9edfa061fd66a (diff)
downloadnebbet.no-a6355e7a6530af3335c4cd8af05f1e9c8b978169.tar.xz
nebbet.no-a6355e7a6530af3335c4cd8af05f1e9c8b978169.zip
.
Diffstat (limited to 'internal/builder/importmap.go')
-rw-r--r--internal/builder/importmap.go58
1 files changed, 0 insertions, 58 deletions
diff --git a/internal/builder/importmap.go b/internal/builder/importmap.go
deleted file mode 100644
index 8445411..0000000
--- a/internal/builder/importmap.go
+++ /dev/null
@@ -1,58 +0,0 @@
-package builder
-
-import (
- "encoding/json"
- "os"
- "path/filepath"
- "strings"
-)
-
-// ImportMap represents a browser importmap.
-type ImportMap struct {
- Imports map[string]string `json:"imports"`
-}
-
-// GenerateImportMap scans libDir for .js files and produces an importmap JSON string.
-//
-// Naming rules:
-// - lib/chart.js → "chart"
-// - lib/icons/index.js → "icons"
-// - lib/utils/helpers.js → "utils/helpers"
-func GenerateImportMap(libDir string) (string, error) {
- imports := make(map[string]string)
-
- if _, err := os.Stat(libDir); os.IsNotExist(err) {
- b, _ := json.MarshalIndent(ImportMap{Imports: imports}, "", " ")
- return string(b), nil
- }
-
- err := filepath.WalkDir(libDir, func(path string, d os.DirEntry, err error) error {
- if err != nil || d.IsDir() || !strings.HasSuffix(path, ".js") {
- return err
- }
- rel, _ := filepath.Rel(libDir, path)
- rel = filepath.ToSlash(rel)
-
- dir := filepath.ToSlash(filepath.Dir(rel))
- base := strings.TrimSuffix(filepath.Base(rel), ".js")
-
- var importName string
- switch {
- case dir == ".":
- importName = base
- case base == "index":
- importName = dir
- default:
- importName = dir + "/" + base
- }
-
- imports[importName] = "/lib/" + rel
- return nil
- })
- if err != nil {
- return "", err
- }
-
- b, err := json.MarshalIndent(ImportMap{Imports: imports}, "", " ")
- return string(b), err
-}