@@ -2,14 +2,23 @@ var path = require('path');
22var dynamicPathParser = require ( '../../utilities/dynamic-path-parser' ) ;
33const stringUtils = require ( 'ember-cli-string-utils' ) ;
44const astUtils = require ( '../../utilities/ast-utils' ) ;
5+ import { findParentModule } from '../../utilities/find-parent-module' ;
56
67module . exports = {
78 description : '' ,
8-
9+
910 availableOptions : [
1011 { name : 'flat' , type : Boolean , default : true }
1112 ] ,
1213
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+
1322 normalizeEntityName : function ( entityName ) {
1423 var parsedPath = dynamicPathParser ( this . project , entityName ) ;
1524
@@ -18,7 +27,7 @@ module.exports = {
1827 } ,
1928
2029 locals : function ( options ) {
21- return {
30+ return {
2231 dynamicPath : this . dynamicPath . dir ,
2332 flat : options . flat
2433 } ;
@@ -37,22 +46,21 @@ module.exports = {
3746 }
3847 } ;
3948 } ,
40-
49+
4150 afterInstall : function ( options ) {
4251 if ( options . dryRun ) {
4352 return ;
4453 }
4554
4655 const returns = [ ] ;
47- const modulePath = path . join ( this . project . root , this . dynamicPath . appRoot , 'app.module.ts' ) ;
4856 const className = stringUtils . classify ( `${ options . entity . name } Pipe` ) ;
4957 const fileName = stringUtils . dasherize ( `${ options . entity . name } .pipe` ) ;
5058 const componentDir = path . relative ( this . dynamicPath . appRoot , this . generatePath ) ;
5159 const importPath = componentDir ? `./${ componentDir } /${ fileName } ` : `./${ fileName } ` ;
5260
5361 if ( ! options [ 'skip-import' ] ) {
5462 returns . push (
55- astUtils . addComponentToModule ( modulePath , className , importPath )
63+ astUtils . addComponentToModule ( this . pathToModule , className , importPath )
5664 . then ( change => change . apply ( ) ) ) ;
5765 }
5866
0 commit comments