forked from Androz2091/discord-music-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docs.js
29 lines (21 loc) · 838 Bytes
/
docs.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
const mdtable = require('mdtable');
const { readFileSync, writeFileSync } = require('fs');
module.exports.generateDocs = (commands) => {
const readme = readFileSync('./README.md', 'utf-8');
const aboveTable = readme.split('| ').shift();
const belowTable = readme.split(' |').pop();
const tableData = {
header: [ 'Name', 'Description', 'Options' ],
alignment: ['L', 'C', 'R'],
rows: []
}
const tableSettings = {
borders: true,
padding: 1
}
commands.forEach((cmd) => {
tableData.rows.push([ `**/${cmd.commandName}**`, cmd.description, cmd.options?.map((o) => `\\<${o.name}>`).join(' ') || '' ]);
});
const finalReadme = `${aboveTable}${mdtable(tableData, tableSettings)}${belowTable}`;
writeFileSync('./README.md', finalReadme, 'utf-8');
}