Skip to content

Commit

Permalink
feat: make node-jq a peer dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Aug 7, 2018
1 parent ca5972e commit 28089d0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,16 @@ foo bar

```
To use `roarr filter` program, you must install peer dependency `node-jq`:
```bash
# If Roarr is installed locally:
$ npm install node-jq
# or, if Roarr is installed globally:
$ npm install node-jq -g

```
### `pretty-print` program
Roarr `pretty-print` CLI program pretty-prints logs for the development purposes.
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"dependencies": {
"boolean": "^0.1.3",
"chalk": "^2.4.1",
"node-jq": "^1.3.1",
"optional": "^0.1.4",
"prettyjson": "^1.2.1",
"semver-compare": "^1.0.0",
"split2": "^2.2.0",
Expand Down Expand Up @@ -71,6 +71,9 @@
],
"sourceMap": false
},
"peerDependencies": {
"node-jq": "^1.3.1"
},
"repository": {
"type": "git",
"url": "git@github.com:gajus/roarr.git"
Expand Down
14 changes: 9 additions & 5 deletions src/bin/commands/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import split from 'split2';
import through from 'through2';
import {
run
} from 'node-jq';
import optional from 'optional';
import {
isRoarrLine
} from './utilities';
Expand All @@ -19,7 +17,7 @@ type LogFilterConfigurationType = {|
+jqExpression: string
|};

const filterLog = (configuration: LogFilterConfigurationType, line: string, callback: (error?: Error, line?: string) => {}) => {
const filterLog = (run, configuration: LogFilterConfigurationType, line: string, callback: (error?: Error, line?: string) => {}) => {
if (!isRoarrLine(line)) {
callback(undefined, configuration.excludeOrphans ? '' : line + '\n');

Expand Down Expand Up @@ -54,13 +52,19 @@ export const builder = (yargs: Object) => {
};

export const handler = (argv: ArgvType) => {
const jq = optional('node-jq');

if (!jq) {
throw new Error('Must install `node-jq` dependency to use `roarr filter`.');
}

// argv
process.stdin
.pipe(split())
.pipe(through((chunk, encoding, callback) => {
const line = chunk.toString();

filterLog(argv, line, callback);
filterLog(jq.run, argv, line, callback);
}))
.pipe(process.stdout);
};

0 comments on commit 28089d0

Please sign in to comment.