UNPKG

vitepress-jsdoc

Version:

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

95 lines 2.95 kB
"use strict"; /* * @vitepress * --- * headline: Main Index * --- */ Object.defineProperty(exports, "__esModule", { value: true }); exports.generate = void 0; const output_js_1 = require("./utilities/output.js"); const index_js_1 = require("./classes/index.js"); /** * ## Generate Markdown Files * Orchestrates the process of reading, filtering, and writing files. * * - **options**: The plugin options of type `PluginOptions`. * * @example * ```typescript * generate(myCliArgs); * ``` */ const generate = async (options) => { const argParser = new index_js_1.ArgumentParser(); const parsedArgs = argParser.parse(options); const startTime = Date.now(); const docsManager = new index_js_1.DocsFolderManager(); const deletedPaths = await docsManager.delete(parsedArgs.docsFolder, parsedArgs.rmPattern); const dirManager = new index_js_1.DirectoryManager({ srcPath: parsedArgs.srcFolder, include: parsedArgs.include, exclude: parsedArgs.exclude, }); const lsFolder = await dirManager.build(); docsManager.create(parsedArgs.docsFolder); const fileProc = new index_js_1.FileProcessor(); const filteredResult = await fileProc.processFiles(lsFolder, options); (0, output_js_1.printStats)(lsFolder, filteredResult); const readme = new index_js_1.ReadmeManager(); await readme.create(options, deletedPaths); const resultTime = (Math.abs(startTime - Date.now()) / 1000).toFixed(2); console.log(`\n⏰ Time: ${resultTime}s`); const watcher = new index_js_1.WatcherManager(options); watcher.watch(); }; exports.generate = generate; /** * Vitepress JSDoc Plugin. * * @function * @param {PluginOptions} options - The options for the plugin. * @returns {Plugin} Returns a Vite plugin object. * * @example * ```typescript * // Example Vitepress Configuration * import { defineConfig } from "vitepress"; * import VitpressJsdocPlugin from "vitepress-jsdoc"; * * export default defineConfig({ * vite: { * plugins: [ * VitpressJsdocPlugin({ * folder: "code", * source: "./dist/mjs/", * dist: "./docs", * title: "API", * partials: ["./dist/mjs/partials/*.hbs"], * helpers: ["./dist/mjs/helpers/*.js"], * readme: "./README.md", * exclude: "**\/*.json,**\/*.hbs,**\/*.d.js,**\/*.map,**\/interfaces.*", * }), * ], * }, * }); * ``` */ const plugin = (options) => { return { name: 'vitepress-jsdoc-plugin', // Hook for 'serve' configureServer(server) { // Call your watch function here options.watch = true; const watcher = new index_js_1.WatcherManager(options); watcher.watch(); }, // Hook for 'build' // async buildStart() { // await generate(options); // }, }; }; exports.default = plugin; //# sourceMappingURL=index.js.map