Add .fxrc support (#22)

js-version
Anton Medvedev 6 years ago committed by GitHub
parent d86b06c609
commit b3741760d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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

Loading…
Cancel
Save