import "dotenv/config"; import fs from "fs"; import { fetchAllPrompts, sortPrompts, fetchPromptCategories, } from "./utils/cms-client.js"; import { generateMarkdown, SUPPORTED_LANGUAGES, } from "./utils/markdown-generator.js"; async function main() { try { // Loop through all supported languages for (const lang of SUPPORTED_LANGUAGES) { console.log(`\n🌐 Processing language: ${lang.name} (${lang.code})...`); console.log(" šŸ“„ Fetching categories from CMS..."); const { allCategories } = await fetchPromptCategories(lang.code); console.log(` āœ… Fetched ${allCategories.length} categories`); console.log(` šŸ“„ Fetching prompts from CMS (locale: ${lang.code})...`); const { docs: prompts, total } = await fetchAllPrompts( lang.code, allCategories ); console.log(` āœ… Fetched ${prompts.length} prompts (total: ${total})`); console.log(" šŸ”ƒ Sorting prompts..."); const sorted = sortPrompts(prompts, total); console.log(" šŸ“ Generating README..."); const markdown = generateMarkdown( { ...sorted, categories: allCategories }, total, lang.code ); console.log(` šŸ’¾ Writing ${lang.readmeFileName}...`); fs.writeFileSync(lang.readmeFileName, markdown, "utf-8"); console.log(` āœ… ${lang.readmeFileName} updated successfully!`); console.log( ` šŸ“Š Stats: ${sorted.stats.total} total, ${sorted.featured.length} featured` ); } console.log("\n✨ All languages processed successfully!"); } catch (error) { console.error("āŒ Error:", error); process.exit(1); } } main();