All files seed.ts

25.92% Statements 7/27
100% Branches 0/0
0% Functions 0/1
25.92% Lines 7/27

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 361x 1x 1x 1x 1x 1x   1x                                                        
import * as path from "node:path";
import { cwd } from "node:process";
import { loadAndGetConfig } from "./config";
import { getLogger } from "./log";
import { getManifest } from "./manifest";
import { fileExists } from "./plainstack-fs";
 
const log = getLogger("seed");
 
export async function runSeed() {
  const config = await loadAndGetConfig();
  const { database } = await getManifest(["database"], { config, cwd: cwd() });
 
  const seedPath = path.join(cwd(), config.paths.seed);
 
  // TODO move to manifest for loading
  if (!(await fileExists(seedPath))) {
    log.info("Seed file not found. Skipping seeding.");
    return;
  }
 
  try {
    const seedModule = await import(seedPath);
 
    if (typeof seedModule.seed !== "function") {
      throw new Error("Seed file does not export a seed function");
    }
 
    await seedModule.seed(database);
    log.info("Seeding completed successfully.");
  } catch (error) {
    log.error("Error during seeding:", error);
    throw error;
  }
}