UNPKG

quilon

Version:

Generate ERDs from your entity files automagically

47 lines (46 loc) 2.25 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.FileSystemUtils = void 0; const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); const glob_1 = require("glob"); class FileSystemUtils { /** * Reads and parses a JSON file from the specified path. * * @template T The type of the parsed JSON object. * @param {string} path - The path of the JSON file to read. * @returns {T} The parsed JSON content as an object of type T. * @throws {Error} If the file cannot be read or parsed. */ static readAndParseJSONFile(path) { const fileBuffer = fs_1.default.readFileSync(path); return JSON.parse(fileBuffer.toString()); } /** * Reads all files in a directory that match a specified filename pattern. * * @param {string} directory - The directory to search within. * @param {string} fileNamePattern - The glob pattern to match file names. * @returns {Promise<string[]>} A promise that resolves to an array of matching file paths. */ static readFilesFromDirectory(directory, fileNamePattern) { return __awaiter(this, void 0, void 0, function* () { const directoryPath = path_1.default.resolve(directory); return (0, glob_1.glob)(`${directoryPath}/**/${fileNamePattern}`); }); } } exports.FileSystemUtils = FileSystemUtils;