Support dry run publishing using --dry

This commit is contained in:
Daniel Imms
2019-06-15 13:42:52 -07:00
parent 846a1897e9
commit 2e83483e08
+19 -3
View File
@@ -11,6 +11,11 @@ const packageJson = require('../package.json');
// Setup auth
fs.writeFileSync(`${process.env['HOME']}/.npmrc`, `//registry.npmjs.org/:_authToken=${process.env['NPM_AUTH_TOKEN']}`);
const isDryRun = process.argv.indexOf('--dry') !== -1;
if (isDryRun) {
console.log('Publish dry run');
}
// Determine if this is a stable or beta release
const publishedVersions = getPublishedVersions();
const isStableRelease = publishedVersions.indexOf(packageJson.version) === -1;
@@ -22,15 +27,23 @@ console.log(`Publishing version: ${nextVersion}`);
// Set the version in package.json
const packageJsonFile = path.resolve(__dirname, '..', 'package.json');
packageJson.version = nextVersion;
fs.writeFileSync(packageJsonFile, JSON.stringify(packageJson, null, 2));
if (isDryRun) {
console.log(`Set version of ${packageJsonFile} to ${nextVersion}`);
} else {
fs.writeFileSync(packageJsonFile, JSON.stringify(packageJson, null, 2));
}
// Publish
const args = ['publish'];
if (!isStableRelease) {
args.push('--tag', 'beta');
}
const result = cp.spawn('npm', args, { stdio: 'inherit' });
result.on('exit', code => process.exit(code));
if (isDryRun) {
console.log(`Spawn: npm ${args.join(' ')}`);
} else {
const result = cp.spawn('npm', args, { stdio: 'inherit' });
result.on('exit', code => process.exit(code));
}
function getNextBetaVersion() {
if (!/^[0-9]+\.[0-9]+\.[0-9]+$/.exec(packageJson.version)) {
@@ -61,3 +74,6 @@ function getPublishedVersions(version, tag) {
}
return versionsJson;
}
function publishPackage(packageDir) {
}