Gathering detailed insights and metrics for shelljs-nodecli
Gathering detailed insights and metrics for shelljs-nodecli
Gathering detailed insights and metrics for shelljs-nodecli
Gathering detailed insights and metrics for shelljs-nodecli
npm install shelljs-nodecli
Typescript
Module System
NPM Version
63.3
Supply Chain
87.2
Quality
74.9
Maintenance
50
Vulnerability
100
License
Cumulative downloads
Total Downloads
Last day
-64%
9
Compared to previous day
Last week
-46.4%
89
Compared to previous week
Last month
-32.6%
5,314
Compared to previous month
Last year
53.2%
18,879
Compared to previous year
An extension for ShellJS that makes it easy to find and execute Node.js CLIs.
ShellJS is a fantastic tool for interacting with the shell environment in a cross-platform way. It allows you to easily write scripts that would otherwise be written in bash without worrying about compatibility.
The only problem is that it's a real pain to execute Node binaries that are installed locally. Most end up manually looking into the node_modules
directory to find the binary file to execute directly with Node, especially when working on Windows, where the files in node_modules/.bin
tend not to work from scripting environments like make and ShellJS. Consequently, you end up seeing a lot of this:
1// before 2var ESLINT = "node_modules/eslint/bin/eslint.js"; 3 4exec("node " + ESLINT + " myfile.js");
Since Node binaries are specified in their package.json
files, it's actually pretty easy to look up the location of the runtime file and get the path. That's where the ShellJS Node CLI extension comes in:
1var nodeCLI = require("shelljs-nodecli"); 2 3nodeCLI.exec("eslint", "myfile.js");
The nodeCLI utility has its own exec()
that is specifically for use when executing Node CLIs. It searches through the working directory's node_modules
directory to find a locally installed utility. If it's not found there, then it searches globally. If it's still not found, then an error is thrown.
You can pass in as many string arguments as you'd like, and they will automatically be concatenated together with a space in between, such as:
1var nodeCLI = require("shelljs-nodecli"); 2 3nodeCLI.exec("eslint", "-f compact", "myfile.js");
This ends up creating the following string:
"eslint -f compact myfile.js"
This frees you from needing to do tedious string concatenation to execute the command.
The exec()
method otherwise behaves exactly the same as the default ShellJS exec()
method, meaning you can use the same options and callback arguments, such as:
1var nodeCLI = require("shelljs-nodecli"); 2 3var version = nodeCLI.exec('eslint', '-v', {silent:true}).output; 4 5var child = nodeCLI.exec('some_long_running_process', {async:true}); 6child.stdout.on('data', function(data) { 7 /* ... do something with data ... */ 8}); 9 10nodeCLI.exec('some_long_running_process', function(code, output) { 11 console.log('Exit code:', code); 12 console.log('Program output:', output); 13});
Copyright 2014 Nicholas C. Zakas. All rights reserved.
MIT License
No vulnerabilities found.
No security vulnerabilities found.