11import * as fs from 'fs' ;
22import * as path from 'path' ;
33import * as ts from 'typescript' ;
4+ import { stripIndent } from 'common-tags' ;
45
56import { SchemaClass , SchemaClassFactory } from '@ngtools/json-schema' ;
67
@@ -73,15 +74,13 @@ export class CliConfig<JsonType> {
7374 }
7475
7576 static fromConfigPath < T > ( configPath : string , otherPath : string [ ] = [ ] ) : CliConfig < T > {
76- const configContent = fs . existsSync ( configPath )
77- ? ts . sys . readFile ( configPath )
78- : '{}' ;
77+ const configContent = ts . sys . readFile ( configPath ) || '{}' ;
7978 const schemaContent = fs . readFileSync ( DEFAULT_CONFIG_SCHEMA_PATH , 'utf-8' ) ;
8079
8180 let otherContents = new Array < string > ( ) ;
8281 if ( configPath !== otherPath [ 0 ] ) {
8382 otherContents = otherPath
84- . map ( path => fs . existsSync ( path ) && ts . sys . readFile ( path ) )
83+ . map ( path => ts . sys . readFile ( path ) )
8584 . filter ( content => ! ! content ) ;
8685 }
8786
@@ -92,18 +91,28 @@ export class CliConfig<JsonType> {
9291 try {
9392 content = JSON . parse ( configContent ) ;
9493 } catch ( err ) {
95- throw new InvalidConfigError (
96- ' Parsing .angular-cli.json failed. Please make sure your .angular-cli.json'
97- + ' is valid JSON. Error:\n' + err
98- ) ;
94+ throw new InvalidConfigError ( stripIndent `
95+ Parsing ' ${ configPath } ' failed. Ensure the file is valid JSON.
96+ Error: ${ err . message }
97+ ` ) ;
9998 }
10099
100+ others = otherContents . map ( otherContent => {
101+ try {
102+ return JSON . parse ( otherContent ) ;
103+ } catch ( err ) {
104+ throw new InvalidConfigError ( stripIndent `
105+ Parsing '${ configPath } ' failed. Ensure the file is valid JSON.
106+ Error: ${ err . message }
107+ ` ) ;
108+ }
109+ } ) ;
110+
101111 try {
102112 schema = JSON . parse ( schemaContent ) ;
103- others = otherContents . map ( otherContent => JSON . parse ( otherContent ) ) ;
104113 } catch ( err ) {
105114 throw new InvalidConfigError (
106- `Parsing Angular CLI schema or other configuration files failed. Error:\n${ err } `
115+ `Parsing Angular CLI schema failed. Error:\n${ err . message } `
107116 ) ;
108117 }
109118
0 commit comments