25 lines
605 B
TypeScript
25 lines
605 B
TypeScript
import fs from "fs";
|
|
import path from "path";
|
|
|
|
export async function listWsFiles(dir: string) {
|
|
const files: string[] = [];
|
|
|
|
function walk(currentDir: string) {
|
|
const entries = fs.readdirSync(currentDir, { withFileTypes: true });
|
|
for (const entry of entries) {
|
|
const fullPath = path.join(currentDir, entry.name);
|
|
if (entry.isDirectory()) {
|
|
walk(fullPath);
|
|
} else if (entry.isFile() && entry.name === "ws.ts") {
|
|
files.push(fullPath);
|
|
}
|
|
}
|
|
}
|
|
|
|
walk(dir);
|
|
|
|
const modules = await Promise.all(files.map((file) => import(file)));
|
|
|
|
return modules;
|
|
}
|