loose-ts-check
Version:
Run TS type-check and ignore certain errors in some files
29 lines (28 loc) • 824 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.readJSONArray = void 0;
const fs_1 = require("fs");
const readJSONArray = (path, ignoreMissingFile) => {
let fileContent;
try {
fileContent = (0, fs_1.readFileSync)(path, { encoding: 'utf-8' });
}
catch (error) {
if (ignoreMissingFile) {
return [];
}
return new Error(`Cannot read file ${path}: ${error.message}`);
}
let parsedFile;
try {
parsedFile = JSON.parse(fileContent);
}
catch (error) {
return new Error(`Cannot parse JSON file ${path}: ${error.message}`);
}
if (!Array.isArray(parsedFile)) {
return new Error(`File ${path} is not a valid array`);
}
return parsedFile;
};
exports.readJSONArray = readJSONArray;