diff --git a/pack/node.go b/pack/node.go index 9ce04c2..6a6afd7 100644 --- a/pack/node.go +++ b/pack/node.go @@ -23,6 +23,7 @@ func (n *NodePack) Metadata() *Metadata { }, User: user, } + if fileExists(n.WorkDir, "yarn.lock") { meta.Tools = append(meta.Tools, &Tool{ Name: "yarn", @@ -52,6 +53,11 @@ func (n *NodePack) Metadata() *Metadata { }, }) } + + scripts := n.scripts() + if scripts["build"] { + meta.Install = append(meta.Install, meta.Tools[0].Name+" run build") + } return meta } @@ -118,3 +124,28 @@ func (n *NodePack) Version() (string, error) { } return "", nil } + +func (n *NodePack) scripts() map[string]bool { + b, err := fileRead(n.WorkDir, "package.json") + if err != nil { + return nil + } + + conf := map[string]interface{}{} + if err = json.Unmarshal(b, &conf); err != nil { + return nil + } + + scripts, ok := conf["scripts"].(map[string]interface{}) + if !ok { + return nil + } + + scriptMap := map[string]bool{} + for key, value := range scripts { + if _, ok := value.(string); ok { + scriptMap[key] = true + } + } + return scriptMap +}