Skip to content

Commit

Permalink
feat: republish major tag on new npm version
Browse files Browse the repository at this point in the history
Fixes #9
  • Loading branch information
domharrington committed Jul 7, 2023
1 parent 240831f commit a90c644
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
41 changes: 41 additions & 0 deletions bin/set-major-version-tag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env node
/* eslint-disable no-console */

// Inspired by https://github.com/readmeio/rdme/blob/edc68c365e9f39f41a16cf389ee960bf71f6425e/bin/set-major-version-tag.js
// https://github.com/readmeio/readme-micro/issues/9

/**
* Sets major git tag as part of release process
*
* @example v7
*/
const { execSync } = require('child_process');

// eslint-disable-next-line import/no-extraneous-dependencies
const semverParse = require('semver/functions/parse');

const pkg = require('../package.json');

async function setMajorVersionTag() {
const parsedVersion = semverParse(pkg.version);

if (parsedVersion.prerelease.length) {
console.warn('Pre-release version, not setting major version tag');
return process.exit(0);
}

const cmd = `git tag v${parsedVersion.major} -f -m 'Top-level tag pointing to ${parsedVersion.version}'`;

console.log(`$ ${cmd}`);

try {
const stdout = execSync(cmd);
console.log(stdout.toString());
return process.exit(0);
} catch (e) {
console.error('Error running command', e);
return process.exit(1);
}
}

setMajorVersionTag();
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"test": "jest",
"preversion": "echo $npm_package_version > .old-version.txt",
"version": "sed -i '' \"s/$(cat .old-version.txt)/$npm_package_version/\" README.md && git add README.md",
"postversion": "rm -rf .old-version.txt"
"postversion": "rm -rf .old-version.txt && ./bin/set-major-version-tag.js"
},
"author": "",
"license": "ISC",
Expand All @@ -37,7 +37,8 @@
"eslint": "^8.37.0",
"jest": "^29.5.0",
"nock": "^13.3.0",
"prettier": "^2.8.7"
"prettier": "^2.8.7",
"semver": "^7.5.3"
},
"prettier": "@readme/eslint-config/prettier",
"publishConfig": {
Expand Down

0 comments on commit a90c644

Please sign in to comment.