| 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 | |
| 8 | import { readFileSync, writeFileSync, readdirSync } from 'node:fs'; |
| 9 | import { join } from 'node:path'; |
| 10 | |
| 11 | const cSpellDictionaryDir = './.cspell'; |
| 12 | |
| 13 | function 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 | |
| 23 | function 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 | |
| 30 | function main() { |
| 31 | const files = findDictionaries(); |
| 32 | files.forEach(sortWordsInFile); |
| 33 | } |
| 34 | |
| 35 | main(); |
| 36 | |