UNPKG

1.01 kBJavaScriptView Raw
1"use strict";
2/**
3 * @license
4 * Copyright Google LLC All Rights Reserved.
5 *
6 * Use of this source code is governed by an MIT-style license that can be
7 * found in the LICENSE file at https://angular.io/license
8 */
9Object.defineProperty(exports, "__esModule", { value: true });
10exports.readJsonFile = void 0;
11const schematics_1 = require("@angular-devkit/schematics");
12const fs_1 = require("fs");
13const jsonc_parser_1 = require("jsonc-parser");
14function readJsonFile(path) {
15 if (!(0, fs_1.existsSync)(path)) {
16 throw new schematics_1.FileDoesNotExistException(path);
17 }
18 const errors = [];
19 const content = (0, jsonc_parser_1.parse)((0, fs_1.readFileSync)(path, 'utf-8'), errors, { allowTrailingComma: true });
20 if (errors.length) {
21 const { error, offset } = errors[0];
22 throw new Error(`Failed to parse "${path}" as JSON AST Object. ${(0, jsonc_parser_1.printParseErrorCode)(error)} at location: ${offset}.`);
23 }
24 return content;
25}
26exports.readJsonFile = readJsonFile;