-
-
Notifications
You must be signed in to change notification settings - Fork 45
/
builder.go
77 lines (62 loc) · 1.72 KB
/
builder.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
72
73
74
75
76
77
package build
import (
"sync"
"github.com/eko/monday/pkg/build/command"
"github.com/eko/monday/pkg/config"
"github.com/eko/monday/pkg/helper"
"github.com/eko/monday/pkg/ui"
)
// Builder represents a local application builder
type Builder interface {
BuildAll()
Build(application *config.Application)
}
type builder struct {
projectName string
applications []*config.Application
view ui.View
}
// NewBuilder instanciates a new builder instance
func NewBuilder(view ui.View, project *config.Project) *builder {
return &builder{
projectName: project.Name,
applications: project.Applications,
view: view,
}
}
// BuildAll builds all local applications in separated goroutines
func (b *builder) BuildAll() {
var wg = sync.WaitGroup{}
for _, application := range b.applications {
wg.Add(1)
go func(application *config.Application) {
defer wg.Done()
b.Build(application)
}(application)
}
wg.Wait()
}
// Build builds the application
func (b *builder) Build(application *config.Application) {
if application.Build == nil {
return
}
if err := helper.CheckPathExists(application.GetPath()); err != nil {
b.view.Writef("❌ %s\n", err.Error())
return
}
var build = application.Build
var err error
switch build.Type {
case command.BuilderType:
b.view.Writef("⚙️ Building local app '%s' via %s...\n", application.Name, build.Type)
err = command.Build(application, b.view)
default:
b.view.Writef("❌ Unknown build type '%s' for application '%s'\n", build.Type, application.Name)
}
if err != nil {
b.view.Writef("❌ Error while building application '%s': %v\n", application.Name, err)
return
}
b.view.Writef("✅ Build of application '%s' complete!\n", application.Name)
}