shx is a wrapper around ShellJS Unix
commands, providing an easy solution for simple Unix-like, cross-platform
commands in npm package scripts.
The following code can be run either a Unix or Windows command line:
$ shx pwd # ShellJS commands are supported automatically
/home/username/path/to/dir
$ shx ls # files are outputted one per line
file.txt
file2.txt
$ shx rm *.txt # a cross-platform way to delete files!
$ shx ls
$ shx echo "Hi there!"
Hi there!
$ shx touch helloworld.txt
$ shx cp helloworld.txt foobar.txt
$ shx mkdir sub
$ shx ls
foobar.txt
helloworld.txt
sub
$ shx rm -r sub # options work as wellAll commands internally call the ShellJS corresponding function, guaranteeing cross-platform compatibility.
ShellJS is good for writing long scripts. If you want to write bash-like, platform-independent scripts, we recommend you go with that.
However, shx is ideal for one-liners inside package.json:
{
"scripts": {
"clean": "shx rm -rf build dist && shx echo Done"
}
}| Nate Fischer | Ari Porad | Levi Thomason |