-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (37 loc) · 1.18 KB
/
index.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
#!/usr/bin/env node
const currentDir = './';
const fs = require('fs');
const path = require('path');
function readDirectory(directory) {
let scannedFiles = [];
try {
fs.readdirSync(directory).forEach((file) => {
let fullPath = path.join(directory, file);
if(fs.lstatSync(fullPath).isDirectory()) {
scannedFiles = scannedFiles.concat(readDirectory(fullPath));
}
if(path.extname(fullPath) === '.dd') {
const data = fs.readFileSync(fullPath, 'utf8')
const lastIndex = fullPath.lastIndexOf('\\');
scannedFiles.push({path: fullPath.slice(0, lastIndex + 1), data});
}
});
return scannedFiles;
} catch(e) {
return e;
}
}
function compileMarkdown() {
const results = readDirectory(currentDir);
let writeString = '# Route Documentation\n';
results.reverse().forEach((result) => {
writeString += `## ${result.path}\n`
writeString += `### ${result.data}\n`
});
try {
fs.writeFileSync(`${currentDir}/DirectoryDoc.md`, writeString)
} catch (err) {
console.error(err)
}
}
compileMarkdown();