41 lines
1.3 KiB
JavaScript
41 lines
1.3 KiB
JavaScript
import { readFileSync, writeFileSync } from "node:fs"
|
|
|
|
const targetWords = JSON.parse(readFileSync(new URL("../targetWords.json", import.meta.url), "utf8"))
|
|
const dictionaryWords = JSON.parse(readFileSync(new URL("../dictionary.json", import.meta.url), "utf8"))
|
|
|
|
const normalizeWords = words => [...new Set(words
|
|
.map(word => String(word).trim().toLowerCase())
|
|
.filter(word => /^[a-z]{5}$/.test(word)))]
|
|
|
|
const answers = normalizeWords(targetWords)
|
|
const dictionary = normalizeWords([...dictionaryWords, ...answers]).sort()
|
|
|
|
const quote = value => `'${value.replaceAll("'", "''")}'`
|
|
const answerRows = answers
|
|
.map((word, index) => ` (${index + 1}, ${quote(word)})`)
|
|
.join(",\n")
|
|
const dictionaryRows = dictionary
|
|
.map(word => ` (${quote(word)})`)
|
|
.join(",\n")
|
|
|
|
const sql = `-- Generated by scripts/generate-supabase-word-seed.mjs.
|
|
-- Re-run the generator after changing targetWords.json or dictionary.json.
|
|
|
|
begin;
|
|
|
|
truncate table public.wordle_words;
|
|
truncate table public.wordle_dictionary;
|
|
|
|
insert into public.wordle_words (position, word) values
|
|
${answerRows};
|
|
|
|
insert into public.wordle_dictionary (word) values
|
|
${dictionaryRows};
|
|
|
|
commit;
|
|
`
|
|
|
|
writeFileSync(new URL("../supabase/seed-word-data.sql", import.meta.url), sql)
|
|
|
|
console.log(`Wrote ${answers.length} answers and ${dictionary.length} accepted guesses.`)
|