File tree Expand file tree Collapse file tree 1 file changed +31
-2
lines changed
Expand file tree Collapse file tree 1 file changed +31
-2
lines changed Original file line number Diff line number Diff line change 55 * This file ensures proper execution when run via npx from GitHub or npm registry
66 */
77
8- // Simply delegate to the CLI tool
9- require ( './cli/bmad-cli.js' ) ;
8+ const { execSync } = require ( 'node:child_process' ) ;
9+ const path = require ( 'node:path' ) ;
10+ const fs = require ( 'node:fs' ) ;
11+
12+ // Check if we're running in an npx temporary directory
13+ const isNpxExecution = __dirname . includes ( '_npx' ) || __dirname . includes ( '.npm' ) ;
14+
15+ if ( isNpxExecution ) {
16+ // Running via npx - spawn child process to preserve user's working directory
17+ const args = process . argv . slice ( 2 ) ;
18+ const bmadCliPath = path . join ( __dirname , 'cli' , 'bmad-cli.js' ) ;
19+
20+ if ( ! fs . existsSync ( bmadCliPath ) ) {
21+ console . error ( 'Error: Could not find bmad-cli.js at' , bmadCliPath ) ;
22+ console . error ( 'Current directory:' , __dirname ) ;
23+ process . exit ( 1 ) ;
24+ }
25+
26+ try {
27+ // Execute CLI from user's working directory (process.cwd()), not npm cache
28+ execSync ( `node "${ bmadCliPath } " ${ args . join ( ' ' ) } ` , {
29+ stdio : 'inherit' ,
30+ cwd : process . cwd ( ) , // This preserves the user's working directory
31+ } ) ;
32+ } catch ( error ) {
33+ process . exit ( error . status || 1 ) ;
34+ }
35+ } else {
36+ // Local execution - use require
37+ require ( './cli/bmad-cli.js' ) ;
38+ }
You can’t perform that action at this time.
0 commit comments