-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathjs.go
37 lines (30 loc) · 858 Bytes
/
js.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
package main
import (
"fmt"
"path/filepath"
"strings"
"github.com/goexl/gfx"
)
func (p *plugin) js(source string, labels []string) (err error) {
modulePath := filepath.Join(source, jsModuleFilename)
if _, exists := gfx.Exists(modulePath); !exists {
return
}
dependencies := make([]jsonElement, 0, len(labels)+1)
dependencies = append(dependencies, jsonElement{
path: `version`,
value: p.Version,
})
// 处理依赖模块
if err = p.each(labels, p.jsModules(dependencies)); nil != err {
return
}
err = p.json(modulePath, dependencies...)
return
}
func (p *plugin) jsModules(dependencies []jsonElement) moduleFunc {
return func(module *module) {
_module := strings.ReplaceAll(module.Name, `.`, `\.`)
dependencies = append(dependencies, jsonElement{path: fmt.Sprintf("dependencies.%s", _module), value: module.Version})
}
}