@sidekick-coder/db
Version:
Cli Tool to manipulate data from diferent sources
21 lines (18 loc) • 552 B
JavaScript
import { promises } from 'fs';
import { resolve } from 'path';
import { pathToFileURL } from 'url';
// src/utils/importAll.ts
async function importAll(path, options) {
const files = await promises.readdir(path);
const result = {};
for await (const file of files) {
if ((options == null ? void 0 : options.exclude) && options.exclude.includes(file)) {
continue;
}
const url = pathToFileURL(resolve(path, file));
const module = await import(url.href);
result[file] = module;
}
return result;
}
export { importAll };