Skip to content

Commit 6a505a2

Browse files
committed
chore: add optional OTP option to release script
1 parent da67b4c commit 6a505a2

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

scripts/npm-utils.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ import { exec } from './child-process.mjs';
55
* @param {{ cwd: String, dryRun: Boolean}} options
66
* @returns {Promise<any>}
77
*/
8-
export function publishPackage(publishTagName, { cwd, dryRun }) {
8+
export function publishPackage(publishTagName, { cwd, otp, dryRun }) {
99
const execArgs = ['publish'];
1010
if (publishTagName) {
1111
execArgs.push('--tag', publishTagName);
1212
}
13+
if (otp) {
14+
execArgs.push('--otp', otp);
15+
}
1316
if (dryRun) {
1417
execArgs.push('--dry-run');
1518
}

scripts/release.mjs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,11 @@ const pkg = loadJsonFileSync(path.join(__dirname, '../', 'package.json'));
141141
} else if (whichBumpType.includes('beta')) {
142142
publishTagName = 'beta';
143143
}
144-
await publishPackage(publishTagName, { cwd, dryRun: argv.dryRun });
144+
let otp = '';
145+
if (await promptConfirmation(`${c.bgMagenta(dryRunPrefix)} Do you have OTP (One-Time-Password) enabled?`, undefined, 1)) {
146+
otp = await promptOtp();
147+
}
148+
await publishPackage(publishTagName, { cwd, otp, dryRun: argv.dryRun });
145149
console.log(`${c.bgMagenta(dryRunPrefix)} 📦 Published to NPM - 🔗 https://www.npmjs.com/package/${pkg.name}`.trim())
146150
}
147151

@@ -264,7 +268,9 @@ async function promptConfirmation(message, choices, defaultIndex) {
264268
{ key: 'y', name: 'Yes', value: true },
265269
{ key: 'n', name: 'No', value: false },
266270
];
267-
defaultIndex = 0;
271+
if (defaultIndex === undefined) {
272+
defaultIndex = 0;
273+
}
268274
}
269275

270276
// display propmpt message and choices
@@ -274,10 +280,18 @@ async function promptConfirmation(message, choices, defaultIndex) {
274280
}
275281

276282
// get and process input
277-
const input = await getConsoleInput("Enter value " + " (default " + (defaultIndex + 1) + ') ');
283+
const input = await getConsoleInput(`Enter value (default ${(defaultIndex + 1)}) `);
278284
var index = !isNaN(input) && !isNaN(parseFloat(input)) ? +input - 1 : defaultIndex;
279285
if (index < 0 || index >= choices.length) {
280-
throw Error('The input ' + input + ' could not be matched to a selection');
286+
throw Error(`The input ${input} could not be matched to a selection`);
281287
}
282288
return choices[index].value;
283289
}
290+
291+
async function promptOtp() {
292+
const otp = await getConsoleInput(`Enter OTP value:`);
293+
if (otp.length < 6) {
294+
throw new Error('OTP must be 6 digits.');
295+
}
296+
return otp;
297+
}

0 commit comments

Comments
 (0)