From 1b52299b72a590a410fec0713954bd34e0af3c8f Mon Sep 17 00:00:00 2001 From: Jonathan Neal Date: Wed, 11 Aug 2021 12:16:25 -0400 Subject: [PATCH] chore: add new release script --- .task/bump.sh | 16 ------------ .task/release.js | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + 3 files changed, 65 insertions(+), 16 deletions(-) delete mode 100644 .task/bump.sh create mode 100644 .task/release.js diff --git a/.task/bump.sh b/.task/bump.sh deleted file mode 100644 index 4cf87b78..00000000 --- a/.task/bump.sh +++ /dev/null @@ -1,16 +0,0 @@ -# bump all workspace package versions as a new prerelease -NEW_VERSION=$(npm version prerelease --workspaces --git-tag-version | tail -1); - -# add each updated package.json, because npm fails to -git add "packages/core/package.json"; -git add "packages/react/package.json"; -git add "packages/stringify/package.json"; - -# commit the new version -git commit -m "$NEW_VERSION"; - -# create a new tag for the new version -git tag "$NEW_VERSION"; - -# push the new version and new tag -git push && git push --tags; diff --git a/.task/release.js b/.task/release.js new file mode 100644 index 00000000..6a9fe22d --- /dev/null +++ b/.task/release.js @@ -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() diff --git a/package.json b/package.json index e04f5ced..fdb6fe53 100644 --- a/package.json +++ b/package.json @@ -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"