fuzzyworld

word-waltz / files / scripts / generate-guess-list.js

generate-guess-list.js

1000 B · history · blame

1#!/usr/bin/env node
2/**
3 * scripts/generate-guess-list.js
4 *
5 * Generates src/utils/validGuesses.ts from the `word-list` npm package.
6 * Filters to lowercase 5-letter alphabetic words only.
7 *
8 * Run with: node scripts/generate-guess-list.js
9 * Automatically run before `dev` and `build` via package.json scripts.
10 */
11
12import wordListPath from 'word-list';
13import { readFileSync, writeFileSync } from 'fs';
14import { resolve, dirname } from 'path';
15import { fileURLToPath } from 'url';
16
17const __dirname = dirname(fileURLToPath(import.meta.url));
18const OUT = resolve(__dirname, '../src/utils/validGuesses.ts');
19
20const words = readFileSync(wordListPath, 'utf8')
21 .split('\n')
22 .filter(w => /^[a-z]{5}$/.test(w));
23
24const ts = `// cspell:disable
25// AUTO-GENERATED — do not edit by hand. Run: node scripts/generate-guess-list.js
26export const VALID_GUESSES = new Set<string>(${JSON.stringify(words)});
27`;
28
29writeFileSync(OUT, ts, 'utf8');
30console.log(`Generated ${OUT} with ${words.length} words.`);