forked from paketo-buildpacks/node-run-script
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.go
More file actions
40 lines (33 loc) · 844 Bytes
/
scripts.go
File metadata and controls
40 lines (33 loc) · 844 Bytes
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
package noderunscript
import (
"fmt"
"os"
"path/filepath"
"strings"
"github.com/paketo-buildpacks/libnodejs"
)
func ScriptsToRun(workingDir string, nodeRunScripts string) ([]string, string, error) {
scripts := strings.Split(nodeRunScripts, ",")
for i := range scripts {
scripts[i] = strings.TrimSpace(scripts[i])
}
packageJSON, err := libnodejs.ParsePackageJSON(workingDir)
if err != nil {
return nil, "", err
}
var missing []string
for _, script := range scripts {
if _, ok := packageJSON.AllScripts[script]; !ok {
missing = append(missing, script)
}
}
if len(missing) > 0 {
return nil, "", fmt.Errorf("could not find script(s) %s in package.json", missing)
}
manager := "npm"
_, err = os.Stat(filepath.Join(workingDir, "yarn.lock"))
if err == nil {
manager = "yarn"
}
return scripts, manager, nil
}