diff --git a/scripts/release.mts b/scripts/release.mts index 7471306..4be8956 100644 --- a/scripts/release.mts +++ b/scripts/release.mts @@ -1,9 +1,12 @@ import fs from 'node:fs' import prompts from 'prompts' import * as semver from 'semver' +import type { SemVer } from 'semver' import spawn from 'cross-spawn' import { cyan } from 'kolorist' +const docsPath = ['./README.md', './docs/README.zh-CN.md'] + async function release() { console.log(cyan('Fetching origin...')) spawn.sync('git', ['pull'], { stdio: 'inherit' }) @@ -30,7 +33,7 @@ async function release() { spawn.sync('npm', ['pack'], { stdio: 'inherit' }) const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf-8')) - const { version: currentVersion } = pkg + const { name, version: currentVersion } = pkg const choices = Array.from(['patch', 'minor', 'major'], title => ({ title, @@ -84,6 +87,16 @@ async function release() { return } + if (!['patch', 'prerelease'].includes(t)) { + const parsedCurrentVersion = semver.parse(currentVersion) as SemVer + const parsedTargetVersion = semver.parse(targetVersion) as SemVer + const pattern = new RegExp(`${name}@${parsedCurrentVersion.major}.${parsedCurrentVersion.minor}`, 'g') + const replacement = `${name}@${parsedTargetVersion.major}.${parsedTargetVersion.minor}` + docsPath.forEach((docPath) => { + fs.writeFileSync(docPath, fs.readFileSync(docPath, 'utf-8').replace(pattern, replacement)) + }) + } + pkg.version = targetVersion fs.writeFileSync('./package.json', JSON.stringify(pkg, null, 2))