UNPKG

@eventcatalog/linter

Version:

A linter for EventCatalog to validate frontmatter and resource references

43 lines 1.39 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseAllFiles = exports.parseFrontmatter = void 0; const promises_1 = __importDefault(require("fs/promises")); const gray_matter_1 = __importDefault(require("gray-matter")); const parseFrontmatter = async (file) => { try { const fileContent = await promises_1.default.readFile(file.path, 'utf-8'); const { data, content } = (0, gray_matter_1.default)(fileContent); return { file, frontmatter: data, content, raw: fileContent, }; } catch (error) { return { file, error: error instanceof Error ? error : new Error(String(error)), }; } }; exports.parseFrontmatter = parseFrontmatter; const parseAllFiles = async (files) => { const results = await Promise.all(files.map(exports.parseFrontmatter)); const parsed = []; const errors = []; for (const result of results) { if ('error' in result) { errors.push(result); } else { parsed.push(result); } } return { parsed, errors }; }; exports.parseAllFiles = parseAllFiles; //# sourceMappingURL=index.js.map