-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
generate-commands-md.js
68 lines (49 loc) · 1.9 KB
/
generate-commands-md.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
61
62
63
64
65
66
67
68
const fs = require('fs');
const path = require('path');
const config = require('./config.json');
let commands = [];
let commands_path = path.resolve(__dirname, 'commands');
let output = `# Commands
### Table of contents`;
fs.readdir(commands_path, (err, items) => {
if(err)
throw "Unable to read commands folder";
items.forEach(item => {
if(path.extname(item) == '.js')
commands.push(require(path.resolve(commands_path, item)));
});
commands.forEach(command => {
if(!Array.isArray(command.command))
command.command = [command.command];
});
commands.forEach(command => {
output += `\n- [${config.prefix}${command.command[0]}](#${command.command[0]})`;
});
output += `\n---`
commands.forEach(command => {
output += `\n## ${config.prefix}${command.command[0]}`;
if(command.description){
if(!Array.isArray(command.description))
command.description = [command.description];
output += `\n${command.description.join("\n")}`;
}
if(command.command.length > 1)
output += `\n\n**Variations**: \`${config.prefix}${command.command.join('`, `' + config.prefix)}\``;
output += `\n\n**Usage**: \`${config.prefix}${command.command[0]}`;
if(command.usage)
output += ` ${command.usage}`;
output += '`';
if(command.example){
if(!Array.isArray(command.example))
command.example = [command.example];
output += `\n### Example${command.example.length > 1 ? 's' : ''}:`;
command.example.forEach(example => {
output += `\n\n\`\`\`\n${config.prefix}${example.run}\n\`\`\``;
if(example.result)
output += `\n${example.result}`;
});
}
});
fs.writeFileSync('COMMANDS.md', output);
process.exit(0);
});