clear-wallet/release-scripts/version-release.ts

49 lines
1.4 KiB
TypeScript
Raw Normal View History

import { execSync } from 'child_process';
import { readFileSync, writeFileSync } from 'fs';
import { resolve } from 'path';
async function main() {
// -1. Check if you are in the main branch
const branch = execSync(`git branch --show-current`).toString();
if (branch !== 'main') {
console.log('You must be in the main branch to create a release');
return
}
2025-01-23 08:03:48 +00:00
// 0. Check tag is not already created
const tags = execSync(`git tag --list`).toString();
2025-01-23 08:15:34 +00:00
if(!process.env.npm_package_version) {
console.log('No version found in package.json');
return;
}
const nextVersion = bumpVersion(process.env.npm_package_version);
if (tags.includes(`v${nextVersion}`)) {
console.log(`Tag v${nextVersion} already exists`);
2025-01-23 08:03:48 +00:00
return;
}
// 1. Bump version in package.json
const packageJsonPath = resolve('./package.json');
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
2025-01-23 08:15:34 +00:00
packageJson.version = nextVersion;
writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
// 3. Commit changes
execSync(`git add .`);
2025-01-23 08:15:34 +00:00
execSync(`git commit -m "clear-wallet@v${nextVersion}"`);
// 4. Create and push tag
2025-01-23 08:15:34 +00:00
execSync(`git tag v${nextVersion}`);
execSync(`git push --follow-tags`);
}
function bumpVersion(version: string): string {
const parts = version.split('.');
parts[2] = String(parseInt(parts[2]) + 1);
return parts.join('.');
}
main();