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