use INIT_CWD as default dir cause it's current working dir

This commit is contained in:
yangjun 2025-09-18 20:20:48 +08:00
parent f09e282d72
commit 97b7416a1c
6 changed files with 27 additions and 18 deletions

View File

@ -5,7 +5,7 @@ const yamlUtilities = require('../lib/yaml-utils');
class WebBuilder { class WebBuilder {
constructor(options = {}) { constructor(options = {}) {
this.rootDir = options.rootDir || process.cwd(); this.rootDir = options.rootDir || process.env.INIT_CWD || process.cwd();
this.outputDirs = options.outputDirs || [path.join(this.rootDir, 'dist')]; this.outputDirs = options.outputDirs || [path.join(this.rootDir, 'dist')];
this.resolver = new DependencyResolver(this.rootDir); this.resolver = new DependencyResolver(this.rootDir);
this.templatePath = path.join( this.templatePath = path.join(

View File

@ -21,7 +21,7 @@ program
.option('--no-clean', 'Skip cleaning output directories') .option('--no-clean', 'Skip cleaning output directories')
.action(async (options) => { .action(async (options) => {
const builder = new WebBuilder({ const builder = new WebBuilder({
rootDir: process.cwd(), rootDir: process.env.INIT_CWD || process.cwd(),
}); });
try { try {
@ -64,7 +64,7 @@ program
.option('--no-clean', 'Skip cleaning output directories') .option('--no-clean', 'Skip cleaning output directories')
.action(async (options) => { .action(async (options) => {
const builder = new WebBuilder({ const builder = new WebBuilder({
rootDir: process.cwd(), rootDir: process.env.INIT_CWD || process.cwd(),
}); });
try { try {
@ -87,7 +87,7 @@ program
.command('list:agents') .command('list:agents')
.description('List all available agents') .description('List all available agents')
.action(async () => { .action(async () => {
const builder = new WebBuilder({ rootDir: process.cwd() }); const builder = new WebBuilder({ rootDir: process.env.INIT_CWD || process.cwd() });
const agents = await builder.resolver.listAgents(); const agents = await builder.resolver.listAgents();
console.log('Available agents:'); console.log('Available agents:');
for (const agent of agents) console.log(` - ${agent}`); for (const agent of agents) console.log(` - ${agent}`);
@ -98,7 +98,7 @@ program
.command('list:expansions') .command('list:expansions')
.description('List all available expansion packs') .description('List all available expansion packs')
.action(async () => { .action(async () => {
const builder = new WebBuilder({ rootDir: process.cwd() }); const builder = new WebBuilder({ rootDir: process.env.INIT_CWD || process.cwd() });
const expansions = await builder.listExpansionPacks(); const expansions = await builder.listExpansionPacks();
console.log('Available expansion packs:'); console.log('Available expansion packs:');
for (const expansion of expansions) console.log(` - ${expansion}`); for (const expansion of expansions) console.log(` - ${expansion}`);
@ -109,7 +109,7 @@ program
.command('validate') .command('validate')
.description('Validate agent and team configurations') .description('Validate agent and team configurations')
.action(async () => { .action(async () => {
const builder = new WebBuilder({ rootDir: process.cwd() }); const builder = new WebBuilder({ rootDir: process.env.INIT_CWD || process.cwd() });
try { try {
// Validate by attempting to build all agents and teams // Validate by attempting to build all agents and teams
const agents = await builder.resolver.listAgents(); const agents = await builder.resolver.listAgents();

View File

@ -70,7 +70,7 @@ program
.name('bmad-flatten') .name('bmad-flatten')
.description('BMAD-METHOD™ codebase flattener tool') .description('BMAD-METHOD™ codebase flattener tool')
.version('1.0.0') .version('1.0.0')
.option('-i, --input <path>', 'Input directory to flatten', process.cwd()) .option('-i, --input <path>', 'Input directory to flatten', process.env.INIT_CWD || process.cwd())
.option('-o, --output <path>', 'Output file path', 'flattened-codebase.xml') .option('-o, --output <path>', 'Output file path', 'flattened-codebase.xml')
.action(async (options) => { .action(async (options) => {
let inputDir = path.resolve(options.input); let inputDir = path.resolve(options.input);
@ -87,7 +87,7 @@ program
const noPathArguments = !userSpecifiedInput && !userSpecifiedOutput; const noPathArguments = !userSpecifiedInput && !userSpecifiedOutput;
if (noPathArguments) { if (noPathArguments) {
const detectedRoot = await findProjectRoot(process.cwd()); const detectedRoot = await findProjectRoot(process.env.INIT_CWD || process.cwd());
const suggestedOutput = detectedRoot const suggestedOutput = detectedRoot
? path.join(detectedRoot, 'flattened-codebase.xml') ? path.join(detectedRoot, 'flattened-codebase.xml')
: path.resolve('flattened-codebase.xml'); : path.resolve('flattened-codebase.xml');
@ -101,7 +101,10 @@ program
inputDir = detectedRoot; inputDir = detectedRoot;
outputPath = suggestedOutput; outputPath = suggestedOutput;
} else { } else {
inputDir = await promptPath('Enter input directory path', process.cwd()); inputDir = await promptPath(
'Enter input directory path',
process.env.INIT_CWD || process.cwd(),
);
outputPath = await promptPath( outputPath = await promptPath(
'Enter output file path', 'Enter output file path',
path.join(inputDir, 'flattened-codebase.xml'), path.join(inputDir, 'flattened-codebase.xml'),
@ -109,7 +112,10 @@ program
} }
} else { } else {
console.log('Could not auto-detect a project root.'); console.log('Could not auto-detect a project root.');
inputDir = await promptPath('Enter input directory path', process.cwd()); inputDir = await promptPath(
'Enter input directory path',
process.env.INIT_CWD || process.cwd(),
);
outputPath = await promptPath( outputPath = await promptPath(
'Enter output file path', 'Enter output file path',
path.join(inputDir, 'flattened-codebase.xml'), path.join(inputDir, 'flattened-codebase.xml'),

View File

@ -181,7 +181,7 @@ program
program program
.command('flatten') .command('flatten')
.description('Flatten codebase to XML format') .description('Flatten codebase to XML format')
.option('-i, --input <path>', 'Input directory to flatten', process.cwd()) .option('-i, --input <path>', 'Input directory to flatten', process.env.INIT_CWD || process.cwd())
.option('-o, --output <path>', 'Output file path', 'flattened-codebase.xml') .option('-o, --output <path>', 'Output file path', 'flattened-codebase.xml')
.action(async (options) => { .action(async (options) => {
try { try {
@ -216,7 +216,7 @@ async function promptInstallation() {
type: 'input', type: 'input',
name: 'directory', name: 'directory',
message: 'Enter the full path to your project directory where BMad should be installed:', message: 'Enter the full path to your project directory where BMad should be installed:',
default: path.resolve('.'), default: path.resolve(process.env.INIT_CWD || '.'),
validate: (input) => { validate: (input) => {
if (!input.trim()) { if (!input.trim()) {
return 'Please enter a valid project path'; return 'Please enter a valid project path';

View File

@ -1963,7 +1963,7 @@ class Installer {
async findInstallation() { async findInstallation() {
// Look for .bmad-core in current directory or parent directories // Look for .bmad-core in current directory or parent directories
let currentDir = process.cwd(); let currentDir = process.env.INIT_CWD || process.cwd();
while (currentDir !== path.dirname(currentDir)) { while (currentDir !== path.dirname(currentDir)) {
const bmadDir = path.join(currentDir, '.bmad-core'); const bmadDir = path.join(currentDir, '.bmad-core');
@ -1977,10 +1977,13 @@ class Installer {
} }
// Also check if we're inside a .bmad-core directory // Also check if we're inside a .bmad-core directory
if (path.basename(process.cwd()) === '.bmad-core') { if (path.basename(process.env.INIT_CWD || process.cwd()) === '.bmad-core') {
const manifestPath = path.join(process.cwd(), 'install-manifest.yaml'); const manifestPath = path.join(
process.env.INIT_CWD || process.cwd(),
'install-manifest.yaml',
);
if (await fileManager.pathExists(manifestPath)) { if (await fileManager.pathExists(manifestPath)) {
return path.dirname(process.cwd()); // Return parent directory return path.dirname(process.env.INIT_CWD || process.cwd()); // Return parent directory
} }
} }
@ -2001,7 +2004,7 @@ class Installer {
const child = spawn('node', [flattenerPath, ...arguments_], { const child = spawn('node', [flattenerPath, ...arguments_], {
stdio: 'inherit', stdio: 'inherit',
cwd: process.cwd(), cwd: process.env.INIT_CWD || process.cwd(),
}); });
child.on('exit', (code) => { child.on('exit', (code) => {

View File

@ -109,7 +109,7 @@ class V3ToV4Upgrader {
type: 'input', type: 'input',
name: 'projectPath', name: 'projectPath',
message: 'Please enter the path to your V3 project:', message: 'Please enter the path to your V3 project:',
default: process.cwd(), default: process.env.INIT_CWD || process.cwd(),
}, },
]); ]);