-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.go
49 lines (42 loc) · 1.41 KB
/
build.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
package nodestart
import (
"github.com/paketo-buildpacks/libnodejs"
"github.com/paketo-buildpacks/libreload-packit"
"github.com/paketo-buildpacks/packit/v2"
"github.com/paketo-buildpacks/packit/v2/scribe"
)
func Build(logger scribe.Emitter, reloader Reloader) packit.BuildFunc {
return func(context packit.BuildContext) (packit.BuildResult, error) {
logger.Title("%s %s", context.BuildpackInfo.Name, context.BuildpackInfo.Version)
file, err := libnodejs.FindNodeApplication(context.WorkingDir)
if err != nil {
return packit.BuildResult{}, err
}
originalProcess := packit.Process{
Type: "web",
Command: "node",
Args: []string{file},
Default: true,
Direct: true,
}
var processes []packit.Process
if shouldEnableReload, err := reloader.ShouldEnableLiveReload(); err != nil {
return packit.BuildResult{}, err
} else if shouldEnableReload {
nonReloadableProcess, reloadableProcess := reloader.TransformReloadableProcesses(originalProcess, libreload.ReloadableProcessSpec{
WatchPaths: []string{context.WorkingDir},
})
reloadableProcess.Type = "web"
nonReloadableProcess.Type = "no-reload"
processes = append(processes, reloadableProcess, nonReloadableProcess)
} else {
processes = append(processes, originalProcess)
}
logger.LaunchProcesses(processes)
return packit.BuildResult{
Launch: packit.LaunchMetadata{
Processes: processes,
},
}, nil
}
}