-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjsdocs.js
33 lines (25 loc) · 1019 Bytes
/
jsdocs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const jsdoc2md = require("jsdoc-to-markdown");
const fs = require("fs");
const path = require("path");
/* input and output paths */
const inputFile = "./src/*.js";
const outputDir = "../docs";
/* get template data */
const templateData = jsdoc2md.getTemplateDataSync({ files: inputFile });
/* reduce templateData to an array of class names */
const classNames = templateData.reduce((classNames, identifier) => {
if (identifier.kind === "module") {
classNames.push(identifier.name);
}
return classNames;
}, []);
var output = "";
/* create a documentation file for each class */
classNames.forEach(className => {
const template = `{{#module name="${className}"}}{{>docs}}{{/module}}`;
output =
jsdoc2md.renderSync({ data: templateData, template: template }) + "\n";
fs.writeFileSync(path.resolve(outputDir, `${className}.md`), output);
});
// const output = jsdoc2md.renderSync({ data: templateData, template: "{{>modules}}" });
// fs.writeFileSync(path.resolve(outputDir, `Api.md`), output);