doxdox-renderer-github-wiki
Version:
GitHub Wiki renderer for doxdox.
41 lines (34 loc) • 1.32 kB
JavaScript
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(/</, '<').replace(/>/, '>'))
.join(', '),
description || ''
])
])}`
: ''}
${method.returns.length
? `### Returns
${method.returns.map(param => `${param.types
.map(type => type.replace(/</, '<').replace(/>/, '>'))
.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();
};