diff --git a/scripts/release.ts b/scripts/release.ts index e1b09e9c..3b05ad6a 100644 --- a/scripts/release.ts +++ b/scripts/release.ts @@ -5,9 +5,9 @@ import prompts from 'prompts'; import semver from 'semver'; import colors from 'picocolors'; import { - args, getLatestTag, getPackageInfo, + getTagSha, getVersionChoices, isDryRun, logRecentCommits, @@ -18,33 +18,31 @@ import { } from './releaseUtils.js'; (async () => { - let targetVersion: string | undefined; - const { currentVersion, pkg, pkgPath, pkgDir } = await getPackageInfo(); + const { currentVersion, pkgPath, pkgDir } = await getPackageInfo(); - const packageName = pkg.name; + const latestTag = await getLatestTag(); + if (latestTag) { + const sha = await getTagSha(latestTag); + await logRecentCommits(latestTag, sha); + } - await logRecentCommits(packageName); + const { release }: { release: string } = await prompts({ + type: 'select', + name: 'release', + message: 'Select release type', + choices: getVersionChoices(currentVersion), + }); - if (!targetVersion) { - const { release }: { release: string } = await prompts({ - type: 'select', - name: 'release', - message: 'Select release type', - choices: getVersionChoices(currentVersion), + let targetVersion = release; + if (release === 'custom') { + const { version }: { version: string } = await prompts({ + type: 'text', + name: 'version', + message: 'Input custom version', + initial: currentVersion, }); - - if (release === 'custom') { - const res: { version: string } = await prompts({ - type: 'text', - name: 'version', - message: 'Input custom version', - initial: currentVersion, - }); - targetVersion = res.version; - } else { - targetVersion = release; - } + targetVersion = version; } if (!semver.valid(targetVersion)) { @@ -52,14 +50,7 @@ import { process.exit(1); } - const tag = `${packageName}@${targetVersion}`; - - if (targetVersion.includes('beta') && !args.tag) { - args.tag = 'beta'; - } - if (targetVersion.includes('alpha') && !args.tag) { - args.tag = 'alpha'; - } + const tag = `v${targetVersion}`; const { yes }: { yes: boolean } = await prompts({ type: 'confirm', @@ -74,21 +65,6 @@ import { step('\nUpdating package version...'); updateVersion(pkgDir, pkgPath, targetVersion); - step('\nGenerating changelog...'); - const latestTag = await getLatestTag(packageName); - if (!latestTag) { - step('\nNo previous tag, skipping changelog generation.'); - } else { - const sha = ( - await run('git', ['rev-list', '-n', '1', latestTag], { - stdio: 'pipe', - }) - ).stdout.trim(); - - const changelogArgs = ['generate-changelog', `${sha}..HEAD`]; - await run('npx', changelogArgs, { cwd: pkgDir }); - } - const { stdout } = await run('git', ['diff'], { stdio: 'pipe' }); if (stdout) { step('\nCommitting changes...'); @@ -101,8 +77,8 @@ import { } step('\nPushing to GitHub...'); - await runIfNotDry('git', ['push', 'origin', `refs/tags/${tag}`]); await runIfNotDry('git', ['push']); + await runIfNotDry('git', ['push', 'origin', `refs/tags/${tag}`]); if (isDryRun) { console.log('\nDry run finished - run git diff to see package changes.'); diff --git a/scripts/releaseUtils.ts b/scripts/releaseUtils.ts index 43a2d419..d611f094 100644 --- a/scripts/releaseUtils.ts +++ b/scripts/releaseUtils.ts @@ -163,28 +163,26 @@ export function updateVersion(pkgDir: string, pkgPath: string, version: string): execSync('npm install', { cwd: pkgDir, stdio: 'inherit' }); } -export async function getLatestTag(pkgName: string): Promise { - const tags = (await run('git', ['tag'], { stdio: 'pipe' })).stdout +export async function getLatestTag(): Promise { + return (await run('git', ['tag'], { stdio: 'pipe' })).stdout .split(/\n/) - .filter(Boolean); - const prefix = `${pkgName}@`; - return tags - .filter((tag) => tag.startsWith(prefix)) + .filter(Boolean) .sort() .reverse()[0]; } -export async function logRecentCommits(pkgName: string): Promise { - const tag = await getLatestTag(pkgName); - if (!tag) return; - const sha = await run('git', ['rev-list', '-n', '1', tag], { +export async function getTagSha(tag: string): Promise { + return await run('git', ['rev-list', '-n', '1', tag], { stdio: 'pipe', }).then((res) => res.stdout.trim()); +} + +export async function logRecentCommits(tag: string, sha: string): Promise { console.log( colors.bold( - `\n${colors.blue('i')} Commits of ${colors.green( - pkgName - )} since ${colors.green(tag)} ${colors.gray(`(${sha.slice(0, 5)})`)}` + `\n${colors.blue('i')} Commits since ${colors.green( + tag, + )} ${colors.gray(`(${sha.slice(0, 5)})`)}` ) ); await run( diff --git a/scripts/verifyPublish.ts b/scripts/verifyPublish.ts index b3dc0e05..ea442707 100644 --- a/scripts/verifyPublish.ts +++ b/scripts/verifyPublish.ts @@ -8,18 +8,9 @@ import { args, getPackageInfo } from './releaseUtils.js'; process.exit(1); } - const versionIndex = tag.lastIndexOf('@'); - const pkgName = tag.slice(0, versionIndex); - const version = tag.slice(versionIndex + 1); + const [, version] = tag.split('v'); - const { pkg, currentVersion } = await getPackageInfo(); - const packageName = pkg.name; - if (pkgName !== packageName) { - console.error( - `Package name from tag '${pkgName}' mismatches with package '${packageName}'` - ); - process.exit(1); - } + const { currentVersion } = await getPackageInfo(); if (currentVersion !== version) { console.error( `Package version from tag '${version}' mismatches with current version '${currentVersion}'`