Skip to content

Commit b02a7e5

Browse files
committed
fix(@angular/cli): on error finding files, show warning
This should not prevent execution, but is useful to know.
1 parent fcbc7db commit b02a7e5

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

packages/angular/cli/commands/generate-impl.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export class GenerateCommand extends SchematicCommand<GenerateCommandSchema> {
3636
schematic.description.path,
3737
this._workflow.registry,
3838
schematic.description.schemaJson,
39+
this.logger,
3940
);
4041
} else {
4142
continue;

packages/angular/cli/models/command-runner.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,8 @@ export async function runCommand(
9292
throw new Error('Invalid command JSON loaded from ' + JSON.stringify(schemaPath));
9393
}
9494

95-
commandMap[name] = await parseJsonSchemaToCommandDescription(
96-
name,
97-
schemaPath,
98-
registry,
99-
schema,
100-
);
95+
commandMap[name] =
96+
await parseJsonSchemaToCommandDescription(name, schemaPath, registry, schema, logger);
10197
}
10298

10399
let commandName: string | undefined = undefined;

packages/angular/cli/utilities/json-schema.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import { json } from '@angular-devkit/core';
8+
import { json, logging } from '@angular-devkit/core';
99
import { ExportStringRef } from '@angular-devkit/schematics/tools';
1010
import { readFileSync } from 'fs';
1111
import { dirname, resolve } from 'path';
@@ -36,6 +36,7 @@ export async function parseJsonSchemaToSubCommandDescription(
3636
jsonPath: string,
3737
registry: json.schema.SchemaRegistry,
3838
schema: json.JsonObject,
39+
logger: logging.Logger,
3940
): Promise<SubCommandDescription> {
4041
const options = await parseJsonSchemaToOptions(registry, schema);
4142

@@ -61,12 +62,20 @@ export async function parseJsonSchemaToSubCommandDescription(
6162
let longDescription = '';
6263
if (typeof schema.$longDescription == 'string' && schema.$longDescription) {
6364
const ldPath = resolve(dirname(jsonPath), schema.$longDescription);
64-
longDescription = readFileSync(ldPath, 'utf-8');
65+
try {
66+
longDescription = readFileSync(ldPath, 'utf-8');
67+
} catch (e) {
68+
logger.warn(`File ${ldPath} was not found while constructing the subcommand ${name}.`);
69+
}
6570
}
6671
let usageNotes = '';
6772
if (typeof schema.$usageNotes == 'string' && schema.$usageNotes) {
6873
const unPath = resolve(dirname(jsonPath), schema.$usageNotes);
69-
usageNotes = readFileSync(unPath, 'utf-8');
74+
try {
75+
usageNotes = readFileSync(unPath, 'utf-8');
76+
} catch (e) {
77+
logger.warn(`File ${unPath} was not found while constructing the subcommand ${name}.`);
78+
}
7079
}
7180

7281
const description = '' + (schema.description === undefined ? '' : schema.description);
@@ -86,8 +95,10 @@ export async function parseJsonSchemaToCommandDescription(
8695
jsonPath: string,
8796
registry: json.schema.SchemaRegistry,
8897
schema: json.JsonObject,
98+
logger: logging.Logger,
8999
): Promise<CommandDescription> {
90-
const subcommand = await parseJsonSchemaToSubCommandDescription(name, jsonPath, registry, schema);
100+
const subcommand =
101+
await parseJsonSchemaToSubCommandDescription(name, jsonPath, registry, schema, logger);
91102

92103
// Before doing any work, let's validate the implementation.
93104
if (typeof schema.$impl != 'string') {

0 commit comments

Comments
 (0)