Skip to content

Commit

Permalink
Don't try to set dist-tag, just do it separately
Browse files Browse the repository at this point in the history
  • Loading branch information
ghengeveld committed Jun 27, 2022
1 parent 91e42d7 commit 0d1bd21
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions scripts/release.js
Expand Up @@ -27,16 +27,13 @@ const bumpVersion = async ({ bump, tag, currentTag, dryRun }) => {
}
};

const publishPackage = async ({ tag, otp, dryRun }) => {
const publishPackage = async ({ tag, dryRun }) => {
const { version } = await readJSON(join(__dirname, '../package.json'));
const dry = dryRun ? '--dry-run' : '';
console.log(`✅ Publishing ${tag} version ${version} ${dry && `(${dry})`}`);
await command(`npm publish --tag ${tag} --otp ${otp} ${dry}`);
await command(`npm publish --tag ${tag} ${dry}`);
if (!dryRun) {
await command(`git push --follow-tags`);
if (tag === 'latest') {
await command(`npm dist-tag add chromatic@${version} next --otp ${otp}`);
}
}
};

Expand Down Expand Up @@ -69,23 +66,19 @@ const publishAction = async ({ repo, tag, version }) => {
(async () => {
const [bump, tag, ...rest] = process.argv.slice(2);
const dryRun = rest.includes('--dry-run');
const [, otp] = rest.find((arg) => arg.startsWith('--otp'))?.match(/[=\s"'](\d{6})["']?$/) || [];

if (!['patch', 'minor', 'major'].includes(bump)) {
throw new Error("Invalid bump, expecting one of 'patch', 'minor', 'major'");
}
if (!['canary', 'next', 'latest'].includes(tag)) {
throw new Error("Invalid tag, expecting one of 'canary', 'next', 'latest'");
}
if (!otp) {
throw new Error('Missing --otp flag, expecting 6 digits');
}

const { version: currentVersion } = await readJSON(join(__dirname, '../package.json'));
const [, , , currentTag] = currentVersion.match(/^([0-9]+\.[0-9]+\.[0-9]+)(-(\w+)\.\d+)?$/);

await bumpVersion({ bump, tag, currentTag, dryRun });
await publishPackage({ tag, otp, dryRun });
await publishPackage({ tag, dryRun });

if (dryRun) {
console.log(`✅ Not publishing action due to --dry-run`);
Expand All @@ -102,4 +95,9 @@ const publishAction = async ({ repo, tag, version }) => {
await publishAction({ repo: 'chromaui/action-next', tag, version });
await publishAction({ repo: 'chromaui/action', tag, version });
}

if (tag === 'latest') {
const tagCommand = `npm dist-tag add chromatic@${version} next`;
console.log(`⚠️ Don't forget to update the 'next' tag by running:\n ${tagCommand}`);
}
})();

0 comments on commit 0d1bd21

Please sign in to comment.