Created
October 24, 2017 04:56
-
-
Save chengjianhua/4c778d7f553b7045d00a5a87d6a39fd6 to your computer and use it in GitHub Desktop.
check a package version is whether a `beta` one
This file contains hidden or 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 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