@@ -32,6 +32,12 @@ import { Schema as AppShellOptions } from './schema';
32
32
33
33
34
34
// Helper functions. (possible refactors to utils)
35
+ function formatMissingAppMsg ( label : string , nameOrIndex : string | undefined ) : string {
36
+ const nameOrIndexText = nameOrIndex ? ` (${ nameOrIndex } )` : '' ;
37
+
38
+ return `${ label } app ${ nameOrIndexText } not found.` ;
39
+ }
40
+
35
41
function getSourceFile ( host : Tree , path : string ) : ts . SourceFile {
36
42
const buffer = host . read ( path ) ;
37
43
if ( ! buffer ) {
@@ -80,7 +86,7 @@ function addAppShellConfig(options: AppShellOptions): Rule {
80
86
const app = getAppFromConfig ( config , options . clientApp || '0' ) ;
81
87
82
88
if ( ! app ) {
83
- throw new SchematicsException ( ` Client app ( ${ options . clientApp } ) could not be found.` ) ;
89
+ throw new SchematicsException ( formatMissingAppMsg ( ' Client' , options . clientApp ) ) ;
84
90
}
85
91
86
92
if ( ! options . route ) {
@@ -103,7 +109,7 @@ function addRouterModule(options: AppShellOptions): Rule {
103
109
const config = getConfig ( host ) ;
104
110
const app = getAppFromConfig ( config , options . clientApp || '0' ) ;
105
111
if ( app === null ) {
106
- throw new SchematicsException ( 'Client app not found.' ) ;
112
+ throw new SchematicsException ( formatMissingAppMsg ( 'Client' , options . clientApp ) ) ;
107
113
}
108
114
const modulePath = getAppModulePath ( host , app ) ;
109
115
const moduleSource = getSourceFile ( host , modulePath ) ;
@@ -144,10 +150,9 @@ function addRouterOutlet(options: AppShellOptions): Rule {
144
150
const config = getConfig ( host ) ;
145
151
const app = getAppFromConfig ( config , options . clientApp || '0' ) ;
146
152
if ( app === null ) {
147
- throw new SchematicsException ( 'Client app not found.' ) ;
153
+ throw new SchematicsException ( formatMissingAppMsg ( 'Client' , options . clientApp ) ) ;
148
154
}
149
155
const modulePath = getAppModulePath ( host , app ) ;
150
- // const modulePath = getAppModulePath(host, options);
151
156
const moduleSource = getSourceFile ( host , modulePath ) ;
152
157
153
158
const metadataNode = getDecoratorMetadata ( moduleSource , 'NgModule' , '@angular/core' ) [ 0 ] ;
@@ -209,11 +214,11 @@ function addServerRoutes(options: AppShellOptions): Rule {
209
214
const config = getConfig ( host ) ;
210
215
const app = getAppFromConfig ( config , options . universalApp ) ;
211
216
if ( app === null ) {
212
- throw new SchematicsException ( 'Universal/server app not found.' ) ;
217
+ throw new SchematicsException ( formatMissingAppMsg ( 'Universal/server' , options . universalApp ) ) ;
213
218
}
214
219
const modulePath = getServerModulePath ( host , app ) ;
215
220
if ( modulePath === null ) {
216
- throw new SchematicsException ( 'Universal/server app not found.' ) ;
221
+ throw new SchematicsException ( 'Universal/server module not found.' ) ;
217
222
}
218
223
219
224
let moduleSource = getSourceFile ( host , modulePath ) ;
0 commit comments