-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtranspile.go
65 lines (57 loc) · 1.31 KB
/
transpile.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package mermaidlive
import (
"log"
"os"
"path/filepath"
"github.com/evanw/esbuild/pkg/api"
)
func Refresh() {
log.Printf("transpiling & copying: %v, %v", staticFilesToCopy(), esbuildEntrypoints())
transpile()
copyStatic()
}
func copyStatic() {
for _, f := range staticFilesToCopy() {
text, err := os.ReadFile(filepath.Join(uiSrc, f))
crashOnError(err)
os.WriteFile(filepath.Join(dist, f), text, 0644)
}
}
func transpile() {
result := api.Build(api.BuildOptions{
EntryPoints: esbuildEntrypoints(),
Bundle: true,
Outdir: dist,
MinifySyntax: false,
MinifyWhitespace: false,
MinifyIdentifiers: false,
Sourcemap: api.SourceMapInline,
Engines: []api.Engine{
{Name: api.EngineChrome, Version: "58"},
{Name: api.EngineFirefox, Version: "57"},
{Name: api.EngineSafari, Version: "11"},
{Name: api.EngineEdge, Version: "16"},
},
Write: true,
})
handleErrors(result.Errors)
}
func staticFilesToCopy() []string {
var res = []string{
"index.html",
"index.css",
}
if ClusterObservabilityEnabled {
res = append(res, "cluster.html")
}
return res
}
func esbuildEntrypoints() []string {
var res = []string{
filepath.Join(uiSrc, "index.ts"),
}
if ClusterObservabilityEnabled {
res = append(res, filepath.Join(uiSrc, "cluster.ts"))
}
return res
}