2024-10-13 11:22:38 +00:00
|
|
|
import { execSync } from 'child_process';
|
|
|
|
import { readFileSync, writeFileSync } from 'fs';
|
|
|
|
import { resolve } from 'path';
|
|
|
|
|
|
|
|
async function main() {
|
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;
|
|
|
|
}
|
|
|
|
|
2024-10-13 11:22:38 +00:00
|
|
|
// 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;
|
2024-10-13 11:22:38 +00:00
|
|
|
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}"`);
|
2024-10-13 11:22:38 +00:00
|
|
|
|
|
|
|
// 4. Create and push tag
|
2025-01-23 08:15:34 +00:00
|
|
|
execSync(`git tag v${nextVersion}`);
|
2024-10-13 11:22:38 +00:00
|
|
|
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();
|