import { mkdir, writeFile } from "node:fs/promises"; import path from "node:path"; import { fileURLToPath } from "node:url"; import type { RawProduct } from "./llm/types.js"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const DATA_DIR = path.resolve(__dirname, "../data/raw"); function slugifyPath(text: string): string { return text .toLowerCase() .replace(/[^a-zа-яё0-9]+/gi, "-") .replace(/^-+|-+$/g, "") .replace(/-+/g, "-"); } export async function dumpCategory( categoryName: string, products: RawProduct[], ): Promise { await mkdir(DATA_DIR, { recursive: true }); const filename = `${slugifyPath(categoryName)}.json`; const filepath = path.join(DATA_DIR, filename); await writeFile(filepath, JSON.stringify(products, null, 2), "utf-8"); console.log(` Wrote ${products.length} products → ${filepath}`); return filepath; }