Skip to content

Instantly share code, notes, and snippets.

@IJustDev
Last active November 14, 2023 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IJustDev/56f5f61cf8f62be9bcd6249b1e1de7aa to your computer and use it in GitHub Desktop.
Save IJustDev/56f5f61cf8f62be9bcd6249b1e1de7aa to your computer and use it in GitHub Desktop.
Makefile to publish royalzsoftware/royal-data-ts to GitHub and npm by simply changing the CHANGELOG.md
const fs = require('fs');
function readChangelogFile() {
const buffer = fs.readFileSync(__dirname + '/../CHANGELOG.md');
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) {
console.info("Nothing to do");
return process.exit(1);
}
console.log("Updating version in package.json from " + packageJson.version + " to " + latestVesion);
packageJson.version = latestVesion;
savePackageJson(packageJson);
return process.exit(0);
# requires: jq, git, github cli (gh) and node with npm.
release:
git diff --quiet -- ':(exclude)Makefile' ':(exclude)CHANGELOG.md' ':(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 CHANGELOG.md 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 CHANGELOG.md
npm publish
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment