Skip to content

Commit

Permalink
Merge pull request #18 from hcodes/update_deps
Browse files Browse the repository at this point in the history
v4
  • Loading branch information
hcodes authored Jan 8, 2018
2 parents 66504cd + 220ca1f commit ddea553
Show file tree
Hide file tree
Showing 7 changed files with 896 additions and 574 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"no-console": [0]
},
"env": {
"es6": true,
"node": true,
"mocha": true
},
Expand Down
33 changes: 0 additions & 33 deletions .jscsrc

This file was deleted.

4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v4.0.0
- Теперь для работы с STDIN необходимо явно указывать опцию `--stdin`.
- Обновлены зависимости в package.json.

## v3.1.1
- Обновлены зависимости в package.json.

Expand Down
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,25 @@ Usage: eyo [options] <file-or-url...>
Restoring the letter «ё» (yo) in russian texts.
Options:
-h, --help output usage information
-V, --version output the version number
-l, --lint Search of safe and unsafe replacements
-s, --sort Sort results
--no-colors Clean output without colors
-h, --help Output usage information
-V, --version Output the version number
-l, --lint Search of safe and unsafe replacements
-s, --sort Sort results
--stdin Process text provided on <STDIN>
--stdin-filename <file> Specify filename to process STDIN as
--no-colors Clean output without colors
```

### Примеры использования
`eyo file.txt > file.out.txt` — безопасная замена «е» на «ё» в файле.<br/>
`eyo https://example.com/index.html > file.out.html` — безопасная замена «е» на «ё» на странице сайта.

`cat file1.txt file2.txt file3.txt | eyo`

`eyo --lint file1.txt file2.txt` — вывод слов для файлов, где необходима или возможна замена.<br/>
`eyo --lint http://habrahabr.ru` — вывод слов для страницы сайта, где необходима или возможна замена.

`cat file1.txt file2.txt file3.txt | eyo --stdin > output.txt`<br/>
`cat file1.txt | eyo --stdin --stdin-filename file1.txt`

## Node.js

Используйте отдельный пакет [`eyo-kernel`](https://www.npmjs.com/package/eyo-kernel) без зависимостей.
Expand Down
36 changes: 17 additions & 19 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

'use strict';

const async = require('async');
const chalk = require('chalk');
const exit = require('exit');
const program = require('commander');
Expand All @@ -14,30 +13,17 @@ program
.option('-l, --lint', 'Search of safe and unsafe replacements')
.option('-s, --sort', 'Sort results')
.option('--no-colors', 'Clean output without colors')
.option('--stdin', 'Process text provided on <STDIN>')
.option('--stdin-filename <file>', 'Specify filename to process STDIN as')
.parse(process.argv);

chalk.enabled = program.colors;

if (process.stdin.isTTY && !program.args.length) {
if (!program.stdin && !program.args.length) {
program.help();
}

if (process.stdin.isTTY) {
const tasks = [];
program.args.forEach(function(resource) {
tasks.push(function(callback) {
if (resource.search(/^https?:/) !== -1) {
utils._processUrl(resource, callback);
} else {
utils._processFile(resource, callback);
}
});
});

async.series(tasks, function() {
exit(process.exitCode);
});
} else {
if (program.stdin) {
let text = '';

process.stdin
Expand All @@ -49,7 +35,19 @@ if (process.stdin.isTTY) {
}
})
.on('end', function() {
utils._processText(text, 'stdin');
utils._processText(text, program.stdinFilename || 'stdin');
exit(process.exitCode);
});
} else {
Promise.all(program.args.map(resource => {
return new Promise(resolve => {
if (resource.search(/^https?:/) !== -1) {
utils._processUrl(resource, resolve);
} else {
utils._processFile(resource, resolve);
}
});
})).then(() => {
exit(process.exitCode);
});
}
Loading

0 comments on commit ddea553

Please sign in to comment.