Skip to content
Functionutilsv0.10.0

importFiles

Imports every .ts, .tsx, .mts, .js, .jsx or .mjs file under a directory, recursively and sorted by path, yielding each module in turn. It skips type declarations, dotfiles, dot-folders and node_modules. A break stops the walk before the next import. A relative dir resolves against root from seedcord.config.ts, whichever file calls this.

Throws:

  • A SeedcordError when the directory cannot be read.

  • A SeedcordError when a file throws while it imports.

  • A SeedcordError when dir is relative and the bot did not start through seedcord dev or its built output.

  • A SeedcordError when the directory is outside root or has a dot-folder or node_modules in its path, under seedcord dev or in a built bot.

  • A SeedcordError when the directory was missing at build time, in a built bot.

importFiles(
    dir: string,
    options?: FileWalkOptions
): AsyncGenerator<ImportedFile>
for await (const { relativePath, imported } of importFiles('./commands')) {
    for (const exported of Object.values(imported)) register(exported, relativePath);
}