Files
BMAD-METHOD/tools/bmad-npx-wrapper.js
manjaroblack 17e7d14cc2 fix: honor original working directory when running npx installer and searching for task files
(cherry picked from commit 6a5a597fe39bc75379f54bedc1616bfab283dfa1)
2025-08-18 19:34:09 -05:00

43 lines
1.3 KiB
JavaScript
Executable File

#!/usr/bin/env node
/**
* BMad Method CLI - Direct execution wrapper for npx
* This file ensures proper execution when run via npx from GitHub
*/
const { execSync } = require('node:child_process');
const path = require('node:path');
const fs = require('node:fs');
// Check if we're running in an npx temporary directory
const isNpxExecution = __dirname.includes('_npx') || __dirname.includes('.npm');
// If running via npx, we need to handle things differently
if (isNpxExecution) {
const arguments_ = process.argv.slice(2);
// Use the installer for all commands
const bmadScriptPath = path.join(__dirname, 'installer', 'bin', 'bmad.js');
if (!fs.existsSync(bmadScriptPath)) {
console.error('Error: Could not find bmad.js at', bmadScriptPath);
console.error('Current directory:', __dirname);
process.exit(1);
}
try {
// Honor the directory where the user invoked npx from
const originalCwd = process.env.INIT_CWD || process.env.PWD || process.cwd();
execSync(`node "${bmadScriptPath}" ${arguments_.join(' ')}`, {
stdio: 'inherit',
cwd: originalCwd,
env: { ...process.env, BMAD_ORIGINAL_CWD: originalCwd },
});
} catch (error) {
process.exit(error.status || 1);
}
} else {
// Local execution - use installer for all commands
require('./installer/bin/bmad.js');
}