From 7e9654f270911a94d013a2efe9582e3c781531ab Mon Sep 17 00:00:00 2001 From: yangjun <290968698@qq.com> Date: Tue, 11 Nov 2025 12:28:59 +0800 Subject: [PATCH] use INIT_CWD as default dir cause it's current working dir --- tools/bmad-npx-wrapper.js | 2 +- tools/cli/bundlers/bundle-web.js | 4 ++-- tools/cli/bundlers/web-bundler.js | 2 +- tools/cli/lib/ui.js | 6 +++--- tools/cli/regenerate-manifests.js | 2 +- tools/flattener/main.js | 8 ++++---- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tools/bmad-npx-wrapper.js b/tools/bmad-npx-wrapper.js index bc63a412..958ede0f 100755 --- a/tools/bmad-npx-wrapper.js +++ b/tools/bmad-npx-wrapper.js @@ -27,7 +27,7 @@ if (isNpxExecution) { // Execute CLI from user's working directory (process.cwd()), not npm cache execSync(`node "${bmadCliPath}" ${args.join(' ')}`, { stdio: 'inherit', - cwd: process.cwd(), // This preserves the user's working directory + cwd: process.env.INIT_CWD || process.cwd(), // This preserves the user's working directory }); } catch (error) { process.exit(error.status || 1); diff --git a/tools/cli/bundlers/bundle-web.js b/tools/cli/bundlers/bundle-web.js index 8bb84868..9a0b56ae 100755 --- a/tools/cli/bundlers/bundle-web.js +++ b/tools/cli/bundlers/bundle-web.js @@ -27,7 +27,7 @@ program .action(async (options) => { try { // Clean output directory first - const outputDir = path.isAbsolute(options.output) ? options.output : path.join(process.cwd(), options.output); + const outputDir = path.isAbsolute(options.output) ? options.output : path.join(process.env.INIT_CWD || process.cwd(), options.output); if (await fs.pathExists(outputDir)) { console.log(chalk.cyan(`🧹 Cleaning ${options.output}...`)); @@ -156,7 +156,7 @@ program .action(async () => { try { const fs = require('fs-extra'); - const outputDir = path.join(process.cwd(), 'web-bundles'); + const outputDir = path.join(process.env.INIT_CWD || process.cwd(), 'web-bundles'); if (await fs.pathExists(outputDir)) { await fs.remove(outputDir); diff --git a/tools/cli/bundlers/web-bundler.js b/tools/cli/bundlers/web-bundler.js index 5109daae..6287c7ea 100644 --- a/tools/cli/bundlers/web-bundler.js +++ b/tools/cli/bundlers/web-bundler.js @@ -28,7 +28,7 @@ class WebBundler { this.discoveredTeams = []; // Temporary directory for generated manifests - this.tempDir = path.join(process.cwd(), '.bundler-temp'); + this.tempDir = path.join(process.env.INIT_CWD || process.cwd(), '.bundler-temp'); this.tempManifestDir = path.join(this.tempDir, 'bmad', '_cfg'); // Bundle statistics diff --git a/tools/cli/lib/ui.js b/tools/cli/lib/ui.js index e0115103..6942c34b 100644 --- a/tools/cli/lib/ui.js +++ b/tools/cli/lib/ui.js @@ -127,7 +127,7 @@ class UI { // Check for existing configured IDEs const { Detector } = require('../installers/lib/core/detector'); const detector = new Detector(); - const bmadDir = path.join(projectDir || process.cwd(), 'bmad'); + const bmadDir = path.join(projectDir || process.env.INIT_CWD || process.cwd(), 'bmad'); const existingInstall = await detector.detect(bmadDir); const configuredIdes = existingInstall.ides || []; @@ -404,12 +404,12 @@ class UI { type: 'input', name: 'directory', message: `Installation directory:`, - default: process.cwd(), + default: process.env.INIT_CWD || process.cwd(), validate: async (input) => this.validateDirectory(input), filter: (input) => { // If empty, use the default if (!input || input.trim() === '') { - return process.cwd(); + return process.env.INIT_CWD || process.cwd(); } return this.expandUserPath(input); }, diff --git a/tools/cli/regenerate-manifests.js b/tools/cli/regenerate-manifests.js index c5a0d48b..ec3c2ade 100644 --- a/tools/cli/regenerate-manifests.js +++ b/tools/cli/regenerate-manifests.js @@ -4,7 +4,7 @@ const { ManifestGenerator } = require('./installers/lib/core/manifest-generator' async function regenerateManifests() { const generator = new ManifestGenerator(); const targetDir = process.argv[2] || 'z1'; - const bmadDir = path.join(process.cwd(), targetDir, 'bmad'); + const bmadDir = path.join(process.env.INIT_CWD || process.cwd(), targetDir, 'bmad'); // List of modules to include in manifests const selectedModules = ['bmb', 'bmm', 'cis']; diff --git a/tools/flattener/main.js b/tools/flattener/main.js index 72bb42f9..f7dfcaab 100644 --- a/tools/flattener/main.js +++ b/tools/flattener/main.js @@ -70,7 +70,7 @@ program .name('bmad-flatten') .description('BMad-Method codebase flattener tool') .version('1.0.0') - .option('-i, --input ', 'Input directory to flatten', process.cwd()) + .option('-i, --input ', 'Input directory to flatten', process.env.INIT_CWD || process.cwd()) .option('-o, --output ', 'Output file path', 'flattened-codebase.xml') .action(async (options) => { let inputDir = path.resolve(options.input); @@ -83,7 +83,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'); if (detectedRoot) { @@ -95,12 +95,12 @@ 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')); } } 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')); } }