Skip to content

Commit c991d31

Browse files
committed
improve script release
1 parent 049cd90 commit c991d31

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

‎scripts/release.ts‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
* --no-release Skip GitHub release creation
2929
* --pr <number> Use specific PR for release notes (default: latest merged)
3030
* --notes <text> Custom release notes (instead of PR description)
31+
--otp <code> npm one-time password for 2FA (prompted if not provided)
3132
*/
3233

3334
import { readFileSync } from 'fs'
@@ -169,6 +170,7 @@ const { values, positionals } = parseArgs({
169170
'no-release': { type: 'boolean', default: false },
170171
pr: { type: 'string' },
171172
notes: { type: 'string' },
173+
otp: { type: 'string' },
172174
help: { type: 'boolean', short: 'h' },
173175
},
174176
allowPositionals: true,
@@ -188,6 +190,7 @@ Options:
188190
--no-release Skip GitHub release
189191
--pr <number> Use specific PR for release notes
190192
--notes <text> Custom release notes
193+
--otp <code> npm one-time password (prompted if not provided)
191194
--help Show this message
192195
`)
193196
process.exit(0)
@@ -200,6 +203,7 @@ const doPublish = !values['no-publish']
200203
const doBuild = !values['no-build']
201204
const doRelease = !values['no-release']
202205
const customNotes = values.notes ?? null
206+
const otpArg = values.otp ?? null
203207

204208
if (onlyPackage && !PACKAGES.includes(onlyPackage)) {
205209
console.error(`Unknown package: ${onlyPackage}. Use: ${PACKAGES.join(' | ')}`)
@@ -275,11 +279,29 @@ if (doBuild) {
275279
// --- Step 3: Publish ---
276280

277281
if (doPublish) {
282+
// Prompt for OTP if not provided via --otp
283+
let otp = otpArg
284+
if (!otp) {
285+
process.stdout.write('\n🔐 Enter npm one-time password (OTP): ')
286+
otp = await new Promise<string>((resolve) => {
287+
process.stdin.setEncoding('utf-8')
288+
process.stdin.resume()
289+
process.stdin.once('data', (data) => {
290+
process.stdin.pause()
291+
resolve(data.trim())
292+
})
293+
})
294+
if (!otp) {
295+
console.error('❌ No OTP provided. Aborting publish.')
296+
process.exit(1)
297+
}
298+
}
299+
278300
console.log('\n🚀 Publishing...')
279301
for (const item of plan) {
280302
try {
281303
const tag = item.next.includes('beta') || item.next.includes('alpha') ? 'next' : item.config.npmTag
282-
await $`cd ${join(ROOT, 'packages', item.config.name)} && npm publish --tag ${tag}`.quiet()
304+
await $`cd ${join(ROOT, 'packages', item.config.name)} && npm publish --tag ${tag} --otp ${otp}`.quiet()
283305
console.log(` ✅ ${item.config.name}@${item.next} published (${tag})`)
284306
} catch (e: any) {
285307
console.error(` ❌ ${item.config.name} publish failed`)

0 commit comments

Comments
 (0)