2022-11-07 14:06:35 +05:30
|
|
|
/**
|
|
|
|
* 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).
|
|
|
|
*/
|
|
|
|
|
2024-02-14 23:32:15 +01:00
|
|
|
import { readFileSync, writeFileSync, readdirSync } from 'node:fs';
|
|
|
|
import { join } from 'node:path';
|
2022-11-04 02:05:50 +05:30
|
|
|
|
2024-02-14 23:32:15 +01:00
|
|
|
const cSpellDictionaryDir = './.cspell';
|
2022-11-04 02:05:50 +05:30
|
|
|
|
2024-02-14 23:32:15 +01:00
|
|
|
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));
|
2022-11-04 02:05:50 +05:30
|
|
|
|
2024-02-14 23:32:15 +01:00
|
|
|
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();
|