-
Notifications
You must be signed in to change notification settings - Fork 1
/
module_engine.go
59 lines (52 loc) · 1.05 KB
/
module_engine.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
package engine
import (
_ "embed"
"github.com/dop251/goja"
"slices"
)
//go:embed module_engine.d.ts
var engineDefine []byte
type EngineModule struct {
}
func (e EngineModule) ExportsWithEngine(engine *Engine) map[string]any {
m := make(map[string]any)
m["Engine"] = engine.ToConstructor(func(v []goja.Value) (any, error) {
var r *Engine
if len(v) == 0 {
r = Get()
} else {
ex := v[0].ToBoolean()
ms := v[1].Export().([]string)
if ex {
m := Mods()
var mm []Mod
for _, module := range m {
if !slices.Contains(ms, module.Name()) {
mm = append(mm, module)
}
}
r = NewRawEngine(mm...)
} else {
m := Mods()
var mm []Mod
for _, module := range m {
if slices.Contains(ms, module.Name()) {
mm = append(mm, module)
}
}
r = NewRawEngine(mm...)
}
}
return r, nil
})
return m
}
func (e EngineModule) Identity() string {
return "go/engine"
}
func (e EngineModule) Exports() map[string]any {
return nil
}
func (e EngineModule) TypeDefine() []byte {
return engineDefine
}