Skip to content

Canary release script cleanup #1843

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions scripts/release-canary.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,25 @@ const { join } = require('path')
const minimist = require('minimist')
const chalk = require('chalk')

const helpMessage = `usage: node scripts/release-canary.js [options]

--otp <code> One-time password (required)
--reset Reset the canary version to 1
--dry-run Run everything but don't actually publish
-h, --help Show this help message`

async function release (opts) {
if (opts.help) {
console.log(helpMessage)
process.exit(0)
}

assert(process.cwd() !== __dirname, 'You should run the script from the top level directory of the repository')
assert(typeof opts.otp === 'string', 'Missing OTP')
const packageJson = JSON.parse(await readFile(join(__dirname, '..', 'package.json'), 'utf8'))
if (!opts['dry-run']) {
assert(typeof opts.otp === 'string', 'Missing OTP')
}

const packageJson = JSON.parse(await readFile(join(__dirname, '..', 'package.json'), 'utf8'))
const originalName = packageJson.name
const originalVersion = packageJson.version
const currentCanaryVersion = packageJson.versionCanary
Expand All @@ -52,6 +66,7 @@ async function release (opts) {
const diff = execSync('git diff').toString().split('\n').map(colorDiff).join('\n')
console.log(diff)
const answer = await confirm()

// release on npm with provided otp
if (answer) {
execSync(`npm publish --otp ${opts.otp} ${opts['dry-run'] ? '--dry-run' : ''}`, { stdio: 'inherit' })
Expand All @@ -73,8 +88,8 @@ async function release (opts) {
)
}

function confirm (question) {
return new Promise((resolve, reject) => {
function confirm () {
return new Promise((resolve) => {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
Expand Down Expand Up @@ -110,12 +125,18 @@ release(
boolean: [
// Reset the canary version to '1'
'reset',
// run all the steps but publish
'dry-run'
]

// run all the steps but don't publish
'dry-run',

// help text
'help',
],
alias: { help: 'h' },
})
)
.catch(err => {
console.log(err)
console.log('\n' + helpMessage)
process.exit(1)
})