mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-14 06:43:25 +08:00
chore: sort cspell dictionaries on commit
This commit is contained in:
parent
4a7489a7b6
commit
f3282e4dad
@ -1,8 +1,8 @@
|
||||
# Contributors to mermaidjs, one per line
|
||||
Ashish Jain
|
||||
cpettitt
|
||||
Dong Cai
|
||||
Nikolay Rozhkov
|
||||
Peng Xiao
|
||||
subhash-halder
|
||||
Vinod Sidharth
|
||||
Ashish Jain
|
||||
|
@ -6,6 +6,6 @@ export default {
|
||||
// https://prettier.io/docs/en/cli.html#--cache
|
||||
'prettier --write',
|
||||
],
|
||||
'cSpell.json': ['tsx scripts/fixCSpell.ts'],
|
||||
'.cspell/*.txt': ['tsx scripts/fixCSpell.ts'],
|
||||
'**/*.jison': ['pnpm -w run lint:jison'],
|
||||
};
|
||||
|
@ -5,20 +5,31 @@
|
||||
* (i.e. the root of the Mermaid project).
|
||||
*/
|
||||
|
||||
import { readFileSync, writeFileSync } from 'node:fs';
|
||||
import prettier from 'prettier';
|
||||
import { readFileSync, writeFileSync, readdirSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
|
||||
const filepath = './cSpell.json';
|
||||
const cSpell: { words: string[] } = JSON.parse(readFileSync(filepath, 'utf8'));
|
||||
const cSpellDictionaryDir = './.cspell';
|
||||
|
||||
cSpell.words = [...new Set(cSpell.words.map((word) => word.toLowerCase()))];
|
||||
cSpell.words.sort((a, b) => a.localeCompare(b));
|
||||
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));
|
||||
|
||||
const prettierConfig = prettier.resolveConfig.sync(filepath) ?? {};
|
||||
writeFileSync(
|
||||
filepath,
|
||||
prettier.format(JSON.stringify(cSpell), {
|
||||
...prettierConfig,
|
||||
filepath,
|
||||
})
|
||||
);
|
||||
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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user