Skip to content

Instantly share code, notes, and snippets.

@chengjianhua
Created October 24, 2017 04:56
Show Gist options
  • Save chengjianhua/4c778d7f553b7045d00a5a87d6a39fd6 to your computer and use it in GitHub Desktop.
Save chengjianhua/4c778d7f553b7045d00a5a87d6a39fd6 to your computer and use it in GitHub Desktop.
check a package version is whether a `beta` one
const cp = require('child_process');
const pkg = require('../package.json');
const BETA_NAMES = ['alpha', 'beta'];
const { version } = pkg;
// the alpha version No. should be like "v7.1.0-alpha.2", "v8.0.0"
const alphaReg = /(?:\d+\.\d+\.\d+)(-([a-zA-Z]+)\.\d+)?/i;
const versionMatch = version.match(alphaReg);
const alpha = versionMatch[2];
const isBeta = BETA_NAMES.includes(alpha);
console.dir({ version, versionMatch, alpha, isBeta }, { colors: true });
const publishArgs = isBeta ? [
'--tag',
'beta',
] : [];
const publishProcess = cp.spawn('npm publish --verbose', [
...publishArgs,
], { shell: true, stdio: ['inherit', 'inherit', 'inherit'] });
publishProcess.on('exit', (code) => {
if (code !== 0) {
process.exit(1);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment