@cloudkinetix/bmad-enhanced
Version:
Cloud-Kinetix enhanced fork of BMAD-METHOD - Breakthrough Method of Agile AI-driven Development with robust versioning and unified validation.
103 lines (84 loc) • 3.32 kB
JavaScript
/**
* Simplified Web Builder for CK Expansion Packs
*
* Builds browser-compatible bundles for CK expansion packs only.
*/
const fs = require('fs-extra');
const path = require('path');
const yaml = require('js-yaml');
class WebBuilder {
constructor(options = {}) {
this.rootDir = options.rootDir || process.cwd();
this.expansionPacksDir = path.join(__dirname, '../../expansion-packs');
this.outputDir = path.join(this.rootDir, 'dist/expansion-packs');
}
async buildExpansionPack(packName, options = {}) {
const packDir = path.join(this.expansionPacksDir, packName);
if (!await fs.pathExists(packDir)) {
throw new Error(`Expansion pack not found: ${packName}`);
}
// Only build CK expansion packs
if (!packName.startsWith('ck-')) {
console.log(`Skipping non-CK expansion pack: ${packName}`);
return;
}
console.log(`Building web bundle for ${packName}...`);
// Create output directory
const packOutputDir = path.join(this.outputDir, packName, 'teams');
await fs.ensureDir(packOutputDir);
// Find team files
const teamsDir = path.join(packDir, 'agent-teams');
if (await fs.pathExists(teamsDir)) {
const teamFiles = await fs.readdir(teamsDir);
for (const teamFile of teamFiles) {
if (teamFile.endsWith('.yaml')) {
await this.buildTeamBundle(packName, path.join(teamsDir, teamFile), packOutputDir);
}
}
}
}
async buildTeamBundle(packName, teamFilePath, outputDir) {
const teamName = path.basename(teamFilePath, '.yaml');
const outputFile = path.join(outputDir, `${teamName}.txt`);
// Read team configuration
const teamContent = await fs.readFile(teamFilePath, 'utf8');
const teamConfig = yaml.load(teamContent);
// Build bundle content
let bundleContent = `# ${teamConfig.name || teamName}\n\n`;
bundleContent += `${teamConfig.description || ''}\n\n`;
bundleContent += '---\n\n';
// Add agents
if (teamConfig.agents) {
for (const agentRef of teamConfig.agents) {
const agentPath = path.join(this.expansionPacksDir, packName, 'agents', `${agentRef}.md`);
if (await fs.pathExists(agentPath)) {
const agentContent = await fs.readFile(agentPath, 'utf8');
bundleContent += `## Agent: ${agentRef}\n\n`;
bundleContent += agentContent + '\n\n---\n\n';
}
}
}
// Write bundle
await fs.writeFile(outputFile, bundleContent);
console.log(` Created: ${path.relative(this.rootDir, outputFile)}`);
}
async buildAllExpansionPacks(options = {}) {
const entries = await fs.readdir(this.expansionPacksDir, { withFileTypes: true });
for (const entry of entries) {
if (entry.isDirectory() && entry.name.startsWith('ck-')) {
try {
await this.buildExpansionPack(entry.name, options);
} catch (error) {
console.warn(`Failed to build ${entry.name}: ${error.message}`);
}
}
}
}
async listExpansionPacks() {
const entries = await fs.readdir(this.expansionPacksDir, { withFileTypes: true });
return entries
.filter(e => e.isDirectory() && e.name.startsWith('ck-'))
.map(e => e.name);
}
}
module.exports = WebBuilder;