-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcreate.go
62 lines (52 loc) · 1.51 KB
/
create.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
package action
import (
"context"
"fmt"
"github.com/pkg/errors"
"projectforge.dev/projectforge/app/project"
"projectforge.dev/projectforge/app/project/build"
)
func onCreate(ctx context.Context, params *Params) *Result {
path := params.Cfg.GetStringOpt("path")
if path == "" {
path = "."
}
prj, _ := params.PSvc.Get(params.ProjectKey)
if prj == nil {
prj = project.NewProject(params.ProjectKey, path)
}
prj = projectFromCfg(prj, params.Cfg)
ret := newResult(TypeCreate, prj, params.Cfg, params.Logger)
if params.CLI {
err := cliProject(ctx, prj, params.MSvc.Keys(), params.Logger)
if err != nil {
return ret.WithError(err)
}
}
params.ProjectKey = prj.Key
params.Logger.Info("Saving project...")
err := params.PSvc.Save(prj, params.Logger)
if err != nil {
return ret.WithError(err)
}
params.Logger.Info("Generating project...")
_, err = params.PSvc.Refresh(params.Logger)
if err != nil {
msg := fmt.Sprintf("unable to load newly created project from path [%s]", path)
return errorResult(errors.Wrap(err, msg), TypeCreate, params.Cfg, params.Logger)
}
ctx, pm, err := getPrjAndMods(ctx, params)
if err != nil {
return errorResult(err, TypeCreate, params.Cfg, params.Logger)
}
retS := onGenerate(pm)
ret = ret.Merge(retS)
if ret.HasErrors() {
return ret
}
params.Logger.Info("Building project...")
ret.Modules = nil
fullBuild(ctx, prj, ret, params.Logger)
params.Logger.Info("Your project is ready! Run [bin/dev." + build.ScriptExtension + "] to start your application")
return ret
}