11import { NodeHost } from '../../lib/ast-tools' ;
2+ import * as appUtils from '../../utilities/app-utils' ;
23
34import * as fs from 'fs' ;
45import * as path from 'path' ;
@@ -71,22 +72,25 @@ export default Blueprint.extend({
7172 type : Boolean ,
7273 default : false ,
7374 description : 'Specifies if declaring module exports the component.'
74- }
75+ } ,
76+ { name : 'app' , type : String , aliases : [ 'a' ] }
7577 ] ,
7678
7779 beforeInstall : function ( options : any ) {
80+ const appConfig = appUtils . getAppFromConfig ( this . project . ngConfig . apps , this . options . app ) ;
7881 if ( options . module ) {
7982 // Resolve path to module
8083 const modulePath = options . module . endsWith ( '.ts' ) ? options . module : `${ options . module } .ts` ;
81- const parsedPath = dynamicPathParser ( this . project , modulePath ) ;
84+ const parsedPath = dynamicPathParser ( this . project , modulePath , appConfig ) ;
8285 this . pathToModule = path . join ( this . project . root , parsedPath . dir , parsedPath . base ) ;
8386
8487 if ( ! fs . existsSync ( this . pathToModule ) ) {
8588 throw 'Module specified does not exist' ;
8689 }
8790 } else {
8891 try {
89- this . pathToModule = findParentModule ( this . project , this . dynamicPath . dir ) ;
92+ this . pathToModule = findParentModule
93+ ( this . project . root , appConfig . root , this . dynamicPath . dir ) ;
9094 } catch ( e ) {
9195 if ( ! options . skipImport ) {
9296 throw `Error locating module for declaration\n\t${ e } ` ;
@@ -96,16 +100,12 @@ export default Blueprint.extend({
96100 } ,
97101
98102 normalizeEntityName : function ( entityName : string ) {
99- const parsedPath = dynamicPathParser ( this . project , entityName ) ;
103+ const appConfig = appUtils . getAppFromConfig ( this . project . ngConfig . apps , this . options . app ) ;
104+ const parsedPath = dynamicPathParser ( this . project , entityName , appConfig ) ;
100105
101106 this . dynamicPath = parsedPath ;
102107
103- let defaultPrefix = '' ;
104- if ( this . project . ngConfig &&
105- this . project . ngConfig . apps [ 0 ] &&
106- this . project . ngConfig . apps [ 0 ] . prefix ) {
107- defaultPrefix = this . project . ngConfig . apps [ 0 ] . prefix ;
108- }
108+ const defaultPrefix = ( appConfig && appConfig . prefix ) || '' ;
109109
110110 let prefix = ( this . options . prefix === 'false' || this . options . prefix === '' )
111111 ? '' : ( this . options . prefix || defaultPrefix ) ;
@@ -191,7 +191,8 @@ export default Blueprint.extend({
191191 if ( ! options . locals . flat ) {
192192 dir += path . sep + options . dasherizedModuleName ;
193193 }
194- const srcDir = this . project . ngConfig . apps [ 0 ] . root ;
194+ const appConfig = appUtils . getAppFromConfig ( this . project . ngConfig . apps , this . options . app ) ;
195+ const srcDir = appConfig . root ;
195196 this . appDir = dir . substr ( dir . indexOf ( srcDir ) + srcDir . length ) ;
196197 this . generatePath = dir ;
197198 return dir ;
0 commit comments