@@ -68,15 +68,25 @@ module.exports = class ColocatedTemplateProcessor extends Plugin {
6868 return ;
6969 }
7070
71- // TODO: deal with alternate extensions (e.g. ts)
72- let possibleJSPath = path . join ( filePathParts . dir , filePathParts . name + '.js' ) ;
73- let hasJSFile = fs . existsSync ( path . join ( this . inputPaths [ 0 ] , possibleJSPath ) ) ;
74-
7571 if ( filePathParts . name === 'template' ) {
7672 filesToCopy . push ( filePath ) ;
7773 return ;
7874 }
7975
76+ let hasBackingClass = false ;
77+ let backingClassPath = path . join ( filePathParts . dir , filePathParts . name ) ;
78+
79+ if ( fs . existsSync ( path . join ( this . inputPaths [ 0 ] , backingClassPath + '.js' ) ) ) {
80+ backingClassPath += '.js' ;
81+ hasBackingClass = true ;
82+ } else if ( fs . existsSync ( path . join ( this . inputPaths [ 0 ] , backingClassPath + '.ts' ) ) ) {
83+ backingClassPath += '.ts' ;
84+ hasBackingClass = true ;
85+ } else {
86+ backingClassPath += '.js' ;
87+ hasBackingClass = false ;
88+ }
89+
8090 let templateContents = fs . readFileSync ( inputPath , { encoding : 'utf8' } ) ;
8191 let jsContents = null ;
8292
@@ -92,12 +102,14 @@ module.exports = class ColocatedTemplateProcessor extends Plugin {
92102 ) } )`;
93103 let prefix = `import { hbs } from 'ember-cli-htmlbars';\nconst __COLOCATED_TEMPLATE__ = ${ hbsInvocation } ;\n` ;
94104
95- logger . debug ( `processing colocated template: ${ filePath } (template-only: ${ hasJSFile } )` ) ;
105+ logger . debug (
106+ `processing colocated template: ${ filePath } (template-only: ${ hasBackingClass } )`
107+ ) ;
96108
97- if ( hasJSFile ) {
109+ if ( hasBackingClass ) {
98110 // add the template, call setComponentTemplate
99111
100- jsContents = fs . readFileSync ( path . join ( this . inputPaths [ 0 ] , possibleJSPath ) , {
112+ jsContents = fs . readFileSync ( path . join ( this . inputPaths [ 0 ] , backingClassPath ) , {
101113 encoding : 'utf8' ,
102114 } ) ;
103115
@@ -114,7 +126,7 @@ module.exports = class ColocatedTemplateProcessor extends Plugin {
114126
115127 jsContents = prefix + jsContents ;
116128
117- let outputPath = path . join ( this . outputPath , possibleJSPath ) ;
129+ let outputPath = path . join ( this . outputPath , backingClassPath ) ;
118130
119131 // TODO: don't speculatively mkdirSync (likely do in a try/catch with ENOENT)
120132 mkdirp . sync ( path . dirname ( outputPath ) ) ;
0 commit comments