-
Notifications
You must be signed in to change notification settings - Fork 0
/
front-builder.go
55 lines (52 loc) · 1.25 KB
/
front-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
package main
import (
"fmt"
"log"
"os"
"time"
"github.com/BrightLocal/FrontBuilder/builder"
"github.com/BrightLocal/FrontBuilder/config"
"github.com/BrightLocal/FrontBuilder/watcher"
)
func main() {
start := time.Now()
fmt.Println("Start build process")
cfg := config.Configure()
frontBuilder := builder.NewBuilder(cfg.Source, cfg.Destination, cfg.IsProduction())
if cfg.HTMLExtension != "" {
frontBuilder.HTMLExtension(cfg.HTMLExtension)
}
if cfg.IndexFile != "" {
frontBuilder.IndexFile(cfg.IndexFile)
}
frontBuilder.ScriptsPrefix(cfg.ScriptsPrefix)
frontBuilder.HTMLPrefix(cfg.HTMLPrefix)
frontBuilder.TypeScriptConfig(cfg.TypeScriptConfig)
if err := frontBuilder.Build(); err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Printf("Build finished: %s\n", time.Since(start))
if cfg.Watch {
buildWatcher, err := watcher.NewBuildWatcher(cfg.Source)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
done := make(chan struct{})
events, err := buildWatcher.Watch()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
go func(e chan struct{}) {
for range e {
log.Println("Rebuild project files")
if err = frontBuilder.Build(); err != nil {
log.Printf("error rebuilding files: %s", err)
}
}
}(events)
<-done
}
}