Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
269 views
in Technique[技术] by (71.8m points)

NPM script to automate package increment and GIT push

I am trying to do the following within one script(or excecute via one command)

  1. Run rollup
  2. Add the files that have changed/created/discarded
  3. Increment the package version number (patch)
  4. Git Commit and add the package version number
  5. Push git

Essentially i want to automate the push process.

Here is the script i created but the git message is "MSG" instead of the version

"npm run rollup && git add . && npm version patch -git-tag-version false && SET MSG=npm version utilities --version git commit -q -m  MSG && git push"

The following command works except the MSG variable does not contain the actual version which is calculated by SET MSG=npm version utilities --version

I attempted it with an ampersand between setting the MSG variable and git commit

Many thanks


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It may be too difficult to write in one CMD line due to lack of backtick support. Instead consider using ShellJS or Tasksfile and having your script run that instead:

"npx task package"
// tasksfile.js
const { sh, cli } = require('tasksfile')

function package() {
    sh('rollup');
    sh('git add .');
    sh('npm version patch -git-tag-version false');

    const version = sh('npm version utilities --version');

    sh(`git commit -q -m ${version}`);
    sh('git push');
}

cli({
  package
})

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...