@@ -2,6 +2,7 @@ var path = require('path');
2
2
var chalk = require ( 'chalk' ) ;
3
3
var Blueprint = require ( 'ember-cli/lib/models/blueprint' ) ;
4
4
var dynamicPathParser = require ( '../../utilities/dynamic-path-parser' ) ;
5
+ var findParentModule = require ( '../../utilities/find-parent-module' ) ;
5
6
var getFiles = Blueprint . prototype . files ;
6
7
const stringUtils = require ( 'ember-cli-string-utils' ) ;
7
8
const astUtils = require ( '../../utilities/ast-utils' ) ;
@@ -17,9 +18,17 @@ module.exports = {
17
18
{ name : 'spec' , type : Boolean , default : true }
18
19
] ,
19
20
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
+
20
29
normalizeEntityName : function ( entityName ) {
21
30
var parsedPath = dynamicPathParser ( this . project , entityName ) ;
22
-
31
+
23
32
this . dynamicPath = parsedPath ;
24
33
25
34
var defaultPrefix = '' ;
@@ -100,15 +109,14 @@ module.exports = {
100
109
}
101
110
102
111
const returns = [ ] ;
103
- const modulePath = path . join ( this . project . root , this . dynamicPath . appRoot , 'app.module.ts' ) ;
104
112
const className = stringUtils . classify ( `${ options . entity . name } Component` ) ;
105
113
const fileName = stringUtils . dasherize ( `${ options . entity . name } .component` ) ;
106
114
const componentDir = path . relative ( this . dynamicPath . appRoot , this . generatePath ) ;
107
115
const importPath = componentDir ? `./${ componentDir } /${ fileName } ` : `./${ fileName } ` ;
108
116
109
117
if ( ! options [ 'skip-import' ] ) {
110
118
returns . push (
111
- astUtils . addComponentToModule ( modulePath , className , importPath )
119
+ astUtils . addComponentToModule ( this . pathToModule , className , importPath )
112
120
. then ( change => change . apply ( ) ) ) ;
113
121
}
114
122
0 commit comments