chore(tools): clean up and refactor bump scripts for clarity and consistency (#325)
* refactor: simplify installer package version sync script and add comments * chore: bump core version based on provided semver type * chore(expansion): bump bmad-creator-tools version (patch)
This commit is contained in:
@@ -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();
|
||||||
|
|||||||
@@ -1,78 +1,83 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
// Load required modules
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const yaml = require('js-yaml');
|
const yaml = require('js-yaml');
|
||||||
|
|
||||||
|
// Parse CLI arguments
|
||||||
const args = process.argv.slice(2);
|
const args = process.argv.slice(2);
|
||||||
|
const packId = args[0];
|
||||||
|
const bumpType = args[1] || 'minor';
|
||||||
|
|
||||||
if (args.length < 1 || args.length > 2) {
|
// Validate arguments
|
||||||
|
if (!packId || args.length > 2) {
|
||||||
console.log('Usage: node bump-expansion-version.js <expansion-pack-id> [major|minor|patch]');
|
console.log('Usage: node bump-expansion-version.js <expansion-pack-id> [major|minor|patch]');
|
||||||
console.log('Default: minor');
|
console.log('Default: minor');
|
||||||
console.log('Example: node bump-expansion-version.js bmad-creator-tools patch');
|
console.log('Example: node bump-expansion-version.js bmad-creator-tools patch');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const packId = args[0];
|
|
||||||
const bumpType = args[1] || 'minor'; // default to minor
|
|
||||||
|
|
||||||
if (!['major', 'minor', 'patch'].includes(bumpType)) {
|
if (!['major', 'minor', 'patch'].includes(bumpType)) {
|
||||||
console.error('Error: Bump type must be major, minor, or patch');
|
console.error('Error: Bump type must be major, minor, or patch');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Version bump logic
|
||||||
function bumpVersion(currentVersion, type) {
|
function bumpVersion(currentVersion, type) {
|
||||||
const [major, minor, patch] = currentVersion.split('.').map(Number);
|
const [major, minor, patch] = currentVersion.split('.').map(Number);
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'major':
|
case 'major': return `${major + 1}.0.0`;
|
||||||
return `${major + 1}.0.0`;
|
case 'minor': return `${major}.${minor + 1}.0`;
|
||||||
case 'minor':
|
case 'patch': return `${major}.${minor}.${patch + 1}`;
|
||||||
return `${major}.${minor + 1}.0`;
|
default: return currentVersion;
|
||||||
case 'patch':
|
|
||||||
return `${major}.${minor}.${patch + 1}`;
|
|
||||||
default:
|
|
||||||
return currentVersion;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Main function to bump version
|
||||||
async function updateVersion() {
|
async function updateVersion() {
|
||||||
|
const configPath = path.join(__dirname, '..', 'expansion-packs', packId, 'config.yaml');
|
||||||
|
|
||||||
|
// Check if config exists
|
||||||
|
if (!fs.existsSync(configPath)) {
|
||||||
|
console.error(`Error: Expansion pack '${packId}' not found`);
|
||||||
|
console.log('\nAvailable expansion packs:');
|
||||||
|
|
||||||
|
const packsDir = path.join(__dirname, '..', 'expansion-packs');
|
||||||
|
const entries = fs.readdirSync(packsDir, { withFileTypes: true });
|
||||||
|
|
||||||
|
entries.forEach(entry => {
|
||||||
|
if (entry.isDirectory() && !entry.name.startsWith('.')) {
|
||||||
|
console.log(` - ${entry.name}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const configPath = path.join(__dirname, '..', 'expansion-packs', packId, 'config.yaml');
|
|
||||||
|
|
||||||
if (!fs.existsSync(configPath)) {
|
|
||||||
console.error(`Error: Expansion pack '${packId}' not found`);
|
|
||||||
console.log('\nAvailable expansion packs:');
|
|
||||||
const expansionPacksDir = path.join(__dirname, '..', 'expansion-packs');
|
|
||||||
const entries = fs.readdirSync(expansionPacksDir, { withFileTypes: true });
|
|
||||||
entries.forEach(entry => {
|
|
||||||
if (entry.isDirectory() && !entry.name.startsWith('.')) {
|
|
||||||
console.log(` - ${entry.name}`);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
const configContent = fs.readFileSync(configPath, 'utf8');
|
const configContent = fs.readFileSync(configPath, 'utf8');
|
||||||
const config = yaml.load(configContent);
|
const config = yaml.load(configContent);
|
||||||
|
|
||||||
const oldVersion = config.version || '1.0.0';
|
const oldVersion = config.version || '1.0.0';
|
||||||
const newVersion = bumpVersion(oldVersion, bumpType);
|
const newVersion = bumpVersion(oldVersion, bumpType);
|
||||||
|
|
||||||
config.version = newVersion;
|
config.version = newVersion;
|
||||||
|
|
||||||
const updatedYaml = yaml.dump(config, { indent: 2 });
|
const updatedYaml = yaml.dump(config, { indent: 2 });
|
||||||
fs.writeFileSync(configPath, updatedYaml);
|
fs.writeFileSync(configPath, updatedYaml);
|
||||||
|
|
||||||
console.log(`✓ ${packId}: ${oldVersion} → ${newVersion}`);
|
console.log(`✓ ${packId}: ${oldVersion} → ${newVersion}`);
|
||||||
console.log(`\n✓ Successfully bumped ${packId} with ${bumpType} version bump`);
|
console.log(`\n✓ Successfully bumped ${packId} with ${bumpType} version bump`);
|
||||||
console.log('\nNext steps:');
|
console.log('\nNext steps:');
|
||||||
console.log('1. Test the changes');
|
console.log(`1. Test the changes`);
|
||||||
console.log('2. Commit: git add -A && git commit -m "chore: bump ' + packId + ' version (' + bumpType + ')"');
|
console.log(`2. Commit: git add -A && git commit -m "chore: bump ${packId} version (${bumpType})"`);
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error updating version:', error.message);
|
console.error('Error updating version:', error.message);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateVersion();
|
updateVersion();
|
||||||
|
|||||||
@@ -5,27 +5,26 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
function prepare(pluginConfig, context) {
|
// This function runs during the "prepare" step of semantic-release
|
||||||
const { nextRelease, logger } = context;
|
function prepare(_, { nextRelease, logger }) {
|
||||||
|
// Define the path to the installer package.json file
|
||||||
// Path to installer package.json
|
const file = path.join(process.cwd(), 'tools/installer/package.json');
|
||||||
const installerPackagePath = path.join(process.cwd(), 'tools', 'installer', 'package.json');
|
|
||||||
|
// If the file does not exist, skip syncing and log a message
|
||||||
if (!fs.existsSync(installerPackagePath)) {
|
if (!fs.existsSync(file)) return logger.log('Installer package.json not found, skipping');
|
||||||
logger.log('Installer package.json not found, skipping sync');
|
|
||||||
return;
|
// Read and parse the package.json file
|
||||||
}
|
const pkg = JSON.parse(fs.readFileSync(file, 'utf8'));
|
||||||
|
|
||||||
// Read installer package.json
|
// Update the version field with the next release version
|
||||||
const installerPackage = JSON.parse(fs.readFileSync(installerPackagePath, 'utf8'));
|
pkg.version = nextRelease.version;
|
||||||
|
|
||||||
// Update version
|
// Write the updated JSON back to the file
|
||||||
installerPackage.version = nextRelease.version;
|
fs.writeFileSync(file, JSON.stringify(pkg, null, 2) + '\n');
|
||||||
|
|
||||||
// Write back
|
// Log success message
|
||||||
fs.writeFileSync(installerPackagePath, JSON.stringify(installerPackage, null, 2) + '\n');
|
|
||||||
|
|
||||||
logger.log(`Synced installer package.json to version ${nextRelease.version}`);
|
logger.log(`Synced installer package.json to version ${nextRelease.version}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { prepare };
|
// Export the prepare function so semantic-release can use it
|
||||||
|
module.exports = { prepare };
|
||||||
|
|||||||
Reference in New Issue
Block a user