Skip to content
Permalink
Browse files

Add .fxrc support (#22)

  • Loading branch information...
antonmedv committed Nov 10, 2018
1 parent d86b06c commit b3741760d81603ec928d6f0fa2d3e74124aacf83
Showing with 34 additions and 5 deletions.
  1. +22 −0 README.md
  2. +12 −5 index.js
@@ -121,6 +121,28 @@ $ npm install -g lodash
$ cat package.json | fx 'require("lodash").keys(this.dependencies)'
```

### Using .fxrc

Create _.fxrc_ file in `$HOME` directory, and require any packages or define global functions.

For example, access all lodash methods without `_` prefix. Put in your `.fxrc` file:

```js
Object.assign(global, require('lodash'))
```

And now you will be able to call all lodash methods. For example, see who's been committing to react recently:

```
curl 'https://api.github.com/repos/facebook/react/commits?per_page=100' \
| fx 'mapValues(groupBy(this, "commit.committer.name"), size)'
```

> To be able require global modules make sure you have correct `NODE_PATH` env variable.
> ```bash
> export NODE_PATH=/usr/local/lib/node_modules
> ```
### Formatting

If you need something different then JSON (for example arguments for xargs) do not return anything from reducer.
@@ -1,6 +1,17 @@
#!/usr/bin/env node
'use strict'
const os = require('os')
const path = require('path')
const pretty = require('@medv/prettyjson')
const {stdin, stdout, stderr} = process

try {
require(path.join(os.homedir(), '.fxrc'))
} catch (err) {
if (err.code !== 'MODULE_NOT_FOUND') {
throw err
}
}

const usage = `
Usage
@@ -28,8 +39,6 @@ const usage = `
`

function main(input) {
const {stdout, stderr} = process

if (input === '') {
stderr.write(usage)
process.exit(2)
@@ -88,15 +97,13 @@ function reduce(json, code) {
}

function run() {
const stdin = process.stdin
stdin.setEncoding('utf8')

let buff = ''

if (stdin.isTTY) {
main('')
}

let buff = ''
stdin.on('readable', () => {
let chunk

0 comments on commit b374176

Please sign in to comment.
You can’t perform that action at this time.