-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
692 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,80 @@ | ||
# languagetool-cli | ||
|
||
For checking errors: | ||
## Checking errors | ||
|
||
```bash | ||
docker run --rm -v ./<directory>:/content hexlet/languagetool-cli node ./bin/check.js firstRule secondRule | ||
docker run --rm -v ./<directory>:/content hexlet/languagetool-cli node ./bin/run.js check <filePath> | ||
``` | ||
|
||
For fixing errors: | ||
Example: | ||
|
||
```bash | ||
docker run --rm -v ./<directory>:/content hexlet/languagetool-cli node ./bin/fix.js firstRule secondRule | ||
docker run --rm -v ./fixtures:/content hexlet/languagetool-cli node ./bin/run.js check /content/**/*.md | ||
``` | ||
|
||
To get wrong words: | ||
Help: | ||
|
||
```bash | ||
docker run --rm -v ./<directory>:/content hexlet/languagetool-cli node ./bin/getWords.js firstRule secondRule | ||
docker run --rm -v ./fixtures:/content hexlet/languagetool-cli node ./bin/run.js check -h | ||
|
||
Usage: run check [options] <dirPath> | ||
|
||
Options: | ||
-r, --rules "rule1, rule2, ..." languagetools rules | ||
-l, --language <Ru-ru> A language code like en-US, de-DE, fr, or | ||
auto to guess the language automatically | ||
(default: "auto") | ||
-h, --help display help for command | ||
``` | ||
|
||
## Fixing errors: | ||
|
||
```bash | ||
docker run --rm -v ./<directory>:/content hexlet/languagetool-cli node ./bin/run.js fix <filePath> | ||
``` | ||
|
||
Example: | ||
|
||
```bash | ||
docker run --rm -v ./fixtures:/content hexlet/languagetool-cli node ./bin/run.js fix /content/**/*.md | ||
``` | ||
|
||
Help: | ||
|
||
```bash | ||
docker run --rm -v ./fixtures:/content hexlet/languagetool-cli node ./bin/run.js fix -h | ||
|
||
Usage: run fix [options] <dirPath> | ||
|
||
Options: | ||
-r, --rules "rule1, rule2, ..." languagetools rules | ||
-l, --language <Ru-ru> A language code like en-US, de-DE, fr, or | ||
auto to guess the language automatically | ||
(default: "auto") | ||
-h, --help display help for command | ||
``` | ||
|
||
## To get wrong words: | ||
|
||
```bash | ||
docker run --rm -v ./<directory>:/content hexlet/languagetool-cli node ./bin/run.js words <filePath> | ||
``` | ||
|
||
Example: | ||
|
||
```bash | ||
docker run --rm -v ./fixtures:/content hexlet/languagetool-cli node ./bin/run.js words /content/**/*.md | ||
``` | ||
|
||
```bash | ||
docker run --rm -v ./<directory>:/content hexlet/languagetool-cli node ./bin/run.js words -h | ||
|
||
Options: | ||
-r, --rules "rule1, rule2, ..." languagetools rules | ||
-l, --language <Ru-ru> A language code like en-US, de-DE, fr, or | ||
auto to guess the language automatically | ||
(default: "auto") | ||
-f, --file <wrong_words.txt> Destination (default: "wrong_words.txt") | ||
-h, --help display help for command | ||
|
||
``` |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#!/usr/bin/env node | ||
|
||
import { exec } from 'child_process'; | ||
import fs from 'node:fs'; | ||
import { getErrors, formatErrors, getWrongWords, fix, filterIgnoredErrors, writeIgnoreErrorsFile } from '../src/index.js'; | ||
import { getLanguageToolVersion } from '../src/utils.js'; | ||
import { Command } from 'commander'; | ||
const program = new Command(); | ||
|
||
const serverStartCommand = `sh /LanguageTool-${getLanguageToolVersion}/start.sh >/dev/null 2>&1 &`; | ||
|
||
program | ||
.command('check') | ||
.description('Fix errors with overwriting files') | ||
.argument('[dir_path]', 'path to files', '/content') | ||
.option('-r, --rules "rule1, rule2, ..."', 'languagetools rules', '') | ||
.option('-l, --language <Ru-ru>', 'A language code like en-US, de-DE, fr, or auto to guess the language automatically', 'auto') | ||
.option('-i, --ignore <file_path>', 'Path to file with ignore rules', '/content/ignore') | ||
.action((dirPath, options) => { | ||
exec(serverStartCommand, () => setTimeout(async () => { | ||
const rules = options.rules.split(',').map((item) => item.trim()).filter((item) => item); | ||
const language = options.language; | ||
const ignorePath = options.ignore; | ||
|
||
const errors = await getErrors(dirPath, language, rules); | ||
const filtered = filterIgnoredErrors(errors, ignorePath); | ||
if (filtered) { | ||
const formattedErrors = formatErrors(errors); | ||
console.log(formattedErrors.join('\n------------------------\n')); | ||
process.exit(1); | ||
} | ||
}, 5000)); | ||
}); | ||
|
||
program | ||
.command('fix') | ||
.description('Check errors') | ||
.argument('[dir_path]', 'path to files', '/content') | ||
.option('-r, --rules "rule1, rule2, ..."', 'languagetools rules', '') | ||
.option('-l, --language <Ru-ru>', 'A language code like en-US, de-DE, fr, or auto to guess the language automatically', 'auto') | ||
.option('-i, --ignore <file_path>', 'Path to file with ignore rules', '/content/ignore') | ||
.action((dirPath = '/content', options) => { | ||
exec(serverStartCommand, () => setTimeout(async () => { | ||
const rules = options.rules.split(',').map((item) => item.trim()).filter((item) => item); | ||
const language = options.language; | ||
fix(dirPath, language, rules).then(() => { | ||
console.log('------------------DONE-----------------'); | ||
}); | ||
}, 5000)); | ||
}); | ||
|
||
program | ||
.command('words') | ||
.description('Get errors to a file') | ||
.argument('[dir_path]', 'path to files', '/content') | ||
.option('-r, --rules "rule1, rule2, ..."', 'languagetools rules', '') | ||
.option('-l, --language <Ru-ru>', 'A language code like en-US, de-DE, fr, or auto to guess the language automatically', 'auto') | ||
.option('-f, --file <wrong_words.txt>', 'Destination', '/content/wrong_words.txt') | ||
.action((dirPath = '/content', options) => { | ||
exec(serverStartCommand, () => setTimeout(async () => { | ||
const rules = options.rules.split(',').map((item) => item.trim()).filter((item) => item); | ||
const language = options.language; | ||
const words = await getWrongWords(dirPath, language, rules); | ||
fs.writeFileSync(options.file, words.join('\n'), 'utf-8'); | ||
}, 5000)); | ||
}); | ||
|
||
program | ||
.command('ignore') | ||
.argument('[dir_path]', 'path to files', '/content') | ||
.argument('[file_path]', 'path for ignore file', '/content/ignore') | ||
.option('-r, --rules "rule1, rule2, ..."', 'languagetools rules', '') | ||
.option('-l, --language <Ru-ru>', 'A language code like en-US, de-DE, fr, or auto to guess the language automatically', 'auto') | ||
.option('-f, --file <wrong_words.txt>', 'Destination', '/content/wrong_words.txt') | ||
.action((dirPath = '/content', filePath, options) => { | ||
exec(serverStartCommand, () => setTimeout(async () => { | ||
const rules = options.rules.split(',').map((item) => item.trim()).filter((item) => item); | ||
const language = options.language; | ||
|
||
const errors = await getErrors(dirPath, language, rules); | ||
fs.writeFileSync(filePath, words.join('\n'), 'utf-8'); | ||
}, 5000)); | ||
}); | ||
|
||
program | ||
.parse(process.argv); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.