@@ -120,28 +120,23 @@ module.exports = {
120120 return ;
121121 }
122122
123- var returns = [ ] ;
124- var modulePath = path . resolve ( process . env . PWD , this . dynamicPath . appRoot , 'app.module.ts' ) ;
125- var classifiedName =
126- stringUtils . classify ( `${ options . entity . name } - ${ options . originBlueprintName } ` ) ;
127- var importPath = `'./ ${ options . entity . name } /` +
128- stringUtils . dasherize ( ` ${ options . entity . name } .component';` ) ;
123+ const returns = [ ] ;
124+ const modulePath = path . join ( this . project . root , this . dynamicPath . appRoot , 'app.module.ts' ) ;
125+ const className = stringUtils . classify ( ` ${ options . entity . name } Component` ) ;
126+ const fileName = stringUtils . dasherize ( `${ options . entity . name } .component ` ) ;
127+ const componentDir = path . relative ( this . dynamicPath . appRoot , this . generatePath ) ;
128+ const importPath = componentDir ? `./ ${ componentDir } / ${ fileName } ` : `./ ${ fileName } ` ;
129129
130130 if ( ! options . flat ) {
131- returns . push ( function ( ) {
132- return addBarrelRegistration ( this , this . generatePath )
133- } ) ;
131+ returns . push ( addBarrelRegistration ( this , componentDir ) ) ;
134132 } else {
135- returns . push ( function ( ) {
136- return addBarrelRegistration (
137- this ,
138- this . generatePath ,
139- options . entity . name + '.component' )
140- } ) ;
133+ returns . push ( addBarrelRegistration ( this , componentDir , fileName ) ) ;
141134 }
142135
143136 if ( ! options [ 'skip-import' ] ) {
144- returns . push ( astUtils . importComponent ( modulePath , classifiedName , importPath ) ) ;
137+ returns . push (
138+ astUtils . addComponentToModule ( modulePath , className , importPath )
139+ . then ( change => change . apply ( ) ) ) ;
145140 }
146141
147142 return Promise . all ( returns ) ;
0 commit comments