UNPKG

vitepress-jsdoc

Version:

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

61 lines (60 loc) 2.45 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.createReadmeFile = void 0; const promises_1 = __importDefault(require("node:fs/promises")); const plugin_options_js_1 = require("../parsers/plugin-options.js"); /** * Creates or updates the README file for the documentation. If a custom README file is provided, * its content will be used; otherwise, a default welcome message will be written. * * @function * @async * * @param {PluginOptions} options - The plugin options providing configuration for the README creation. * @param {string[]} [deletedPaths] - An optional list of paths that were deleted. Used to check if the README was among them. * * @returns {Promise<void>} A promise that resolves when the README file has been successfully created or updated. * * @throws Will throw an error if there's an issue reading from or writing to the file system. * * @example * * const options = { * srcFolder: './src', * codeFolder: 'code', * docsFolder: './docs', * title: 'My Documentation', * readme: './src/README.md' * }; * * createReadmeFile(options); */ const createReadmeFile = async (options, deletedPaths) => { const { srcFolder, codeFolder, docsFolder, title, readme } = (0, plugin_options_js_1.parsePluginOptions)(options); let readMeContent = ` # Welcome to ${title} Thank you for checking out this project! This is a default README message, as a custom README was not provided. Feel free to contribute or reach out with any questions or suggestions. `; const readmePath = readme || `${srcFolder}/README.md`; try { readMeContent = await promises_1.default.readFile(readmePath, 'utf8'); if (deletedPaths?.some((p) => p.includes(`${codeFolder}/README.md`))) { console.log(`\n README ${readmePath.replace('README.md', '')}README.md → ${docsFolder}/README.md`); } } catch { console.log(`\n README Add default README.md`); } try { await promises_1.default.writeFile(`${docsFolder}/README.md`, readMeContent); } catch (error) { console.error(`Error writing to ${docsFolder}/README.md:`, error); throw error; } }; exports.createReadmeFile = createReadmeFile; //# sourceMappingURL=create-readme.js.map