Command registration (for mini)
diff --git a/src/utils/commandRegistration/getFilesInFolder.ts b/src/utils/commandRegistration/getFilesInFolder.ts
index a669065..d8a1298 100644
--- a/src/utils/commandRegistration/getFilesInFolder.ts
+++ b/src/utils/commandRegistration/getFilesInFolder.ts
@@ -1,23 +1,27 @@
import fs from "fs";
-export default async function getSubcommandsInFolder(path: string) {
+export default async function getSubcommandsInFolder(path: string, indent: string = "") {
const files = fs.readdirSync(path, { withFileTypes: true }).filter(
file => !file.name.endsWith(".ts") && !file.name.endsWith(".map")
);
const subcommands = [];
const subcommandGroups = [];
+ let errors = 0;
for (const file of files) {
if (file.name === "_meta.js") continue;
- // If its a folder
- if (file.isDirectory()) {
- // Get the _meta.ts file
- console.log(`│ ├─ Loading subcommand group ${file.name}}`)
- subcommandGroups.push((await import(`../../../${path}/${file.name}/_meta.js`)).command);
- } else if (file.name.endsWith(".js")) {
- // If its a file
- console.log(`│ ├─ Loading subcommand ${file.name}}`)
- subcommands.push((await import(`../../../${path}/${file.name}`)).command);
+ try {
+ if (file.isDirectory()) {
+ // Get the _meta.ts file
+ subcommandGroups.push((await import(`../../../${path}/${file.name}/_meta.js`)).command);
+ } else if (file.name.endsWith(".js")) {
+ // If its a file
+ console.log(`│ ${indent}├─ Loading subcommand ${file.name}`)
+ subcommands.push((await import(`../../../${path}/${file.name}`)).command);
+ }
+ } catch (e) {
+ console.error(`│ ${indent}│ └─ Error loading ${file.name}: ${e}`);
+ errors++;
}
}
- return {subcommands, subcommandGroups};
+ return {subcommands, subcommandGroups, errors};
}