Skip to content

Commit a927c5c

Browse files
authored
Canary release script cleanup (#1843)
* add help messaging to canary release script * Don't require OTP during a dry run * Linter/whitespace cleanup
1 parent c820058 commit a927c5c

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

scripts/release-canary.js

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,25 @@ const { join } = require('path')
2222
const minimist = require('minimist')
2323
const chalk = require('chalk')
2424

25+
const helpMessage = `usage: node scripts/release-canary.js [options]
26+
27+
--otp <code> One-time password (required)
28+
--reset Reset the canary version to 1
29+
--dry-run Run everything but don't actually publish
30+
-h, --help Show this help message`
31+
2532
async function release (opts) {
33+
if (opts.help) {
34+
console.log(helpMessage)
35+
process.exit(0)
36+
}
37+
2638
assert(process.cwd() !== __dirname, 'You should run the script from the top level directory of the repository')
27-
assert(typeof opts.otp === 'string', 'Missing OTP')
28-
const packageJson = JSON.parse(await readFile(join(__dirname, '..', 'package.json'), 'utf8'))
39+
if (!opts['dry-run']) {
40+
assert(typeof opts.otp === 'string', 'Missing OTP')
41+
}
2942

43+
const packageJson = JSON.parse(await readFile(join(__dirname, '..', 'package.json'), 'utf8'))
3044
const originalName = packageJson.name
3145
const originalVersion = packageJson.version
3246
const currentCanaryVersion = packageJson.versionCanary
@@ -52,6 +66,7 @@ async function release (opts) {
5266
const diff = execSync('git diff').toString().split('\n').map(colorDiff).join('\n')
5367
console.log(diff)
5468
const answer = await confirm()
69+
5570
// release on npm with provided otp
5671
if (answer) {
5772
execSync(`npm publish --otp ${opts.otp} ${opts['dry-run'] ? '--dry-run' : ''}`, { stdio: 'inherit' })
@@ -73,8 +88,8 @@ async function release (opts) {
7388
)
7489
}
7590

76-
function confirm (question) {
77-
return new Promise((resolve, reject) => {
91+
function confirm () {
92+
return new Promise((resolve) => {
7893
const rl = readline.createInterface({
7994
input: process.stdin,
8095
output: process.stdout
@@ -110,12 +125,18 @@ release(
110125
boolean: [
111126
// Reset the canary version to '1'
112127
'reset',
113-
// run all the steps but publish
114-
'dry-run'
115-
]
128+
129+
// run all the steps but don't publish
130+
'dry-run',
131+
132+
// help text
133+
'help',
134+
],
135+
alias: { help: 'h' },
116136
})
117137
)
118138
.catch(err => {
119139
console.log(err)
140+
console.log('\n' + helpMessage)
120141
process.exit(1)
121142
})

0 commit comments

Comments
 (0)