940 B36 lines
Blame
1/**
2 * Sorts all the `words` in the cSpell.json file.
3 *
4 * Run from the same folder as the `cSpell.json` file
5 * (i.e. the root of the Mermaid project).
6 */
7
8import { readFileSync, writeFileSync, readdirSync } from 'node:fs';
9import { join } from 'node:path';
10
11const cSpellDictionaryDir = './.cspell';
12
13function sortWordsInFile(filepath: string) {
14 const words = readFileSync(filepath, 'utf8')
15 .split('\n')
16 .map((word) => word.trim())
17 .filter((word) => word);
18 words.sort((a, b) => a.localeCompare(b));
19
20 writeFileSync(filepath, words.join('\n') + '\n', 'utf8');
21}
22
23function findDictionaries() {
24 const files = readdirSync(cSpellDictionaryDir, { withFileTypes: true })
25 .filter((dir) => dir.isFile())
26 .filter((dir) => dir.name.endsWith('.txt'));
27 return files.map((file) => join(cSpellDictionaryDir, file.name));
28}
29
30function main() {
31 const files = findDictionaries();
32 files.forEach(sortWordsInFile);
33}
34
35main();
36