https://github.com/danilosampaio/runit-on-cli
Run node modules directly on CLI
https://github.com/danilosampaio/runit-on-cli
cli node shell
Last synced: 2 months ago
JSON representation
Run node modules directly on CLI
- Host: GitHub
- URL: https://github.com/danilosampaio/runit-on-cli
- Owner: danilosampaio
- License: mit
- Created: 2021-07-22T15:28:31.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2021-07-25T16:30:33.000Z (almost 5 years ago)
- Last Synced: 2025-09-23T15:55:23.118Z (9 months ago)
- Topics: cli, node, shell
- Language: JavaScript
- Homepage:
- Size: 303 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# runit-on-cli
> Run node modules directly on CLI
[](https://circleci.com/gh/danilosampaio/runit-on-cli)
## Install
```
npm install -g runit-on-cli
```
### API
```
$ runit-on-cli [-c] [-f [functionName]] [-n [version]] [-p [parameters...]] [-s] [-t [transformFunction]] [-u [subModule]]
```
- `-c, --call-module-as-function`: call the exported module as a function intead of object
- `-f, --function-name [functionName]`: call a specific function from exported module
- `-n, --npm-module-version [version]`: run a specific version of the npm module
- `-p, --params [parameters...]`: list of params that will be passed to the module/function call
- `-s, --silent`: print only the module output, without progress or logs
- `-t, --transform-output [transformFunction]`: define a function to modify module/function return
- `-u, --sub-module [subModule]`: import a submodule, such as 'crypto-js/sha256'
## Examples
__Running a module with default export, passing one string parameter:__
```sh
$ runit-on-cli jwt-decode -p \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c\"
```

*The above example using silent mode (-s option) will output only the return content:*
```js
{ sub: '1234567890', name: 'John Doe', iat: 1516239022 }
```
__Running a module with a named export, passing two parameters, an object and an array:__
```sh
$ runit-on-cli -s lodash orderBy -p '[{name:"banana"},{name:"apple"}]' '["name"]'
```
```js
[ { name: 'apple' }, { name: 'banana' } ]
```
__Passing a parameter from a file content:__
```sh
$ runit-on-cli -s lodash orderBy -p "$(cat ./users.json)" '["first"]'
```
```js
[
{ first: 'ane', last: 'mcfly' },
{ first: 'john', last: 'mayer' },
{ first: 'mary', last: 'jane' }
]
```
__A more complex example using lodash map:__
```sh
$ runit-on-cli -s lodash map -p "$(cat ./users.json)" 'e => {e.full = e.first + " " + e.last; return e;}'
```
```js
[
{ first: 'mary', last: 'jane', full: 'mary jane' },
{ first: 'john', last: 'mayer', full: 'john mayer' },
{ first: 'ane', last: 'mcfly', full: 'ane mcfly' }
]
```
__Running async functions and transform the output to return a specific property:__
```sh
$ runit-on-cli -s axios get -p \'http://universities.hipolabs.com\' -t 'output.data'
```
```js
{
data: {
author: { name: 'hipo', website: 'http://hipolabs.com' },
github: 'https://github.com/Hipo/university-domains-list',
example: 'http://universities.hipolabs.com/search?name=middle&country=Turkey'
}
}
```
__A more complex example of using -t option:__
```sh
$ runit-on-cli -s moment -t 'moment().add(7, "days").format("YYYY/MM/DD")'
```
```
2021/08/01
```
*Using the `-t` option is possible to use the node environment, actually.*
__Using the node environment by -t option:__
```sh
$ runit-on-cli -s axios get -p \'http://universities.hipolabs.com\' -t 'Object.keys(output.data)'
```
```js
[ 'author', 'github', 'example' ]
```
__Call a specific function from exported module:__
```sh
$ runit-on-cli chalk -f blue -p \"Hello World\"
```

*The same result is got by using `-t` option: `runit-on-cli chalk -p \"Hello World\" -t 'chalk.blue(output)'`*
__Another example of calling a specific function from exported module:__
```sh
$ runit-on-cli -s faker -f phone.phoneNumber
```
```
550-681-2495
```
__Running a module with a named export, without parameters:__
```sh
$ runit-on-cli -s uuid v4
```
```sh
2a7bb8f8-ac20-46ea-a0eb-ea58df26d48e
```
__Running the exported module as a function intead of object, and call a specific function:__
```sh
$ runit-on-cli moment -c -f add -p 7 \'days\'
```

*The `-c` options is necessary for this case because `moment` export is a function: `moment().add(7,'days')`*
__Running a submodule:__
```sh
$ runit-on-cli crypto-js -u sha256 -p \'test\'
```

## License
MIT © [Danilo Sampaio](http://github.org/danilosampaio)