Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dzencot committed Jul 2, 2024
1 parent 44d48c7 commit a795b8d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,7 @@ test:
getWords:
docker run --rm \
-v ./fixtures:/content \
hexlet/languagetool-cli
-v ./bin:/LanguageTool-6.3/bin \
-v ./src:/LanguageTool-6.3/src \
hexlet/languagetool-cli \
node ./bin/getWords.js
4 changes: 3 additions & 1 deletion bin/getWords.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#!/usr/bin/env node

import { exec } from 'child_process';
import fs from 'node:fs';
import { getWrongWords } from '../src/index.js';

exec('sh /LanguageTool-6.3/start.sh >/dev/null 2>&1 &', () => setTimeout(async () => {
const rules = process.argv.slice(2);
getWrongWords(rules);
const words = await getWrongWords('/content', rules);
fs.writeFileSync('/content/wrong_words.txt', words.join('\n'), 'utf-8');
}, 5000));
8 changes: 4 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ const isFiltered = (word) => {
return false;
};

const getWrongWords = async (rules = []) => {
const getWrongWords = async (dirPath, rules = []) => {

const filePaths = await getFilePaths();
const filePaths = await getFilePaths(dirPath);

const promises = filePaths.map(async (fullpath) => {
const content = fs.readFileSync(fullpath, 'utf-8');
Expand All @@ -58,8 +58,8 @@ const getWrongWords = async (rules = []) => {
return result.filter((item) => item).join('\n');
});

Promise.all(promises).then((words) => {
fs.writeFileSync(path.join(dirpath, 'wrong_words.txt'), words.map((w) => w.trim()).filter((w) => w).join('\n'), 'utf-8');
return Promise.all(promises).then((words) => {
return words.map((w) => w.trim()).filter((w) => w);
});
};

Expand Down

0 comments on commit a795b8d

Please sign in to comment.