feat: add isModule
This commit is contained in:
+1
-11
@@ -168,7 +168,7 @@ export class CommandManager {
|
||||
private async loadCatCommands(catPath: string): Promise<Array<Command>> {
|
||||
const promises = fs
|
||||
.readdirSync(catPath)
|
||||
.filter((file) => this.isValidCommandFile(file))
|
||||
.filter((file) => isModule(file))
|
||||
.map(
|
||||
async (file) => await this.attemptLoadCommand(path.join(catPath, file))
|
||||
);
|
||||
@@ -178,16 +178,6 @@ export class CommandManager {
|
||||
/*
|
||||
cmd parsing
|
||||
*/
|
||||
private isValidCommandFile(file: string): boolean {
|
||||
if (file.endsWith('.d.ts')) return false;
|
||||
return (
|
||||
file.endsWith('.js') ||
|
||||
file.endsWith('.ts') ||
|
||||
file.endsWith('.mjs') ||
|
||||
file.endsWith('.cjs')
|
||||
);
|
||||
}
|
||||
|
||||
private async attemptLoadCommand(filePath: string): Promise<Command | null> {
|
||||
try {
|
||||
const module = await import(`file://${filePath}`);
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
const MOD_EXCLUDE: Array<string> = ['.d.ts'];
|
||||
const MOD_INCLUDE: Array<string> = ['.ts', '.js', '.mjs', '.cjs'];
|
||||
export function isModule(path: string): boolean {
|
||||
for (const ext of MOD_EXCLUDE) if (path.endsWith(ext)) return false;
|
||||
|
||||
for (const ext of MOD_INCLUDE) if (path.endsWith(ext)) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user