1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | Object.defineProperty(exports, "__esModule", { value: true });
|
10 | exports.readJsonFile = void 0;
|
11 | const schematics_1 = require("@angular-devkit/schematics");
|
12 | const fs_1 = require("fs");
|
13 | const jsonc_parser_1 = require("jsonc-parser");
|
14 | function 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 | }
|
26 | exports.readJsonFile = readJsonFile;
|