Skip to content

Commit

Permalink
Add node build script.
Browse files Browse the repository at this point in the history
  • Loading branch information
beornf committed Apr 5, 2023
1 parent ac70c65 commit 334f922
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions pack/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

0 comments on commit 334f922

Please sign in to comment.