@@ -33,10 +33,101 @@ class UI {
3333 await installer . handleLegacyV4Migration ( confirmedDirectory , legacyV4 ) ;
3434 }
3535
36- // Check if there's an existing BMAD installation
37- const fs = require ( 'fs-extra' ) ;
38- const path = require ( 'node:path' ) ;
39- const bmadDir = await installer . findBmadDir ( confirmedDirectory ) ;
36+ // Check for legacy folders and prompt for rename before showing any menus
37+ let hasLegacyCfg = false ;
38+ let hasLegacyBmadFolder = false ;
39+ let bmadDir = null ;
40+ let legacyBmadPath = null ;
41+
42+ // First check for legacy .bmad folder (instead of _bmad)
43+ const entries = await fs . readdir ( confirmedDirectory , { withFileTypes : true } ) ;
44+ for ( const entry of entries ) {
45+ if ( entry . isDirectory ( ) && entry . name === '.bmad' ) {
46+ hasLegacyBmadFolder = true ;
47+ legacyBmadPath = path . join ( confirmedDirectory , '.bmad' ) ;
48+ bmadDir = legacyBmadPath ;
49+
50+ // Check if it has _cfg folder
51+ const cfgPath = path . join ( legacyBmadPath , '_cfg' ) ;
52+ if ( await fs . pathExists ( cfgPath ) ) {
53+ hasLegacyCfg = true ;
54+ }
55+ break ;
56+ }
57+ }
58+
59+ // If no .bmad found, check for current installations
60+ if ( ! hasLegacyBmadFolder ) {
61+ const bmadResult = await installer . findBmadDir ( confirmedDirectory ) ;
62+ bmadDir = bmadResult . bmadDir ;
63+ hasLegacyCfg = bmadResult . hasLegacyCfg ;
64+ }
65+
66+ if ( hasLegacyBmadFolder || hasLegacyCfg ) {
67+ console . log ( chalk . yellow ( '\n⚠️ Legacy folder structure detected' ) ) ;
68+
69+ let message = 'The following folders need to be renamed:\n' ;
70+ if ( hasLegacyBmadFolder ) {
71+ message += chalk . dim ( ` • ".bmad" → "_bmad"\n` ) ;
72+ }
73+ if ( hasLegacyCfg ) {
74+ message += chalk . dim ( ` • "_cfg" → "_config"\n` ) ;
75+ }
76+ console . log ( message ) ;
77+
78+ const { shouldRename } = await inquirer . prompt ( [
79+ {
80+ type : 'confirm' ,
81+ name : 'shouldRename' ,
82+ message : 'Would you like the installer to rename these folders for you?' ,
83+ default : true ,
84+ } ,
85+ ] ) ;
86+
87+ if ( ! shouldRename ) {
88+ console . log ( chalk . red ( '\n❌ Installation cancelled' ) ) ;
89+ console . log ( chalk . dim ( 'You must manually rename the folders before proceeding:' ) ) ;
90+ if ( hasLegacyBmadFolder ) {
91+ console . log ( chalk . dim ( ` • Rename ".bmad" to "_bmad"` ) ) ;
92+ }
93+ if ( hasLegacyCfg ) {
94+ console . log ( chalk . dim ( ` • Rename "_cfg" to "_config"` ) ) ;
95+ }
96+ process . exit ( 0 ) ;
97+ return ;
98+ }
99+
100+ // Perform the renames
101+ const ora = require ( 'ora' ) ;
102+ const spinner = ora ( 'Updating folder structure...' ) . start ( ) ;
103+
104+ try {
105+ // First rename .bmad to _bmad if needed
106+ if ( hasLegacyBmadFolder ) {
107+ const newBmadPath = path . join ( confirmedDirectory , '_bmad' ) ;
108+ await fs . move ( legacyBmadPath , newBmadPath ) ;
109+ bmadDir = newBmadPath ;
110+ spinner . succeed ( 'Renamed ".bmad" to "_bmad"' ) ;
111+ }
112+
113+ // Then rename _cfg to _config if needed
114+ if ( hasLegacyCfg ) {
115+ spinner . start ( 'Renaming configuration folder...' ) ;
116+ const oldCfgPath = path . join ( bmadDir , '_cfg' ) ;
117+ const newCfgPath = path . join ( bmadDir , '_config' ) ;
118+ await fs . move ( oldCfgPath , newCfgPath ) ;
119+ spinner . succeed ( 'Renamed "_cfg" to "_config"' ) ;
120+ }
121+
122+ spinner . succeed ( 'Folder structure updated successfully' ) ;
123+ } catch ( error ) {
124+ spinner . fail ( 'Failed to update folder structure' ) ;
125+ console . error ( chalk . red ( `Error: ${ error . message } ` ) ) ;
126+ process . exit ( 1 ) ;
127+ }
128+ }
129+
130+ // Check if there's an existing BMAD installation (after any folder renames)
40131 const hasExistingInstall = await fs . pathExists ( bmadDir ) ;
41132
42133 // Always ask for custom content, but we'll handle it differently for new installs
@@ -190,7 +281,8 @@ class UI {
190281 const { Installer } = require ( '../installers/lib/core/installer' ) ;
191282 const detector = new Detector ( ) ;
192283 const installer = new Installer ( ) ;
193- const bmadDir = await installer . findBmadDir ( projectDir || process . cwd ( ) ) ;
284+ const bmadResult = await installer . findBmadDir ( projectDir || process . cwd ( ) ) ;
285+ const bmadDir = bmadResult . bmadDir ;
194286 const existingInstall = await detector . detect ( bmadDir ) ;
195287 const configuredIdes = existingInstall . ides || [ ] ;
196288
0 commit comments