UNPKG

doxdox-renderer-github-wiki

Version:
41 lines (34 loc) 1.32 kB
import { join } from 'node:path'; import admzip from 'adm-zip'; import { markdownTable } from 'markdown-table'; const renderMethod = (method, config) => `## ${method.fullName} ${method.description} ${method.params.length ? `### Parameters ${markdownTable([ ['Name', 'Types', 'Description'], ...method.params.map(({ name, types, description }) => [ name, types .map(type => type.replace(/</, '&lt;').replace(/>/, '&gt;')) .join(', '), description || '' ]) ])}` : ''} ${method.returns.length ? `### Returns ${method.returns.map(param => `${param.types .map(type => type.replace(/</, '&lt;').replace(/>/, '&gt;')) .join(', ')} ${param.description || ''}`)}` : ''} Documentation generated with [doxdox](https://github.com/docsbydoxdox/doxdox) ${!config || config['hideGeneratedTimestamp'] !== true ? `\nGenerated on ${new Date().toDateString()} ${new Date().toTimeString()}\n` : ''}`; export default async (doc) => { const zip = new admzip(); await Promise.all(doc.files.map(async (file) => Promise.all(file.methods.map(async (method) => zip.addFile(join(file.path, `${method.name}.md`), Buffer.from(renderMethod(method, doc.config), 'utf-8')))))); return zip.toBuffer(); };