forked from ieskudero/three-dxf-viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjsdoc.js
60 lines (47 loc) · 1.78 KB
/
jsdoc.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const fs = require( 'fs' );
const path = require( 'path' );
const jsdoc2md = require( 'jsdoc-to-markdown' );
class Doc {
constructor() {
}
documentFile( folder, file ) {
if ( !fs.existsSync( folder ) ) fs.mkdirSync( folder );
/* get template data */
const templateData = jsdoc2md.getTemplateDataSync( { files: file } );
const jsdoc = ( type ) => {
/* reduce templateData to an array of class names */
const names = templateData.reduce( ( names, identifier ) => {
if ( identifier.kind === type ) names.push( identifier.name );
return names;
}, [] );
/* create a documentation file for each module */
for ( const name of names ) {
const template = `{{#${type} name="${name}"}}{{>docs}}{{/${type}}}`;
console.log( `rendering ${name}, template: ${template}` );
const output = jsdoc2md.renderSync( { data: templateData, template: template } );
fs.writeFileSync( path.resolve( folder, `${name}.md` ), output );
}
};
jsdoc( 'module' );
jsdoc( 'class' );
}
async documentFiles( inFolder, outFolder, recursive = false ) {
const files = await fs.promises.readdir( inFolder );
for( let file of files ) {
if( recursive && fs.lstatSync( path.join( inFolder, file ) ).isDirectory() ) {
let newInFolder = path.join( inFolder, file );
let newOutFolder = path.join( outFolder, file );
if ( !fs.existsSync( newOutFolder ) ) fs.mkdirSync( newOutFolder );
await this.documentFiles( newInFolder, newOutFolder, recursive );
}
else doc.documentFile ( outFolder, path.join( inFolder, file ) );
}
}
}
const outputDir = __dirname + '/api';
let doc = new Doc();
//create main file documentation
doc.documentFile ( outputDir, __dirname + '/main.js' );
( async () => {
await doc.documentFiles( __dirname + '/src', outputDir, true );
} )();