Skip to content

Script Home

Thiago Souza edited this page May 1, 2018 · 2 revisions

Script Home

The jp script home is a filesystem directory that allows extending the jp script runtime with pre-defined tools, scripts and npm dependencies. By default, the script home is set to ~/.jp (can be changed with -h parameter).

The script home directory supports the following structure:

  • A scripts directory: collection of custom scripts.
  • A utils directory: collection of custom utility objects.
  • Any npm installed module: npm modules that can be loaded with require.

The scripts directory

The scripts directory should contain a list of custom scripts. It is expected that a script exports a function that defines the processing pipeline, for instance:

module.exports = () => select('.n').reduce((a, b) => a + b, 0)

A script saved as ~/.jp/scripts/sample/sum.js can be invoked as following:

$ echo '[ { "n": 1 }, { "n": 2 } ]' | jp sample/sum
3

Notice that the sum.js script stays in a sample directory inside the scripts of ~/.jp, which can be addressed with sample/sum.

The utils directory

Clone this wiki locally