-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdocsBuilder.js
40 lines (35 loc) · 1.08 KB
/
docsBuilder.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
39
40
const fs = require('fs');
const glob = require("glob");
const path = require('path');
const jsdoc2md = require('jsdoc-to-markdown');
// let files = fs.readdirSync(path.resolve(__dirname, 'core/'));
function ensureDirectoryExistence(filePath) {
var dirname = path.dirname(filePath);
if (fs.existsSync(dirname)) {
return true;
}
ensureDirectoryExistence(dirname);
fs.mkdirSync(dirname);
}
function renameToMd(filename) {
return filename.replace('core/', 'wiki/').replace('.js', '.md');
}
glob("core/**/*.js", function (er, files) {
if (er) {
throw new Error(er);
return 1;
}
files = files.filter( filename => {
return !filename.includes('.spec.js');
})
for (let file of files) {
console.log(`Generating Docs for ${file}`);
let text = jsdoc2md.renderSync({
files: path.resolve(__dirname, file)
});
let markdownFilename = renameToMd(file);
console.log(`Exporting to ${markdownFilename}`);
ensureDirectoryExistence(path.resolve(__dirname, markdownFilename))
fs.writeFileSync(path.resolve(__dirname, markdownFilename), text);
}
})