diff --git a/Makefile b/Makefile index 6001905..3186772 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/bin/getWords.js b/bin/getWords.js index c7cd329..53adfb7 100644 --- a/bin/getWords.js +++ b/bin/getWords.js @@ -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)); diff --git a/src/index.js b/src/index.js index 531c787..6c9a352 100644 --- a/src/index.js +++ b/src/index.js @@ -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'); @@ -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); }); };