Skip to content

Instantly share code, notes, and snippets.

@luiscoms
Last active July 13, 2018 14:53
Show Gist options
  • Save luiscoms/b983e4375a384523a7994d32bd841fc2 to your computer and use it in GitHub Desktop.
Save luiscoms/b983e4375a384523a7994d32bd841fc2 to your computer and use it in GitHub Desktop.
Bumpversion example
fs = require('fs');
// pega o primeiro argumento do script
v = process.argv[1];
// pega o conteúdo do arquivo changelog
changelog = fs.readFileSync('CHANGELOG.md').toString();
// substitui a linha que contem Next Release e a linha inferior
// pela variável v seguida de traços
c = changelog.replace(/(Next Release\\n-+)/i, '\\$1'+'\\n\\n'+v+'\\n'+'-'.padStart(v.length, '-'));
// escreve o resultado no arquivo changelog
fs.writeFileSync('CHANGELOG.md', c);

CHANGELOG

1.1.0

  • The next big thing

1.0.1

  • A bug was fixed :(

1.0.0

  • First release

CHANGELOG

Next Release

  • The next big thing

1.0.1

  • A bug was fixed :(

1.0.0

  • First release
{
"scripts": {
"preversion": "npm test",
"version": "npm run build && git add -A dist",
"postversion": "git push && git push --tags && rm -rf build/temp"
}
}
{
"scripts": {
"release:update-changelog": "node -e \"v=process.argv[1]; fs = require('fs'); c = fs.readFileSync('CHANGELOG.md').toString().replace(/(Next Release\\n-+)/i, '\\$1'+'\\n\\n'+v+'\\n'+'-'.padStart(v.length, '-')); fs.writeFileSync('CHANGELOG.md', c); console.log(c);\"",
"preversion": "npm run release:update-changelog ${npm_package_version}"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment