-
Notifications
You must be signed in to change notification settings - Fork 8
/
detect.go
53 lines (46 loc) · 1.25 KB
/
detect.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
package noderunscript
import (
"errors"
"os"
"github.com/paketo-buildpacks/libnodejs"
"github.com/paketo-buildpacks/packit/v2"
)
type BuildPlanMetadata struct {
Build bool `toml:"build"`
}
func Detect(env Environment) packit.DetectFunc {
return func(context packit.DetectContext) (packit.DetectResult, error) {
if env.NodeRunScripts == "" {
return packit.DetectResult{}, packit.Fail.WithMessage(`script running has been deactivated: BP_NODE_RUN_SCRIPTS=""`)
}
projectDir, err := libnodejs.FindProjectPath(context.WorkingDir)
if err != nil {
return packit.DetectResult{}, err
}
_, packageManager, err := ScriptsToRun(projectDir, env.NodeRunScripts)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
return packit.DetectResult{}, packit.Fail.WithMessage("no package.json file present")
}
return packit.DetectResult{}, err
}
return packit.DetectResult{
Plan: packit.BuildPlan{
Requires: []packit.BuildPlanRequirement{
{
Name: "node",
Metadata: BuildPlanMetadata{Build: true},
},
{
Name: packageManager,
Metadata: BuildPlanMetadata{Build: true},
},
{
Name: "node_modules",
Metadata: BuildPlanMetadata{Build: true},
},
},
},
}, nil
}
}