@@ -106,6 +106,34 @@ module.exports = class Migrator {
106106 } ) ;
107107 }
108108
109+ changeComponentStructureToNested ( templateFilePaths ) {
110+ const classFilePaths = this . findClassicComponentClasses ( ) ;
111+
112+ templateFilePaths . forEach ( templateFilePath => {
113+ // Extract '/app/templates/components/nested1/nested-component.hbs'
114+ const filePathFromApp = templateFilePath . slice ( this . projectRoot . length ) ;
115+
116+ // Extract '/nested1/nested-component.hbs'
117+ const filePathFromAppTemplatesComponents = filePathFromApp . slice ( 'app/templates/components/' . length ) ;
118+ const fileExtension = path . extname ( filePathFromAppTemplatesComponents ) ;
119+
120+ // Extract '/nested1/nested-component'
121+ const targetPath = filePathFromAppTemplatesComponents . slice ( 0 , - fileExtension . length ) ;
122+
123+ // Build '[APP_PATH]/app/components/nested1/nested-component/index.hbs'
124+ const newTemplateFilePath = path . join ( this . projectRoot , 'app/components' , targetPath , 'index.hbs' ) ;
125+ moveFile ( templateFilePath , newTemplateFilePath ) ;
126+
127+ // Build '[APP_PATH]/app/components/nested1/nested-component/index.js'
128+ const classFilePath = path . join ( this . projectRoot , 'app/components' , `${ targetPath } .js` ) ;
129+
130+ if ( classFilePaths . includes ( classFilePath ) ) {
131+ const newClassFilePath = path . join ( this . projectRoot , 'app/components' , targetPath , 'index.js' ) ;
132+ moveFile ( classFilePath , newClassFilePath ) ;
133+ }
134+ } ) ;
135+ }
136+
109137 async removeEmptyClassicComponentDirectories ( ) {
110138 const templateFolderPath = path . join ( this . projectRoot , 'app/templates/components' ) ;
111139
@@ -123,6 +151,10 @@ module.exports = class Migrator {
123151
124152 if ( this . newComponentStructure === 'flat' ) {
125153 this . changeComponentStructureToFlat ( templateFilePaths ) ;
154+
155+ } else if ( this . newComponentStructure === 'nested' ) {
156+ this . changeComponentStructureToNested ( templateFilePaths ) ;
157+
126158 }
127159
128160 // Clean up
0 commit comments