1
1
import { NodeHost } from '../../lib/ast-tools' ;
2
+ import { getAppFromConfig } from '../../utilities/app-utils' ;
2
3
3
4
import * as fs from 'fs' ;
4
5
import * as path from 'path' ;
@@ -71,22 +72,30 @@ export default Blueprint.extend({
71
72
type : Boolean ,
72
73
default : false ,
73
74
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.'
74
81
}
75
82
] ,
76
83
77
84
beforeInstall : function ( options : any ) {
85
+ const appConfig = getAppFromConfig ( this . project . ngConfig . apps , this . options . app ) ;
78
86
if ( options . module ) {
79
87
// Resolve path to module
80
88
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 ) ;
82
90
this . pathToModule = path . join ( this . project . root , parsedPath . dir , parsedPath . base ) ;
83
91
84
92
if ( ! fs . existsSync ( this . pathToModule ) ) {
85
93
throw 'Module specified does not exist' ;
86
94
}
87
95
} else {
88
96
try {
89
- this . pathToModule = findParentModule ( this . project , this . dynamicPath . dir ) ;
97
+ this . pathToModule = findParentModule (
98
+ this . project . root , appConfig . root , this . dynamicPath . dir ) ;
90
99
} catch ( e ) {
91
100
if ( ! options . skipImport ) {
92
101
throw `Error locating module for declaration\n\t${ e } ` ;
@@ -96,16 +105,12 @@ export default Blueprint.extend({
96
105
} ,
97
106
98
107
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 ) ;
100
110
101
111
this . dynamicPath = parsedPath ;
102
112
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 ) || '' ;
109
114
110
115
let prefix = ( this . options . prefix === 'false' || this . options . prefix === '' )
111
116
? '' : ( this . options . prefix || defaultPrefix ) ;
@@ -191,7 +196,8 @@ export default Blueprint.extend({
191
196
if ( ! options . locals . flat ) {
192
197
dir += path . sep + options . dasherizedModuleName ;
193
198
}
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 ;
195
201
this . appDir = dir . substr ( dir . indexOf ( srcDir ) + srcDir . length ) ;
196
202
this . generatePath = dir ;
197
203
return dir ;
0 commit comments