Skip to content

Commit

Permalink
chore: Refactor publish-npm script to handle OTP code for publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
klarstrup committed Aug 28, 2024
1 parent 635c4ab commit 959d55f
Showing 1 changed file with 32 additions and 6 deletions.
38 changes: 32 additions & 6 deletions publish-npm.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -453,12 +453,38 @@ async function publish() {
]);
const pubInd = ora(`Publishing ${name}@${tag} ${nextVersion}`).start();
if (!DRY_RUN) {
await run('npm', [
'publish',
'--access',
'public',
`--tag=${tag.startsWith('experimental') ? 'experimental' : tag}`
]);
async function publish(otpCode) {
try {
await run('npm', [
'publish',
'--access',
'public',
`--tag=${
tag.startsWith('experimental')
? 'experimental'
: tag
}`,
otpCode ? `--otp=${otpCode}` : ''
]);
} catch (error) {
if (error.includes('code EOTP')) {
pubInd.stop();
const {otp} = await inquirer.prompt([
{
type: 'input',
name: 'otp',
message:
'Enter NPM OTP code from your authenticator'
}
]);
pubInd.start();
await publish(otp);
} else {
throw error;
}
}
}
await publish();
}
pubInd.succeed(
`Published ${name}@${
Expand Down

0 comments on commit 959d55f

Please sign in to comment.