UNPKG

vitepress-jsdoc

Version:

A bridge between Vitepress and JSDoc-style commented codebases for hassle-free documentation.

46 lines 1.58 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.readFileContent = void 0; const promises_1 = __importDefault(require("node:fs/promises")); const comment_js_1 = require("../parsers/comment.js"); /** * @file This module provides functionality to read the content of a file and parse its Vitepress header. */ /** * Reads the content of a file and parses its Vitepress header. * * @function * @async * * @param {DirectoryFile} file - The file object representing the file to be read. * * @returns {Promise<string>} A promise that resolves with the parsed content of the file. * * @throws Will throw an error if there's an issue reading the file or parsing its content. * * @example * * const file = {name: 'example', ext: '.md', folder: '/src/docs'}; * const content = await readFileContent(file); */ const readFileContent = async (file) => { try { const filePath = file.path; const content = await promises_1.default.readFile(filePath, 'utf8'); return (0, comment_js_1.parseVitepressFileHeader)(content, file); } catch (error) { if (error instanceof Error) { console.error(`Error reading or parsing file: ${error.message}`); } else { console.error('An unknown error occurred:', error); } throw error; } }; exports.readFileContent = readFileContent; //# sourceMappingURL=file-reader.js.map