chore: bump core version based on provided semver type

This commit is contained in:
MIPAN 2025-07-17 22:33:09 +08:00 committed by GitHub
parent b632a4d288
commit 4b23b994c8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 34 additions and 35 deletions

View File

@ -4,8 +4,9 @@ const fs = require('fs');
const path = require('path'); const path = require('path');
const yaml = require('js-yaml'); const yaml = require('js-yaml');
// --- Argument parsing ---
const args = process.argv.slice(2); const args = process.argv.slice(2);
const bumpType = args[0] || 'minor'; // default to minor const bumpType = args[0] || 'minor';
if (!['major', 'minor', 'patch'].includes(bumpType)) { if (!['major', 'minor', 'patch'].includes(bumpType)) {
console.log('Usage: node bump-core-version.js [major|minor|patch]'); console.log('Usage: node bump-core-version.js [major|minor|patch]');
@ -13,45 +14,43 @@ if (!['major', 'minor', 'patch'].includes(bumpType)) {
process.exit(1); process.exit(1);
} }
function bumpVersion(currentVersion, type) { // --- Function to bump semantic version ---
const [major, minor, patch] = currentVersion.split('.').map(Number); function bumpVersion(version, type) {
const [major, minor, patch] = version.split('.').map(Number);
switch (type) {
case 'major': return {
return `${major + 1}.0.0`; major: `${major + 1}.0.0`,
case 'minor': minor: `${major}.${minor + 1}.0`,
return `${major}.${minor + 1}.0`; patch: `${major}.${minor}.${patch + 1}`,
case 'patch': }[type] || version;
return `${major}.${minor}.${patch + 1}`;
default:
return currentVersion;
}
} }
async function bumpCoreVersion() { // --- Main function ---
function bumpCoreVersion() {
const configPath = path.join(__dirname, '..', 'bmad-core', 'core-config.yaml');
try { try {
const coreConfigPath = path.join(__dirname, '..', 'bmad-core', 'core-config.yaml'); const content = fs.readFileSync(configPath, 'utf8');
const config = yaml.load(content);
const coreConfigContent = fs.readFileSync(coreConfigPath, 'utf8');
const coreConfig = yaml.load(coreConfigContent); const oldVersion = config.version || '1.0.0';
const oldVersion = coreConfig.version || '1.0.0';
const newVersion = bumpVersion(oldVersion, bumpType); const newVersion = bumpVersion(oldVersion, bumpType);
coreConfig.version = newVersion; config.version = newVersion;
const updatedYaml = yaml.dump(config, { indent: 2 });
const updatedYaml = yaml.dump(coreConfig, { indent: 2 });
fs.writeFileSync(coreConfigPath, updatedYaml); fs.writeFileSync(configPath, updatedYaml);
console.log(`✓ BMad Core: ${oldVersion}${newVersion}`); console.log(`✓ BMad Core version bumped: ${oldVersion}${newVersion}\n`);
console.log(`\n✓ Successfully bumped BMad Core with ${bumpType} version bump`); console.log('Next steps:');
console.log('\nNext steps:'); console.log(`1. Test your changes`);
console.log('1. Test the changes'); console.log(`2. Commit:\n git add -A && git commit -m "chore: bump core version (${bumpType})"`);
console.log('2. Commit: git add -A && git commit -m "chore: bump core version (' + bumpType + ')"');
} catch (err) {
} catch (error) { console.error(`✗ Failed to bump version: ${err.message}`);
console.error('Error updating core version:', error.message);
process.exit(1); process.exit(1);
} }
} }
bumpCoreVersion(); // --- Run ---
bumpCoreVersion();