-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathproject.go
57 lines (49 loc) · 1.47 KB
/
project.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
package checks
import (
"context"
"fmt"
"github.com/samber/lo"
"projectforge.dev/projectforge/app/doctor"
"projectforge.dev/projectforge/app/project"
"projectforge.dev/projectforge/app/util"
)
var (
currentModuleDeps map[string][]string
currentDangerousModules []string
)
func SetModules(deps map[string][]string, dangerous []string) {
currentModuleDeps = deps
currentDangerousModules = dangerous
}
var Project = &doctor.Check{
Key: "project",
Section: "app",
Title: "Project",
Summary: "Verifies the Project Forge project in the working directory",
URL: util.AppURL,
UsedBy: util.AppName,
Fn: checkProject,
Solve: solveProject,
}
func checkProject(_ context.Context, r *doctor.Result, _ util.Logger) *doctor.Result {
p, fs, r := loadRootProject(r)
if len(r.Errors) > 0 {
return r
}
lo.ForEach(project.Validate(p, fs, currentModuleDeps, currentDangerousModules), func(err *project.ValidationError, _ int) {
r = r.WithError(doctor.NewError("config", "[%s]: %s", err.Code, err.Message))
})
return r
}
func solveProject(_ context.Context, r *doctor.Result, _ util.Logger) *doctor.Result {
if r.Errors.Find("missing") != nil {
r.AddSolution("run [projectforge create] in this directory")
}
if r.Errors.Find("invalid") != nil {
r.AddSolution("the project file isn't valid JSON, not sure what you can do")
}
if r.Errors.Find("config") != nil {
r.AddSolution(fmt.Sprintf("use the %s UI to configure your project", util.AppName))
}
return r
}