What is cmd-shim?
The cmd-shim npm package is designed to create command shims (or symbolic links) on Windows and Unix-like systems for node.js scripts. This allows node.js scripts to be executed as if they were native commands in the user's shell, making it easier to use node.js tools across different platforms without worrying about the underlying differences in how executable scripts are handled.
What are cmd-shim's main functionalities?
Creating command shims
This feature allows the creation of a command shim for a node.js script. The code sample demonstrates how to create a shim for a node.js script located at 'path/to/node-script.js' and place the resulting shim at 'path/to/shim'. This makes the script executable as if it were a native command.
const cmdShim = require('cmd-shim');
cmdShim('path/to/node-script.js', 'path/to/shim', function (err) {
if (err) throw err;
});
Other packages similar to cmd-shim
npx
npx is a package runner tool that comes with npm. It allows you to execute any package from the npm registry without having to install it globally. While npx does not create shims, it provides a similar convenience by allowing direct execution of node.js scripts and commands. Unlike cmd-shim, npx is focused on temporary or one-off execution rather than creating a persistent executable shim.
shelljs
ShellJS is a portable (Windows/Linux/OS X) implementation of Unix shell commands on top of the Node.js API. While it primarily offers a way to script shell commands within Node.js, it shares the cross-platform scripting goal with cmd-shim. However, ShellJS does not specifically focus on creating command shims but rather on providing a wide range of shell commands within Node.js scripts.
cmd-shim
The cmd-shim used in npm to create executable scripts on Windows,
since symlinks are not suitable for this purpose there.
On Unix systems, you should use a symbolic link instead.
Installation
npm install cmd-shim
API
cmdShim(from, to) -> Promise
Create a cmd shim at to
for the command line program at from
.
e.g.
var cmdShim = require('cmd-shim');
cmdShim(__dirname + '/cli.js', '/usr/bin/command-name').then(() => {
})
cmdShim.ifExists(from, to) -> Promise
The same as above, but will just continue if the file does not exist.