blob: a669065c79d851cda75d1ad068fd88266d8999ae [file] [log] [blame]
PineaFan64486c42022-12-28 09:21:04 +00001import fs from "fs";
2
3export default async function getSubcommandsInFolder(path: string) {
4 const files = fs.readdirSync(path, { withFileTypes: true }).filter(
5 file => !file.name.endsWith(".ts") && !file.name.endsWith(".map")
6 );
7 const subcommands = [];
8 const subcommandGroups = [];
9 for (const file of files) {
10 if (file.name === "_meta.js") continue;
11 // If its a folder
12 if (file.isDirectory()) {
13 // Get the _meta.ts file
14 console.log(`│ ├─ Loading subcommand group ${file.name}}`)
15 subcommandGroups.push((await import(`../../../${path}/${file.name}/_meta.js`)).command);
16 } else if (file.name.endsWith(".js")) {
17 // If its a file
18 console.log(`│ ├─ Loading subcommand ${file.name}}`)
19 subcommands.push((await import(`../../../${path}/${file.name}`)).command);
20 }
21 }
22 return {subcommands, subcommandGroups};
23}