You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.2 KiB
43 lines
1.2 KiB
'use strict' |
|
const jsdoc2md = require("jsdoc-to-markdown") |
|
const fs = require('fs') |
|
const path = require('path') |
|
|
|
const outputDir = "./docs/api/" |
|
|
|
function generateFiles(file) { |
|
const templateData = jsdoc2md.getTemplateDataSync({ |
|
files: file, |
|
//configure: "./jsdoc.json" |
|
}) |
|
|
|
let selectedData = templateData.reduce( (selectedData, identifier) => { |
|
if (identifier.kind == 'class' || identifier.kind == 'namespace') { |
|
selectedData.push(identifier) |
|
} |
|
return selectedData |
|
}, []) |
|
|
|
for (const identifier of selectedData) { |
|
let template = "" |
|
let name = identifier.name |
|
if (identifier.kind == 'class') { |
|
template = `{{#class name="${name}"}}{{>docs}}{{/class}}` |
|
} else { |
|
template = `{{#namespace name="${name}"}}{{>header~}}{{>body}}{{/namespace}}` |
|
} |
|
console.log(`rendering ${name}, template: ${template}`) |
|
|
|
const output = jsdoc2md.renderSync({ |
|
data: templateData, |
|
template: template, |
|
partial: ["templates/partials/**/*.hbs"], |
|
"global-index-format": "none", |
|
"module-index-format": "none" |
|
}) |
|
|
|
fs.writeFileSync(path.resolve(outputDir, `${name}.md`), output) |
|
} |
|
} |
|
|
|
generateFiles(["src/*.js"])
|
|
|