47 lines
1.4 KiB
JavaScript
47 lines
1.4 KiB
JavaScript
'use strict';
|
|
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
|
|
const SEMVER_PATTERN = /^\d+\.\d+\.\d+(?:-[\dA-Za-z.-]+)?(?:\+[\dA-Za-z.-]+)?$/;
|
|
|
|
const nextVersion = process.argv[2];
|
|
|
|
if (!nextVersion) {
|
|
throw new Error(
|
|
'Usage: node scripts/prepare-release.cjs <version> — version argument is required.',
|
|
);
|
|
}
|
|
|
|
if (!SEMVER_PATTERN.test(nextVersion)) {
|
|
throw new Error(
|
|
`Invalid semver "${nextVersion}". Expected e.g. 1.2.3 or 1.2.3-beta.1.`,
|
|
);
|
|
}
|
|
|
|
const workspaceRoot = path.resolve(__dirname, '..');
|
|
|
|
const versionJsonPath = path.join(workspaceRoot, 'version.json');
|
|
const adminWebPackagePath = path.join(workspaceRoot, 'admin-web', 'package.json');
|
|
|
|
writeVersionJson(versionJsonPath, nextVersion);
|
|
bumpPackageVersion(adminWebPackagePath, nextVersion);
|
|
|
|
console.log(`[prepare-release] Updated version to ${nextVersion}`);
|
|
console.log('[prepare-release] - version.json');
|
|
console.log('[prepare-release] - admin-web/package.json');
|
|
|
|
function writeVersionJson(filePath, version) {
|
|
const versionJson = { version };
|
|
fs.writeFileSync(filePath, `${JSON.stringify(versionJson, null, 2)}\n`, 'utf8');
|
|
}
|
|
|
|
function bumpPackageVersion(filePath, version) {
|
|
if (!fs.existsSync(filePath)) {
|
|
throw new Error(`Package manifest not found: ${filePath}`);
|
|
}
|
|
const manifest = JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
|
manifest.version = version;
|
|
fs.writeFileSync(filePath, `${JSON.stringify(manifest, null, 2)}\n`, 'utf8');
|
|
}
|