-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.go
46 lines (41 loc) · 1.06 KB
/
run.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
package cmds
import (
"fmt"
"github.com/mocheer/nix/cmds/types"
"github.com/mocheer/pluto/pkg/ds/ds_json"
"github.com/mocheer/pluto/pkg/fn"
"github.com/mocheer/pluto/pkg/sys"
"github.com/mocheer/pluto/pkg/ts"
"github.com/urfave/cli/v2"
)
// Run
var Run = &cli.Command{
Name: "run",
Usage: "执行脚本",
Action: func(c *cli.Context) error {
var conf types.PackageJSON
err := ds_json.ReadFile("./package.json", &conf)
if err == nil {
scriptName := c.Args().Get(0)
scriptContent := conf.Scripts[scriptName]
if scriptContent != "" {
scriptContent = fn.Format(scriptContent, ts.Map[any]{
"appName": conf.Name,
"name": conf.Name,
"version": conf.Version,
"execPath": sys.GetCurrentPath(),
})
// 输出具体执行的内容
fmt.Println("Powershell >", scriptContent)
sys.Shell(scriptContent)
// hooks
postScriptContent := conf.Scripts[scriptName+"#post"]
if postScriptContent != "" {
sys.Shell(postScriptContent)
fmt.Println("Powershell >", scriptContent)
}
}
}
return nil
},
}