-
Notifications
You must be signed in to change notification settings - Fork 0
/
docsMD.config.js
38 lines (33 loc) · 1.2 KB
/
docsMD.config.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
34
35
36
37
38
/** @format */
const jsdoc2md = require('jsdoc-to-markdown');
const fs = require('fs');
const path = require('path');
/* input and output paths */
const InputFiles = ['customJestStubs.js','./stubs/**/*[^.min].js'];
const outputDir = __dirname;
/* get template data */
const templateData = jsdoc2md.getTemplateDataSync({ files: InputFiles });
/* reduce templateData to an array of class names */
const classNames = templateData.reduce((classNames, identifier) => {
if (identifier.kind === 'class') classNames.push(identifier.name);
return classNames;
}, []);
/* create a documentation file for each class */
for (const className of classNames) {
const template = `{{#class name="${className}"}}{{>docs}}{{/class}}`;
console.log(`rendering ${className}, template: ${template}`);
const output = jsdoc2md.renderSync({
data: templateData,
template: template,
});
const FileName = `wiki/${className}.md`;
const FilePath = path.resolve(outputDir, `${FileName}`);
fs.exists(FilePath, exists => {
if (!exists) {
// Create a file
return fs.writeFile(FilePath, output, () => {});
}
fs.writeFileSync(FilePath, output);
});
}
fs.copyFile('README.md', 'wiki/README.md', () => {});