-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathindex.ts
More file actions
executable file
·91 lines (79 loc) · 2.23 KB
/
Copy pathindex.ts
File metadata and controls
executable file
·91 lines (79 loc) · 2.23 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env node
import fs from 'fs-extra';
import { globby as glob } from 'globby';
import reporter from 'vfile-reporter';
import type { VFileMessage } from 'vfile-message';
import { buildPersonalDictionary } from './lib/build-personal-dictionary.js';
import { parseConfig } from './lib/config/index.js';
import { hasMessages } from './lib/has-messages.js';
import { printError } from './lib/print-error.js';
import { generateReports } from './lib/report-generator.js';
import { Spellchecker } from './lib/spellchecker.js';
import { toDictionary } from './lib/to-dictionary.js';
(async () => {
const {
files,
language,
personalDictionaryPaths,
generateDictionaryPath,
noGitignore,
ignoreRegexes,
suggestions,
plugins,
reports,
quiet,
} = parseConfig();
const personalDictionary = await buildPersonalDictionary(
personalDictionaryPaths,
);
const spellchecker = new Spellchecker({
language,
personalDictionary,
ignoreRegexes,
suggestions,
plugins,
});
if (personalDictionaryPaths.length > 0) {
files.push(
...personalDictionaryPaths.map((filePath: string) => `!${filePath}`),
);
}
const filesFromGlobs = await glob(files, { gitignore: !noGitignore });
if (!quiet) {
console.log(
`Spellchecking ${filesFromGlobs.length} file${
filesFromGlobs.length === 1 ? '' : 's'
}...`,
);
}
const checkSpelling = (filePath: string) =>
spellchecker.checkSpelling(filePath);
const vfiles = await Promise.all(filesFromGlobs.map(checkSpelling));
const results = reporter(vfiles, { quiet });
if (results.length > 0) {
if (!quiet) {
console.log();
}
console.log(results);
}
if (reports.length > 0) {
generateReports(reports, vfiles);
}
if (hasMessages(vfiles)) {
if (
generateDictionaryPath !== undefined &&
hasMessages(
vfiles,
(message: VFileMessage) => message.source === 'retext-spell',
)
) {
const path = generateDictionaryPath || 'dictionary.txt';
await fs.writeFile(path, toDictionary(vfiles));
console.log(`Personal dictionary written to ${path}.`);
}
process.exit(1);
}
})().catch(error => {
printError(error);
process.exit(1);
});