From 8d60c7f93407988ee0232ea90980028f299cb0f3 Mon Sep 17 00:00:00 2001 From: srdusr Date: Fri, 26 Sep 2025 13:39:28 +0200 Subject: Initial Commit --- scripts/merge_packs.js | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 scripts/merge_packs.js (limited to 'scripts/merge_packs.js') diff --git a/scripts/merge_packs.js b/scripts/merge_packs.js new file mode 100644 index 0000000..01bf412 --- /dev/null +++ b/scripts/merge_packs.js @@ -0,0 +1,47 @@ +#!/usr/bin/env node +/* + Merge all JSON packs from data/packs/*.json into texts.json at repo root. + Each pack item: { category: string, content: string, attribution: string } +*/ +const fs = require('fs'); +const path = require('path'); +const { glob } = require('glob'); + +const ROOT = path.resolve(__dirname, '..'); +const PACKS_DIR = path.join(ROOT, 'data', 'packs'); +const OUTPUT = path.join(ROOT, 'texts.json'); + +(async () => { + try { + const files = await glob('*.json', { cwd: PACKS_DIR, absolute: true }); + const items = []; + const seen = new Set(); + + for (const file of files) { + const pack = JSON.parse(fs.readFileSync(file, 'utf8')); + for (const item of pack) { + if (!item || !item.content) continue; + const key = `${item.category || ''}\u0000${item.content.trim().toLowerCase()}`; + if (seen.has(key)) continue; + seen.add(key); + items.push({ + category: String(item.category || 'general'), + content: String(item.content), + attribution: String(item.attribution || path.relative(ROOT, file)), + }); + } + } + + // Shuffle + for (let i = items.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)); + [items[i], items[j]] = [items[j], items[i]]; + } + + fs.writeFileSync(OUTPUT, JSON.stringify(items, null, 2)); + console.log(`Merged ${items.length} items into ${OUTPUT}`); + } catch (err) { + console.error('merge_packs failed:', err); + process.exit(1); + } +})(); -- cgit v1.2.3