Skip to content

Commit 9c1d234

Browse files
Broccohansl
authored andcommitted
fix(@schematics/angular): Make app-shell messages consistent
Fixes #289
1 parent fc9b807 commit 9c1d234

File tree

1 file changed

+11
-6
lines changed
  • packages/schematics/angular/app-shell

1 file changed

+11
-6
lines changed

packages/schematics/angular/app-shell/index.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ import { Schema as AppShellOptions } from './schema';
3232

3333

3434
// 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+
3541
function getSourceFile(host: Tree, path: string): ts.SourceFile {
3642
const buffer = host.read(path);
3743
if (!buffer) {
@@ -80,7 +86,7 @@ function addAppShellConfig(options: AppShellOptions): Rule {
8086
const app = getAppFromConfig(config, options.clientApp || '0');
8187

8288
if (!app) {
83-
throw new SchematicsException(`Client app (${options.clientApp}) could not be found.`);
89+
throw new SchematicsException(formatMissingAppMsg('Client', options.clientApp));
8490
}
8591

8692
if (!options.route) {
@@ -103,7 +109,7 @@ function addRouterModule(options: AppShellOptions): Rule {
103109
const config = getConfig(host);
104110
const app = getAppFromConfig(config, options.clientApp || '0');
105111
if (app === null) {
106-
throw new SchematicsException('Client app not found.');
112+
throw new SchematicsException(formatMissingAppMsg('Client', options.clientApp));
107113
}
108114
const modulePath = getAppModulePath(host, app);
109115
const moduleSource = getSourceFile(host, modulePath);
@@ -144,10 +150,9 @@ function addRouterOutlet(options: AppShellOptions): Rule {
144150
const config = getConfig(host);
145151
const app = getAppFromConfig(config, options.clientApp || '0');
146152
if (app === null) {
147-
throw new SchematicsException('Client app not found.');
153+
throw new SchematicsException(formatMissingAppMsg('Client', options.clientApp));
148154
}
149155
const modulePath = getAppModulePath(host, app);
150-
// const modulePath = getAppModulePath(host, options);
151156
const moduleSource = getSourceFile(host, modulePath);
152157

153158
const metadataNode = getDecoratorMetadata(moduleSource, 'NgModule', '@angular/core')[0];
@@ -209,11 +214,11 @@ function addServerRoutes(options: AppShellOptions): Rule {
209214
const config = getConfig(host);
210215
const app = getAppFromConfig(config, options.universalApp);
211216
if (app === null) {
212-
throw new SchematicsException('Universal/server app not found.');
217+
throw new SchematicsException(formatMissingAppMsg('Universal/server', options.universalApp));
213218
}
214219
const modulePath = getServerModulePath(host, app);
215220
if (modulePath === null) {
216-
throw new SchematicsException('Universal/server app not found.');
221+
throw new SchematicsException('Universal/server module not found.');
217222
}
218223

219224
let moduleSource = getSourceFile(host, modulePath);

0 commit comments

Comments
 (0)