collab/mermaid/scripts/fixCSpell.tsblame
View source
6dd74de1/**
6dd74de2 * Sorts all the `words` in the cSpell.json file.
6dd74de3 *
6dd74de4 * Run from the same folder as the `cSpell.json` file
6dd74de5 * (i.e. the root of the Mermaid project).
6dd74de6 */
6dd74de7
6dd74de8import { readFileSync, writeFileSync, readdirSync } from 'node:fs';
6dd74de9import { join } from 'node:path';
6dd74de10
6dd74de11const cSpellDictionaryDir = './.cspell';
6dd74de12
6dd74de13function sortWordsInFile(filepath: string) {
6dd74de14 const words = readFileSync(filepath, 'utf8')
6dd74de15 .split('\n')
6dd74de16 .map((word) => word.trim())
6dd74de17 .filter((word) => word);
6dd74de18 words.sort((a, b) => a.localeCompare(b));
6dd74de19
6dd74de20 writeFileSync(filepath, words.join('\n') + '\n', 'utf8');
6dd74de21}
6dd74de22
6dd74de23function findDictionaries() {
6dd74de24 const files = readdirSync(cSpellDictionaryDir, { withFileTypes: true })
6dd74de25 .filter((dir) => dir.isFile())
6dd74de26 .filter((dir) => dir.name.endsWith('.txt'));
6dd74de27 return files.map((file) => join(cSpellDictionaryDir, file.name));
6dd74de28}
6dd74de29
6dd74de30function main() {
6dd74de31 const files = findDictionaries();
6dd74de32 files.forEach(sortWordsInFile);
6dd74de33}
6dd74de34
6dd74de35main();