npm运行构建,如果成功,则提交

时间:2020-05-27 11:47:19

标签: git npm yarnpkg package.json

我如何设置package.json来检查构建是否成功,然后将更改添加并提交到git?

当前版本:

"build": "react-scripts build"

1 个答案:

答案 0 :(得分:0)

这里是答案:

  "scripts": {
    "build": "react-scripts build",
    "build-and-commit": "node -e \"const mssg = process.argv[1]; require('child_process').execSync('npm run build && git add . && git commit -m \\\"' + mssg + '\\\"', { stdio:[0, 1, 2] })\""
  }

运行方式:

$ npm run build-and-commit -- "commit message"

或:

$ yarn build-and-commit -- "commit message"

此处的完整答案:Pass git commit message to npm script and append to predefined string

Tnx到RobC