@@ -6,10 +6,10 @@ const { moveFile, removeDirs } = require('./utils/file')
66
77module . exports = class Migrator {
88 constructor ( options ) {
9- const { projectRoot, newComponentStructure } = options ;
9+ const { projectRoot, structure } = options ;
1010
1111 this . projectRoot = projectRoot ;
12- this . newComponentStructure = newComponentStructure ;
12+ this . structure = structure ;
1313 }
1414
1515 findClassicComponentTemplates ( ) {
@@ -21,7 +21,7 @@ module.exports = class Migrator {
2121
2222 findClassicComponentClasses ( ) {
2323 const classFolderPath = path . join ( this . projectRoot , 'app/components' ) ;
24- const classFilePaths = glob . sync ( `${ classFolderPath } /**/*.js ` ) ;
24+ const classFilePaths = glob . sync ( `${ classFolderPath } /**/*.{js,ts} ` ) ;
2525
2626 return classFilePaths ;
2727 }
@@ -75,6 +75,15 @@ module.exports = class Migrator {
7575 // Extract '/app/templates/components/nested1/nested-component.hbs'
7676 let filePathFromApp = templateFilePath . slice ( this . projectRoot . length ) ;
7777
78+ /*
79+ When Ember sees `{{partial "foo"}}`, it will look for the template in
80+ two locations:
81+
82+ - `app/templates/foo.hbs`
83+ - `app/templates/-foo.hbs`
84+
85+ If `filePathFromApp` matches the latter pattern, we remove the hyphen.
86+ */
7887 if ( / \/ \- [ \w \- ] + \. h b s / . test ( filePathFromApp ) ) {
7988 filePathFromApp = filePathFromApp . replace ( '/-' , '/' ) ;
8089 }
@@ -125,11 +134,19 @@ module.exports = class Migrator {
125134 moveFile ( templateFilePath , newTemplateFilePath ) ;
126135
127136 // Build '[APP_PATH]/app/components/nested1/nested-component/index.js'
128- const classFilePath = path . join ( this . projectRoot , 'app/components' , `${ targetPath } .js` ) ;
137+ const classFilePath = {
138+ js : path . join ( this . projectRoot , 'app/components' , `${ targetPath } .js` ) ,
139+ ts : path . join ( this . projectRoot , 'app/components' , `${ targetPath } .ts` )
140+ } ;
129141
130- if ( classFilePaths . includes ( classFilePath ) ) {
142+ if ( classFilePaths . includes ( classFilePath . js ) ) {
131143 const newClassFilePath = path . join ( this . projectRoot , 'app/components' , targetPath , 'index.js' ) ;
132- moveFile ( classFilePath , newClassFilePath ) ;
144+ moveFile ( classFilePath . js , newClassFilePath ) ;
145+
146+ } else if ( classFilePaths . includes ( classFilePath . ts ) ) {
147+ const newClassFilePath = path . join ( this . projectRoot , 'app/components' , targetPath , 'index.ts' ) ;
148+ moveFile ( classFilePath . ts , newClassFilePath ) ;
149+
133150 }
134151 } ) ;
135152 }
@@ -149,10 +166,10 @@ module.exports = class Migrator {
149166 templateFilePaths = this . skipTemplatesUsedAsLayoutName ( templateFilePaths ) ;
150167 templateFilePaths = this . skipTemplatesUsedAsPartial ( templateFilePaths ) ;
151168
152- if ( this . newComponentStructure === 'flat' ) {
169+ if ( this . structure === 'flat' ) {
153170 this . changeComponentStructureToFlat ( templateFilePaths ) ;
154171
155- } else if ( this . newComponentStructure === 'nested' ) {
172+ } else if ( this . structure === 'nested' ) {
156173 this . changeComponentStructureToNested ( templateFilePaths ) ;
157174
158175 }
0 commit comments