Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
dzencot committed Jul 3, 2024
1 parent a2c8edf commit f169bf9
Show file tree
Hide file tree
Showing 13 changed files with 692 additions and 95 deletions.
45 changes: 35 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,25 @@ build:
bash:
docker run --rm -it \
-v ./fixtures:/content \
-v ./bin:/usr/local/bin \
-v ./bin:/LanguageTool-6.4/bin \
-v ./src:/LanguageTool-6.4/src \
hexlet/languagetool-cli bash

check:
docker run --rm \
-v ./fixtures:/content \
-v ./bin:/LanguageTool-6.3/bin \
-v ./src:/LanguageTool-6.3/src \
-v ./bin:/LanguageTool-6.4/bin \
-v ./src:/LanguageTool-6.4/src \
hexlet/languagetool-cli \
node ./bin/check.js
node ./bin/run.js check /content/**/*.md

run-fix:
docker run --rm \
-v ./fixtures:/content \
-v ./bin:/LanguageTool-6.3/bin \
-v ./src:/LanguageTool-6.3/src \
-v ./bin:/LanguageTool-6.4/bin \
-v ./src:/LanguageTool-6.4/src \
hexlet/languagetool-cli \
node ./bin/fix.js
node ./bin/run.js fix /content/**/*.md

test:
docker run --rm \
Expand All @@ -31,7 +32,31 @@ test:
getWords:
docker run --rm \
-v ./fixtures:/content \
-v ./bin:/LanguageTool-6.3/bin \
-v ./src:/LanguageTool-6.3/src \
-v ./bin:/LanguageTool-6.4/bin \
-v ./src:/LanguageTool-6.4/src \
hexlet/languagetool-cli \
node ./bin/getWords.js
node ./bin/run.js words /content/**/*.md -f /content/wrong_words.txt

help-check:
docker run --rm \
-v ./fixtures:/content \
-v ./bin:/LanguageTool-6.4/bin \
-v ./src:/LanguageTool-6.4/src \
hexlet/languagetool-cli \
node ./bin/run.js check -h

help-fix:
docker run --rm \
-v ./fixtures:/content \
-v ./bin:/LanguageTool-6.4/bin \
-v ./src:/LanguageTool-6.4/src \
hexlet/languagetool-cli \
node ./bin/run.js fix -h

help-words:
docker run --rm \
-v ./fixtures:/content \
-v ./bin:/LanguageTool-6.4/bin \
-v ./src:/LanguageTool-6.4/src \
hexlet/languagetool-cli \
node ./bin/run.js words -h
73 changes: 67 additions & 6 deletions README.md
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

```
15 changes: 0 additions & 15 deletions bin/check.js

This file was deleted.

12 changes: 0 additions & 12 deletions bin/fix.js

This file was deleted.

12 changes: 0 additions & 12 deletions bin/getWords.js

This file was deleted.

86 changes: 86 additions & 0 deletions bin/run.js
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);
13 changes: 0 additions & 13 deletions fixtures/wrong_words.txt

This file was deleted.

Loading

0 comments on commit f169bf9

Please sign in to comment.