@@ -2,6 +2,7 @@ var path = require('path');
22var chalk = require ( 'chalk' ) ;
33var Blueprint = require ( 'ember-cli/lib/models/blueprint' ) ;
44var dynamicPathParser = require ( '../../utilities/dynamic-path-parser' ) ;
5+ var findParentModule = require ( '../../utilities/find-parent-module' ) ;
56var getFiles = Blueprint . prototype . files ;
67const stringUtils = require ( 'ember-cli-string-utils' ) ;
78const astUtils = require ( '../../utilities/ast-utils' ) ;
@@ -17,9 +18,17 @@ module.exports = {
1718 { name : 'spec' , type : Boolean , default : true }
1819 ] ,
1920
21+ beforeInstall : function ( ) {
22+ try {
23+ this . pathToModule = findParentModule ( this . project , this . dynamicPath . dir ) ;
24+ } catch ( e ) {
25+ throw `Error locating module for declaration\n\t${ e } ` ;
26+ }
27+ } ,
28+
2029 normalizeEntityName : function ( entityName ) {
2130 var parsedPath = dynamicPathParser ( this . project , entityName ) ;
22-
31+
2332 this . dynamicPath = parsedPath ;
2433
2534 var defaultPrefix = '' ;
@@ -100,15 +109,14 @@ module.exports = {
100109 }
101110
102111 const returns = [ ] ;
103- const modulePath = path . join ( this . project . root , this . dynamicPath . appRoot , 'app.module.ts' ) ;
104112 const className = stringUtils . classify ( `${ options . entity . name } Component` ) ;
105113 const fileName = stringUtils . dasherize ( `${ options . entity . name } .component` ) ;
106114 const componentDir = path . relative ( this . dynamicPath . appRoot , this . generatePath ) ;
107115 const importPath = componentDir ? `./${ componentDir } /${ fileName } ` : `./${ fileName } ` ;
108116
109117 if ( ! options [ 'skip-import' ] ) {
110118 returns . push (
111- astUtils . addComponentToModule ( modulePath , className , importPath )
119+ astUtils . addComponentToModule ( this . pathToModule , className , importPath )
112120 . then ( change => change . apply ( ) ) ) ;
113121 }
114122
0 commit comments