11import { NodeHost } from '../../lib/ast-tools' ;
2- import { getAppFromConfig } from '../../utilities/app-utils' ;
2+ import { CliConfig } from '../../models/config' ;
3+ import { getAppFromConfig } from '../../utilities/app-utils' ;
34
45import * as fs from 'fs' ;
56import * as path from 'path' ;
@@ -82,7 +83,9 @@ export default Blueprint.extend({
8283 ] ,
8384
8485 beforeInstall : function ( options : any ) {
85- const appConfig = getAppFromConfig ( this . project . ngConfig . apps , this . options . app ) ;
86+ const cliConfig = CliConfig . fromProject ( ) ;
87+ const ngConfig = cliConfig && cliConfig . config ;
88+ const appConfig = getAppFromConfig ( ngConfig . apps , this . options . app ) ;
8689 if ( options . module ) {
8790 // Resolve path to module
8891 const modulePath = options . module . endsWith ( '.ts' ) ? options . module : `${ options . module } .ts` ;
@@ -105,7 +108,9 @@ export default Blueprint.extend({
105108 } ,
106109
107110 normalizeEntityName : function ( entityName : string ) {
108- const appConfig = getAppFromConfig ( this . project . ngConfig . apps , this . options . app ) ;
111+ const cliConfig = CliConfig . fromProject ( ) ;
112+ const ngConfig = cliConfig && cliConfig . config ;
113+ const appConfig = getAppFromConfig ( ngConfig . apps , this . options . app ) ;
109114 const parsedPath = dynamicPathParser ( this . project , entityName , appConfig ) ;
110115
111116 this . dynamicPath = parsedPath ;
@@ -126,36 +131,37 @@ export default Blueprint.extend({
126131 } ,
127132
128133 locals : function ( options : any ) {
134+ const cliConfig = CliConfig . fromProject ( ) ;
135+ const ngConfig = cliConfig && cliConfig . config ;
136+
129137 this . styleExt = 'css' ;
130- if ( this . project . ngConfig &&
131- this . project . ngConfig . defaults &&
132- this . project . ngConfig . defaults . styleExt ) {
133- this . styleExt = this . project . ngConfig . defaults . styleExt ;
138+ if ( ngConfig && ngConfig . defaults && ngConfig . defaults . styleExt ) {
139+ this . styleExt = ngConfig . defaults . styleExt ;
134140 }
135141
136142 options . inlineStyle = options . inlineStyle !== undefined ?
137143 options . inlineStyle :
138- this . project . ngConfigObj . get ( 'defaults.component.inlineStyle' ) ;
144+ cliConfig && cliConfig . get ( 'defaults.component.inlineStyle' ) ;
139145
140146 options . inlineTemplate = options . inlineTemplate !== undefined ?
141147 options . inlineTemplate :
142- this . project . ngConfigObj . get ( 'defaults.component.inlineTemplate' ) ;
148+ cliConfig && cliConfig . get ( 'defaults.component.inlineTemplate' ) ;
143149
144150 options . flat = options . flat !== undefined ?
145151 options . flat :
146- this . project . ngConfigObj . get ( 'defaults.component.flat' ) ;
152+ cliConfig && cliConfig . get ( 'defaults.component.flat' ) ;
147153
148154 options . spec = options . spec !== undefined ?
149155 options . spec :
150- this . project . ngConfigObj . get ( 'defaults.component.spec' ) ;
156+ cliConfig && cliConfig . get ( 'defaults.component.spec' ) ;
151157
152158 options . viewEncapsulation = options . viewEncapsulation !== undefined ?
153159 options . viewEncapsulation :
154- this . project . ngConfigObj . get ( 'defaults.component.viewEncapsulation' ) ;
160+ cliConfig && cliConfig . get ( 'defaults.component.viewEncapsulation' ) ;
155161
156162 options . changeDetection = options . changeDetection !== undefined ?
157163 options . changeDetection :
158- this . project . ngConfigObj . get ( 'defaults.component.changeDetection' ) ;
164+ cliConfig && cliConfig . get ( 'defaults.component.changeDetection' ) ;
159165
160166 return {
161167 dynamicPath : this . dynamicPath . dir . replace ( this . dynamicPath . appRoot , '' ) ,
@@ -189,14 +195,17 @@ export default Blueprint.extend({
189195 } ,
190196
191197 fileMapTokens : function ( options : any ) {
198+ const cliConfig = CliConfig . fromProject ( ) ;
199+ const ngConfig = cliConfig && cliConfig . config ;
200+ const appConfig = getAppFromConfig ( ngConfig . apps , this . options . app ) ;
201+
192202 // Return custom template variables here.
193203 return {
194204 __path__ : ( ) => {
195205 let dir = this . dynamicPath . dir ;
196206 if ( ! options . locals . flat ) {
197207 dir += path . sep + options . dasherizedModuleName ;
198208 }
199- const appConfig = getAppFromConfig ( this . project . ngConfig . apps , this . options . app ) ;
200209 const srcDir = appConfig . root ;
201210 this . appDir = dir . substr ( dir . indexOf ( srcDir ) + srcDir . length ) ;
202211 this . generatePath = dir ;
0 commit comments