Makefile to publish royalzsoftware/royal-data-ts to GitHub and npm by simply changing the CHANGELOG.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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