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 {
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.resolver = new DependencyResolver(this.rootDir);
this.templatePath = path.join(

View File

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

View File

@ -70,7 +70,7 @@ program
.name('bmad-flatten')
.description('BMAD-METHOD™ codebase flattener tool')
.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')
.action(async (options) => {
let inputDir = path.resolve(options.input);
@ -87,7 +87,7 @@ program
const noPathArguments = !userSpecifiedInput && !userSpecifiedOutput;
if (noPathArguments) {
const detectedRoot = await findProjectRoot(process.cwd());
const detectedRoot = await findProjectRoot(process.env.INIT_CWD || process.cwd());
const suggestedOutput = detectedRoot
? path.join(detectedRoot, 'flattened-codebase.xml')
: path.resolve('flattened-codebase.xml');
@ -101,7 +101,10 @@ program
inputDir = detectedRoot;
outputPath = suggestedOutput;
} 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(
'Enter output file path',
path.join(inputDir, 'flattened-codebase.xml'),
@ -109,7 +112,10 @@ program
}
} else {
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(
'Enter output file path',
path.join(inputDir, 'flattened-codebase.xml'),

View File

@ -181,7 +181,7 @@ program
program
.command('flatten')
.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')
.action(async (options) => {
try {
@ -216,7 +216,7 @@ async function promptInstallation() {
type: 'input',
name: 'directory',
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) => {
if (!input.trim()) {
return 'Please enter a valid project path';

View File

@ -1963,7 +1963,7 @@ class Installer {
async findInstallation() {
// 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)) {
const bmadDir = path.join(currentDir, '.bmad-core');
@ -1977,10 +1977,13 @@ class Installer {
}
// Also check if we're inside a .bmad-core directory
if (path.basename(process.cwd()) === '.bmad-core') {
const manifestPath = path.join(process.cwd(), 'install-manifest.yaml');
if (path.basename(process.env.INIT_CWD || process.cwd()) === '.bmad-core') {
const manifestPath = path.join(
process.env.INIT_CWD || process.cwd(),
'install-manifest.yaml',
);
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_], {
stdio: 'inherit',
cwd: process.cwd(),
cwd: process.env.INIT_CWD || process.cwd(),
});
child.on('exit', (code) => {

View File

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