forked from fnbrjs/fnbr.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
generateExports.js
51 lines (41 loc) · 1.74 KB
/
generateExports.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
/* eslint-disable no-await-in-loop */
/* eslint-disable no-restricted-syntax */
const fs = require('fs').promises;
const path = require('path');
const recursiveReaddir = async (folder) => {
const resolvedFiles = [];
const files = await fs.readdir(folder);
for (const file of files) {
const filePath = path.join(folder, file);
const stat = await fs.stat(filePath);
if (stat.isDirectory()) {
resolvedFiles.push(...await recursiveReaddir(`${folder}/${file}`));
} else {
resolvedFiles.push(`${folder}/${file}`);
}
}
return resolvedFiles;
};
(async () => {
let output = '';
output += '// main exports\nexport { default as Client } from \'./src/Client\';\n'
+ 'export { default as Enums } from \'./enums/Enums\';\n\n// types and interfaces\nexport * from \'./resources/structs\';\n'
+ '\n// endpoints\nexport { default as Endpoints } from \'./resources/Endpoints\';\n';
output += '\n// exceptions\n';
const exceptions = await recursiveReaddir('./src/exceptions');
exceptions.sort();
exceptions.forEach((file) => {
const fileWithoutExtension = file.split('/').pop().split('.')[0];
const filePathWithoutExtension = file.split('.').slice(0, -1).join('.');
output += `export { default as ${fileWithoutExtension} } from '${filePathWithoutExtension}';\n`;
});
output += '\n// structures\n';
const structures = await recursiveReaddir('./src/structures');
structures.sort();
structures.forEach((file) => {
const fileWithoutExtension = file.split('/').pop().split('.')[0];
const filePathWithoutExtension = file.split('.').slice(0, -1).join('.');
output += `export { default as ${fileWithoutExtension} } from '${filePathWithoutExtension}';\n`;
});
await fs.writeFile('./index.ts', output);
})();