-
Notifications
You must be signed in to change notification settings - Fork 0
/
genMethodList.js
33 lines (27 loc) · 1.17 KB
/
genMethodList.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
const fs = require('fs');
const { Mailsac } = require('./mailsac-client');
function getFunctionArgs(func) {
const str = func.toString();
const argsMatch = str.match(/\(([^)]*)\)/);
return argsMatch ? argsMatch[1].split(',').map(arg => arg.trim()) : [];
}
function generateDocs(clsInstance) {
let output = `# \`new ${clsInstance.constructor.name}({ headers: { "Mailsac-Key": 'REPLACE_APIKEY_HERE' } })\`\n\n`;
Object.getOwnPropertyNames(clsInstance).sort().forEach(namespace => {
if (!clsInstance[namespace] || typeof clsInstance[namespace] !== 'object' || ['webSockets', 'webhooks'].includes(namespace)) {
return;
}
output += `## ${namespace}\n`;
Object.getOwnPropertyNames(clsInstance[namespace]).sort().forEach(method => {
if (typeof clsInstance[namespace][method] === 'function') {
const args = getFunctionArgs(clsInstance[namespace][method]);
output += `### \`${namespace}.${method}(${args.join(', ')})\`\n`;
}
});
output += '\n';
});
return output;
}
const mailsac = new Mailsac({ headers: { 'Mailsac-Key': 'key' } });
const docs = generateDocs(mailsac);
fs.writeFileSync(__dirname + '/methodList.md', docs, 'utf8');