Skip to content

Commit

Permalink
chore: add new release script
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathantneal committed Aug 11, 2021
1 parent 7c0065e commit 1b52299
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 16 deletions.
16 changes: 0 additions & 16 deletions .task/bump.sh

This file was deleted.

64 changes: 64 additions & 0 deletions .task/release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import URL from './internal/url.js'
import * as co from './internal/color.js'
import * as cp from './internal/child_process.js'
import * as fs from './internal/fs.js'
import * as rl from './internal/readline.js'

let main = async () => {
let root = URL.from(import.meta.url).to('../')
let pkg = await fs.readFileJson(root.to('package.json'), 'utf8')

let q1option = new Set(['major', 'minor', 'patch', 'prerelease'])
let q1answer = await rl.question(`Bump ${co.dim('(major, minor, patch, prerelease)')}:`)
if (!q1option.has(q1answer)) return

await cp.spawn('npm', ['version', q1answer, '--workspaces'], { stdio: 'pipe' })

let workspacepkgpaths = new Set
let workspacetags = new Set
let version = ''

for (let workspace of pkg.workspaces) {
workspace = root.to(workspace).dir

let workspacepkgpath = workspace.to('package.json')
let workspacepkg = await fs.readFileJson(workspacepkgpath)

version = `v${workspacepkg.version}`

workspacepkgpaths.add(workspacepkgpath)
workspacetags.add(`${workspacepkg.name}@${workspacepkg.version}`)
}

console.log(`Bumped ${co.bold(version)}`)

let tag = q1answer === 'prerelease' ? 'canary' : 'latest'

let q2option = new Set(['y'])
let q2answer = await rl.question(`Publish ${co.bold(version)} as ${co.bold(tag)} ${co.dim('(y/n)')}:`)

if (!q2option.has(q2answer)) {
for (const workspacepkgpath of workspacepkgpaths) {
await cp.spawn('git', ['checkout', '--', workspacepkgpath.ospathname])
}
return
}

await cp.spawn('npm', ['run', 'build'])

let q3answer = await rl.question(`OTP:`)
if (!q3answer) return

for (const workspacepkgpath of workspacepkgpaths) {
await cp.spawn('git', ['add', workspacepkgpath.ospathname])
}

await cp.spawn('git', ['commit', '-m', version])
await cp.spawn('git', ['tag', version])
await cp.spawn('git', ['push'])
await cp.spawn('git', ['push', '--tags'])

await cp.spawn('npm', ['publish', '--tag', tag, '--workspaces', '--otp', otp])
}

main()
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"lint:esm": "node .task/lint-esm.js",
"lint:pkg": "node .task/lint-pkg.js",
"lint:tsc": "node .task/lint-tsc.js",
"release": "node .task/release.js",
"test": "node .task/test.js",
"test:coverage": "node .task/test-coverage.js .task/test.js",
"test:watch": "node .task/test.js --watch"
Expand Down

0 comments on commit 1b52299

Please sign in to comment.