chore: sort cspell dictionaries on commit

This commit is contained in:
Jason Dent 2024-02-14 23:32:15 +01:00
parent 4a7489a7b6
commit f3282e4dad
3 changed files with 27 additions and 16 deletions

View File

@ -1,8 +1,8 @@
# Contributors to mermaidjs, one per line # Contributors to mermaidjs, one per line
Ashish Jain
cpettitt cpettitt
Dong Cai Dong Cai
Nikolay Rozhkov Nikolay Rozhkov
Peng Xiao Peng Xiao
subhash-halder subhash-halder
Vinod Sidharth Vinod Sidharth
Ashish Jain

View File

@ -6,6 +6,6 @@ export default {
// https://prettier.io/docs/en/cli.html#--cache // https://prettier.io/docs/en/cli.html#--cache
'prettier --write', 'prettier --write',
], ],
'cSpell.json': ['tsx scripts/fixCSpell.ts'], '.cspell/*.txt': ['tsx scripts/fixCSpell.ts'],
'**/*.jison': ['pnpm -w run lint:jison'], '**/*.jison': ['pnpm -w run lint:jison'],
}; };

View File

@ -5,20 +5,31 @@
* (i.e. the root of the Mermaid project). * (i.e. the root of the Mermaid project).
*/ */
import { readFileSync, writeFileSync } from 'node:fs'; import { readFileSync, writeFileSync, readdirSync } from 'node:fs';
import prettier from 'prettier'; import { join } from 'node:path';
const filepath = './cSpell.json'; const cSpellDictionaryDir = './.cspell';
const cSpell: { words: string[] } = JSON.parse(readFileSync(filepath, 'utf8'));
cSpell.words = [...new Set(cSpell.words.map((word) => word.toLowerCase()))]; function sortWordsInFile(filepath: string) {
cSpell.words.sort((a, b) => a.localeCompare(b)); const words = readFileSync(filepath, 'utf8')
.split('\n')
.map((word) => word.trim())
.filter((word) => word);
words.sort((a, b) => a.localeCompare(b));
const prettierConfig = prettier.resolveConfig.sync(filepath) ?? {}; writeFileSync(filepath, words.join('\n') + '\n', 'utf8');
writeFileSync( }
filepath,
prettier.format(JSON.stringify(cSpell), { function findDictionaries() {
...prettierConfig, const files = readdirSync(cSpellDictionaryDir, { withFileTypes: true })
filepath, .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();