|
| 1 | +import {promisify} from 'util'; |
| 2 | +import assert from 'assert'; |
| 3 | +import {resolve} from 'path'; |
| 4 | +import semver from 'semver'; |
| 5 | +import {exec as execCallback} from 'child_process'; |
| 6 | +import {writeFile, readFile} from 'fs/promises'; |
| 7 | + |
| 8 | +const exec = promisify(execCallback); |
| 9 | + |
| 10 | +async function updatePackageVersion(packagePath, currentVersion, releaseType) { |
| 11 | + const packageFile = resolve(packagePath, 'package.json'); |
| 12 | + const packageJson = JSON.parse(await readFile(packageFile, 'utf-8')); |
| 13 | + |
| 14 | + packageJson.version = semver.inc(currentVersion, releaseType); |
| 15 | + |
| 16 | + await writeFile(packageFile, JSON.stringify(packageJson, null, 2) + '\n'); |
| 17 | +} |
| 18 | + |
| 19 | +async function main() { |
| 20 | + const releaseType = process.env.RELEASE_TYPE; |
| 21 | + assert.match(releaseType, /^(patch|minor|major)$/, 'Invalid RELEASE_TYPE'); |
| 22 | + |
| 23 | + const packages = JSON.parse((await exec('pnpm ls -r --only-projects --json')).stdout); |
| 24 | + |
| 25 | + for (let {name, path, version, private: isPrivate} of packages) { |
| 26 | + if (isPrivate && name !== 'kurrent-node-client-repository') continue; |
| 27 | + await updatePackageVersion(path, version, releaseType); |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +main().catch(error => { |
| 32 | + console.error('Error updating package versions:', error); |
| 33 | + process.exit(1); |
| 34 | +}); |
0 commit comments