Skip to content

Instantly share code, notes, and snippets.

Last active November 14, 2023 21:25
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Makefile to publish royalzsoftware/royal-data-ts to GitHub and npm by simply changing the
const fs = require('fs');
function readChangelogFile() {
const buffer = fs.readFileSync(__dirname + '/../');
return buffer.toString();
function findLatestVersionFromChangelog(changelogData) {
const regex = /\d*\.\d*\.\d*/;
return regex.exec(changelogData)[0];
function readPackageJson() {
const buffer = fs.readFileSync(__dirname + '/../package.json');
return JSON.parse(buffer);
function savePackageJson(updatedPackageJson) {
fs.writeFileSync(__dirname + '/../package.json', JSON.stringify(updatedPackageJson, null, 2));
const changelogContent = readChangelogFile();
const latestVesion = findLatestVersionFromChangelog(changelogContent);
const packageJson = readPackageJson();
if (latestVesion == packageJson.version) {"Nothing to do");
return process.exit(1);
console.log("Updating version in package.json from " + packageJson.version + " to " + latestVesion);
packageJson.version = latestVesion;
return process.exit(0);
# requires: jq, git, github cli (gh) and node with npm.
git diff --quiet -- ':(exclude)Makefile' ':(exclude)' ':(exclude)tools/*' || (echo "You have uncommited changes" && exit 1)
npm run test
node tools/apply-latest-version-from-changelog-to-package-json.js
npm run build
export TAG=`cat package.json | jq -r .version` && echo $$TAG && git add package.json package-lock.json && git commit -m "chore(changelog): $$TAG" && git tag $$TAG
git push
git push --tags
export TAG=`cat package.json | jq -r .version` && gh release create --title "v$$TAG" $$TAG -F
npm publish
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment