diff options
| author | srdusr <trevorgray@srdusr.com> | 2025-09-26 13:39:28 +0200 |
|---|---|---|
| committer | srdusr <trevorgray@srdusr.com> | 2025-09-26 13:39:28 +0200 |
| commit | 8d60c7f93407988ee0232ea90980028f299cb0f3 (patch) | |
| tree | b343b691d1bce64fb3bc9b40324857486f2be244 /scripts/merge_packs.js | |
| parent | 76f0d0e902e6ed164704572bd81faa5e5e560cf3 (diff) | |
| download | typerpunk-8d60c7f93407988ee0232ea90980028f299cb0f3.tar.gz typerpunk-8d60c7f93407988ee0232ea90980028f299cb0f3.zip | |
Initial Commit
Diffstat (limited to 'scripts/merge_packs.js')
| -rw-r--r-- | scripts/merge_packs.js | 47 |
1 files changed, 47 insertions, 0 deletions
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); + } +})(); |
