|
| 1 | +#!/usr/bin/env zx |
| 2 | +import 'zx/globals' |
| 3 | +/* eslint-disable @typescript-eslint/no-unused-expressions */ |
| 4 | + |
| 5 | +// Creates a new version based on the current branch name |
| 6 | + |
| 7 | +const {packages} = await fs.readJson('./release-please-config.json') |
| 8 | +const workspaces = Object.keys(packages) |
| 9 | + |
| 10 | +echo`found ${chalk.blue(workspaces.length)} workspaces to publish canaries for` |
| 11 | + |
| 12 | +const prev = new Map() |
| 13 | +const next = new Map() |
| 14 | + |
| 15 | +// Get current branch name (replace / with _ for valid npm version) |
| 16 | +const branch = (await $`git rev-parse --abbrev-ref HEAD | sed 's/\\//\\_/g'`).stdout.trim() |
| 17 | + |
| 18 | +const tag = `${branch === 'main' ? 'next' : branch}` |
| 19 | + |
| 20 | +for (const workspace of workspaces) { |
| 21 | + const {name, version, private: isPrivate} = await fs.readJson(`./${workspace}/package.json`) |
| 22 | + if (!isPrivate) { |
| 23 | + await spinner(`bumping ${chalk.blue(name)} from ${chalk.yellow(version)}`, async () => { |
| 24 | + prev.set(name, version) |
| 25 | + // Create version with branch name and commit SHA |
| 26 | + await $`pnpm --filter="${name}" exec pnpm version --no-commit-hooks --no-git-tag-version --preid ${tag} prerelease` |
| 27 | + next.set(name, (await fs.readJson(`./${workspace}/package.json`)).version) |
| 28 | + }) |
| 29 | + echo`bumped ${chalk.blue(name)} from ${chalk.yellow(prev.get(name))} to ${chalk.green(next.get(name))}` |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +await $`pnpm build --output-logs=errors-only`.pipe(process.stdout) |
| 34 | + |
| 35 | +for (const name of next.keys()) { |
| 36 | + try { |
| 37 | + const otp = await question('Enter OTP: ') |
| 38 | + await $`pnpm --filter="${name}" publish --tag ${tag} --no-git-checks --otp=${otp}`.pipe( |
| 39 | + process.stdout, |
| 40 | + ) |
| 41 | + } catch (error) { |
| 42 | + if (error.message.includes('EOTP')) { |
| 43 | + // If OTP is invalid or expired, try again |
| 44 | + const newOtp = await question('Invalid OTP. Please enter again: ') |
| 45 | + await $`pnpm --filter="${name}" publish --tag ${tag} --no-git-checks --otp=${newOtp}`.pipe( |
| 46 | + process.stdout, |
| 47 | + ) |
| 48 | + } else { |
| 49 | + throw error |
| 50 | + } |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +echo`published versions for ${chalk.blue(workspaces.length)} workspaces` |
| 55 | + |
| 56 | +// Revert the version bumps, just do git checkout <package>/package.json |
| 57 | +for (const name of workspaces) { |
| 58 | + await $`git checkout ./${name}/package.json` |
| 59 | +} |
0 commit comments