@@ -2,14 +2,23 @@ var path = require('path');
2
2
var dynamicPathParser = require ( '../../utilities/dynamic-path-parser' ) ;
3
3
const stringUtils = require ( 'ember-cli-string-utils' ) ;
4
4
const astUtils = require ( '../../utilities/ast-utils' ) ;
5
+ const findParentModule = require ( '../../utilities/find-parent-module' ) ;
5
6
6
7
module . exports = {
7
8
description : '' ,
8
-
9
+
9
10
availableOptions : [
10
11
{ name : 'flat' , type : Boolean , default : true }
11
12
] ,
12
13
14
+ beforeInstall : function ( ) {
15
+ try {
16
+ this . pathToModule = findParentModule ( this . project , this . dynamicPath . dir ) ;
17
+ } catch ( e ) {
18
+ throw `Error locating module for declaration\n\t${ e } ` ;
19
+ }
20
+ } ,
21
+
13
22
normalizeEntityName : function ( entityName ) {
14
23
var parsedPath = dynamicPathParser ( this . project , entityName ) ;
15
24
@@ -18,7 +27,7 @@ module.exports = {
18
27
} ,
19
28
20
29
locals : function ( options ) {
21
- return {
30
+ return {
22
31
dynamicPath : this . dynamicPath . dir ,
23
32
flat : options . flat
24
33
} ;
@@ -37,22 +46,21 @@ module.exports = {
37
46
}
38
47
} ;
39
48
} ,
40
-
49
+
41
50
afterInstall : function ( options ) {
42
51
if ( options . dryRun ) {
43
52
return ;
44
53
}
45
54
46
55
const returns = [ ] ;
47
- const modulePath = path . join ( this . project . root , this . dynamicPath . appRoot , 'app.module.ts' ) ;
48
56
const className = stringUtils . classify ( `${ options . entity . name } Pipe` ) ;
49
57
const fileName = stringUtils . dasherize ( `${ options . entity . name } .pipe` ) ;
50
58
const componentDir = path . relative ( this . dynamicPath . appRoot , this . generatePath ) ;
51
59
const importPath = componentDir ? `./${ componentDir } /${ fileName } ` : `./${ fileName } ` ;
52
60
53
61
if ( ! options [ 'skip-import' ] ) {
54
62
returns . push (
55
- astUtils . addComponentToModule ( modulePath , className , importPath )
63
+ astUtils . addComponentToModule ( this . pathToModule , className , importPath )
56
64
. then ( change => change . apply ( ) ) ) ;
57
65
}
58
66
0 commit comments