11import { NodeHost } from '../../lib/ast-tools' ;
2+ import { getAppFromConfig } from '../../utilities/app-utils' ;
23
34import * as fs from 'fs' ;
45import * as path from 'path' ;
@@ -71,22 +72,30 @@ export default Blueprint.extend({
7172 type : Boolean ,
7273 default : false ,
7374 description : 'Specifies if declaring module exports the component.'
75+ } ,
76+ {
77+ name : 'app' ,
78+ type : String ,
79+ aliases : [ 'a' ] ,
80+ description : 'Specifies app name to use.'
7481 }
7582 ] ,
7683
7784 beforeInstall : function ( options : any ) {
85+ const appConfig = getAppFromConfig ( this . project . ngConfig . apps , this . options . app ) ;
7886 if ( options . module ) {
7987 // Resolve path to module
8088 const modulePath = options . module . endsWith ( '.ts' ) ? options . module : `${ options . module } .ts` ;
81- const parsedPath = dynamicPathParser ( this . project , modulePath ) ;
89+ const parsedPath = dynamicPathParser ( this . project , modulePath , appConfig ) ;
8290 this . pathToModule = path . join ( this . project . root , parsedPath . dir , parsedPath . base ) ;
8391
8492 if ( ! fs . existsSync ( this . pathToModule ) ) {
8593 throw 'Module specified does not exist' ;
8694 }
8795 } else {
8896 try {
89- this . pathToModule = findParentModule ( this . project , this . dynamicPath . dir ) ;
97+ this . pathToModule = findParentModule (
98+ this . project . root , appConfig . root , this . dynamicPath . dir ) ;
9099 } catch ( e ) {
91100 if ( ! options . skipImport ) {
92101 throw `Error locating module for declaration\n\t${ e } ` ;
@@ -96,16 +105,12 @@ export default Blueprint.extend({
96105 } ,
97106
98107 normalizeEntityName : function ( entityName : string ) {
99- const parsedPath = dynamicPathParser ( this . project , entityName ) ;
108+ const appConfig = getAppFromConfig ( this . project . ngConfig . apps , this . options . app ) ;
109+ const parsedPath = dynamicPathParser ( this . project , entityName , appConfig ) ;
100110
101111 this . dynamicPath = parsedPath ;
102112
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- }
113+ const defaultPrefix = ( appConfig && appConfig . prefix ) || '' ;
109114
110115 let prefix = ( this . options . prefix === 'false' || this . options . prefix === '' )
111116 ? '' : ( this . options . prefix || defaultPrefix ) ;
@@ -191,7 +196,8 @@ export default Blueprint.extend({
191196 if ( ! options . locals . flat ) {
192197 dir += path . sep + options . dasherizedModuleName ;
193198 }
194- const srcDir = this . project . ngConfig . apps [ 0 ] . root ;
199+ const appConfig = getAppFromConfig ( this . project . ngConfig . apps , this . options . app ) ;
200+ const srcDir = appConfig . root ;
195201 this . appDir = dir . substr ( dir . indexOf ( srcDir ) + srcDir . length ) ;
196202 this . generatePath = dir ;
197203 return dir ;
0 commit comments