Files
BMAD-METHOD/tools/cli.js
manjaroblack a80ea150f2 eat: enhance flattener tool with improved CLI integration and custom directory support (#372)
* feat(cli): move flatten command to installer and update docs

Refactor the flatten command from tools/cli.js to tools/installer/bin/bmad.js for better integration. Add support for custom input directory and improve error handling. Update documentation in README.md and working-in-the-brownfield.md to reflect new command usage. Also clean up package-lock.json and add it to .gitignore.

* chore: update gitignore and add package-lock.json for installer tool

Remove package-lock.json from root gitignore since it's now needed for the installer tool
Add package-lock.json with dependencies for the bmad-method installer

---------

Co-authored-by: Devin Stagner <devin@blackstag.family>
2025-07-27 18:02:08 -05:00

152 lines
4.8 KiB
JavaScript

#!/usr/bin/env node
const { Command } = require('commander');
const WebBuilder = require('./builders/web-builder');
const V3ToV4Upgrader = require('./upgraders/v3-to-v4-upgrader');
const IdeSetup = require('./installer/lib/ide-setup');
const path = require('path');
const program = new Command();
program
.name('bmad-build')
.description('BMad-Method build tool for creating web bundles')
.version('4.0.0');
program
.command('build')
.description('Build web bundles for agents and teams')
.option('-a, --agents-only', 'Build only agent bundles')
.option('-t, --teams-only', 'Build only team bundles')
.option('-e, --expansions-only', 'Build only expansion pack bundles')
.option('--no-expansions', 'Skip building expansion packs')
.option('--no-clean', 'Skip cleaning output directories')
.action(async (options) => {
const builder = new WebBuilder({
rootDir: process.cwd()
});
try {
if (options.clean) {
console.log('Cleaning output directories...');
await builder.cleanOutputDirs();
}
if (options.expansionsOnly) {
console.log('Building expansion pack bundles...');
await builder.buildAllExpansionPacks({ clean: false });
} else {
if (!options.teamsOnly) {
console.log('Building agent bundles...');
await builder.buildAgents();
}
if (!options.agentsOnly) {
console.log('Building team bundles...');
await builder.buildTeams();
}
if (!options.noExpansions) {
console.log('Building expansion pack bundles...');
await builder.buildAllExpansionPacks({ clean: false });
}
}
console.log('Build completed successfully!');
} catch (error) {
console.error('Build failed:', error.message);
process.exit(1);
}
});
program
.command('build:expansions')
.description('Build web bundles for all expansion packs')
.option('--expansion <name>', 'Build specific expansion pack only')
.option('--no-clean', 'Skip cleaning output directories')
.action(async (options) => {
const builder = new WebBuilder({
rootDir: process.cwd()
});
try {
if (options.expansion) {
console.log(`Building expansion pack: ${options.expansion}`);
await builder.buildExpansionPack(options.expansion, { clean: options.clean });
} else {
console.log('Building all expansion packs...');
await builder.buildAllExpansionPacks({ clean: options.clean });
}
console.log('Expansion pack build completed successfully!');
} catch (error) {
console.error('Expansion pack build failed:', error.message);
process.exit(1);
}
});
program
.command('list:agents')
.description('List all available agents')
.action(async () => {
const builder = new WebBuilder({ rootDir: process.cwd() });
const agents = await builder.resolver.listAgents();
console.log('Available agents:');
agents.forEach(agent => console.log(` - ${agent}`));
});
program
.command('list:expansions')
.description('List all available expansion packs')
.action(async () => {
const builder = new WebBuilder({ rootDir: process.cwd() });
const expansions = await builder.listExpansionPacks();
console.log('Available expansion packs:');
expansions.forEach(expansion => console.log(` - ${expansion}`));
});
program
.command('validate')
.description('Validate agent and team configurations')
.action(async () => {
const builder = new WebBuilder({ rootDir: process.cwd() });
try {
// Validate by attempting to build all agents and teams
const agents = await builder.resolver.listAgents();
const teams = await builder.resolver.listTeams();
console.log('Validating agents...');
for (const agent of agents) {
await builder.resolver.resolveAgentDependencies(agent);
console.log(`${agent}`);
}
console.log('\nValidating teams...');
for (const team of teams) {
await builder.resolver.resolveTeamDependencies(team);
console.log(`${team}`);
}
console.log('\nAll configurations are valid!');
} catch (error) {
console.error('Validation failed:', error.message);
process.exit(1);
}
});
program
.command('upgrade')
.description('Upgrade a BMad-Method V3 project to V4')
.option('-p, --project <path>', 'Path to V3 project (defaults to current directory)')
.option('--dry-run', 'Show what would be changed without making changes')
.option('--no-backup', 'Skip creating backup (not recommended)')
.action(async (options) => {
const upgrader = new V3ToV4Upgrader();
await upgrader.upgrade({
projectPath: options.project,
dryRun: options.dryRun,
backup: options.backup
});
});
program.parse();