{"_id":"shelljs-nodecli","_rev":"940332","name":"shelljs-nodecli","description":"ShellJS Node CLI Extension","dist-tags":{"latest":"0.1.1"},"maintainers":[{"name":"nzakas","email":"nicholas@nczconsulting.com"}],"time":{"modified":"2024-08-01T20:56:50.000Z","created":"2014-03-19T17:13:33.031Z","0.1.1":"2014-03-20T20:03:16.100Z","0.1.0":"2014-03-19T17:13:33.031Z"},"users":{"kbakba":true,"elmasse":true,"arkanciscan":true,"brentonhouse":true,"bapinney":true,"max_devjs":true,"guumaster":true,"groovybytes":true,"kontrax":true,"nfischer":true,"scottfreecode":true,"banbara23":true},"author":{"name":"Nicholas C. Zakas"},"versions":{"0.1.1":{"name":"shelljs-nodecli","author":{"name":"Nicholas C. Zakas"},"version":"0.1.1","description":"ShellJS Node CLI Extension","main":"./lib/shelljs-nodecli.js","scripts":{"test":"node Makefile.js","lint":"node Makefile.js lint","patch":"node Makefile.js patch","minor":"node Makefile.js minor","major":"node Makefile.js major"},"dependencies":{"shelljs":"~0.2"},"devDependencies":{"chai":"~1.9.0","sinon":"~1.9.0","istanbul":"~0.1.45","mocha":"~1.13.0","eslint":"~0.4","rewire":"~2.0.0"},"license":"MIT","_id":"shelljs-nodecli@0.1.1","dist":{"shasum":"f1beb5563754c475d06f7d0833e0f6075e462d3b","tarball":"http://registry-npm.ywwl.com/shelljs-nodecli/download/shelljs-nodecli-0.1.1.tgz","integrity":"sha512-/e+APCWKKW9A8YMHKgDzhWQ21zPuDLjn6ATBczxbp6uUeiCSwvw95ynKAjMsRd1yrd5dlCkMKJoc/Lpwrt2w+A==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFGMcgBo68YTvgrNWzAWp4IzgYEby4/20EYCjRBZTVEeAiEA/xphrceFNycIKXsEVKnUUyKfQ/OsfZkBXJboTuFQqNA="}],"size":5218,"noattachment":false,"key":"/shelljs-nodecli/-/shelljs-nodecli-0.1.1.tgz"},"_from":".","_npmVersion":"1.4.3","_npmUser":{"name":"nzakas","email":"nicholas@nczconsulting.com"},"maintainers":[{"name":"nzakas","email":"nicholas@nczconsulting.com"}],"directories":{},"publish_time":1395345796100,"_cnpm_publish_time":1395345796100},"0.1.0":{"name":"shelljs-nodecli","author":{"name":"Nicholas C. Zakas"},"version":"0.1.0","description":"ShellJS Node CLI Extension","main":"./lib/shelljs-nodecli.js","scripts":{"test":"node Makefile.js","lint":"node Makefile.js lint","patch":"node Makefile.js patch","minor":"node Makefile.js minor","major":"node Makefile.js major"},"dependencies":{"shelljs":"^0.2"},"devDependencies":{"chai":"^1.9.0","sinon":"^1.9.0","istanbul":"^0.1.45","mocha":"^1.13.0","eslint":"^0.4","rewire":"^2.0.0"},"license":"MIT","_id":"shelljs-nodecli@0.1.0","dist":{"shasum":"ecbda9420120fc8c82fb764d7e92c10e23156975","tarball":"http://registry-npm.ywwl.com/shelljs-nodecli/download/shelljs-nodecli-0.1.0.tgz","integrity":"sha512-rYGUJlmEQtwFT2PAUS3bRFxW4j61gqF5t/jMg4GQ6hrWV/s9glnojufURpynZaZwDfeFfxBcb/iWGaNC9Zp2yg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCID853u2XQZcpCba6nrXLz1+lQkElx+PFtS17pM7iVVZVAiBv6d4M1uaxfctwf+E2aMkcE60c+p6BXWx+V9p+5oghTw=="}],"size":4564,"noattachment":false,"key":"/shelljs-nodecli/-/shelljs-nodecli-0.1.0.tgz"},"_from":".","_npmVersion":"1.4.3","_npmUser":{"name":"nzakas","email":"nicholas@nczconsulting.com"},"maintainers":[{"name":"nzakas","email":"nicholas@nczconsulting.com"}],"directories":{},"publish_time":1395249213031,"_cnpm_publish_time":1395249213031}},"readme":"# ShellJS Node CLI Extension\n\nAn extension for ShellJS that makes it easy to find and execute Node.js CLIs.\n\n## The Problem\n\n[ShellJS](http://shelljs.org) 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.\n\nThe 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:\n\n```js\n// before\nvar ESLINT = \"node_modules/eslint/bin/eslint.js\";\n\nexec(\"node \" + ESLINT + \" myfile.js\");\n```\n\n## The Solution\n\nSince 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:\n\n```js\nvar nodeCLI = require(\"shelljs-nodecli\");\n\nnodeCLI.exec(\"eslint\", \"myfile.js\");\n```\n\nThe 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.\n\nYou 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:\n\n```js\nvar nodeCLI = require(\"shelljs-nodecli\");\n\nnodeCLI.exec(\"eslint\", \"-f compact\", \"myfile.js\");\n```\n\nThis ends up creating the following string:\n\n```\n\"eslint -f compact myfile.js\"\n```\n\nThis frees you from needing to do tedious string concatenation to execute the command.\n\nThe `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:\n\n```js\nvar nodeCLI = require(\"shelljs-nodecli\");\n\nvar version = nodeCLI.exec('eslint', '-v', {silent:true}).output;\n\nvar child = nodeCLI.exec('some_long_running_process', {async:true});\nchild.stdout.on('data', function(data) {\n    /* ... do something with data ... */\n});\n\nnodeCLI.exec('some_long_running_process', function(code, output) {\n    console.log('Exit code:', code);\n    console.log('Program output:', output);\n});\n```\n\n## License and Copyright\n\nCopyright 2014 Nicholas C. Zakas. All rights reserved.\n\nMIT License\n\n","_attachments":{},"license":"MIT"}