-
Notifications
You must be signed in to change notification settings - Fork 4
/
full.go
71 lines (65 loc) · 1.7 KB
/
full.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
66
67
68
69
70
71
package build
import (
"context"
"fmt"
"path/filepath"
"runtime"
"github.com/pkg/errors"
"projectforge.dev/projectforge/app/lib/telemetry"
"projectforge.dev/projectforge/app/project"
"projectforge.dev/projectforge/app/util"
)
const templatesNS = "templates."
func Full(ctx context.Context, prj *project.Project, logger util.Logger) ([]string, error) {
var logs []string
addLog := func(msg string, args ...any) {
ret := fmt.Sprintf(msg, args...)
logs = append(logs, ret)
}
addLogOutput := func(key string, out string) {
addLog("%s output for [%s]:\n%s", key, prj.Key, out)
}
cmd := func(key string, cmd string, pth string) error {
if key == "" {
key = cmd
}
if pth == "" {
pth = prj.Path
}
exitCode, out, err := telemetry.RunProcessSimple(ctx, cmd, pth, logger)
if err != nil {
return err
}
addLogOutput(key, out)
if exitCode != 0 {
return errors.Errorf(key+" failed with exit code [%d]", exitCode)
}
return nil
}
addLog("building project [%s] in [%s]", prj.Key, prj.Path)
err := cmd(templatesNS+ScriptExtension, filepath.Join("bin", templatesNS+ScriptExtension), "")
if err != nil {
return logs, err
}
err = cmd("", "go mod tidy", "")
if err != nil {
return logs, err
}
err = cmd("", "npm install", filepath.Join(prj.Path, "client"))
if err != nil {
return logs, err
}
err = cmd("client build", filepath.Join("bin", "build", "client."+ScriptExtension), "")
if err != nil {
return logs, err
}
makeCmd := "make build"
if runtime.GOOS == OSWindows {
makeCmd = fmt.Sprintf(`go build -ldflags "-s -w" -trimpath -o build/release/%s.exe`, prj.Executable())
}
err = cmd("project build", makeCmd, "")
if err != nil {
return logs, err
}
return logs, nil
}