3 category: JavaScript libraries
8 [ShellJS](https://github.com/shelljs/shelljs) is a portable (Windows/Linux/OS X) implementation of Unix shell commands on top of the Node.js API.
14 var shell = require('shelljs')
18 if (!shell.which('git')) {
19 shell.echo('Sorry, this script requires git')
25 // Copy files to release dir
26 shell.rm('-rf', 'out/Release')
27 shell.cp('-R', 'stuff/', 'out/Release')
31 // Replace macros in each .js file
33 shell.ls('*.js').forEach(function (file) {
34 shell.sed('-i', 'BUILD_VERSION', 'v0.1.2', file)
35 shell.sed('-i', /^.*REMOVE_THIS_LINE.*$/, '', file)
36 shell.sed('-i', /.*REPLACE_LINE_WITH_MACRO.*\n/, shell.cat('macro.js'), file)
42 // Run external tool synchronously
43 if (shell.exec('git commit -am "Auto-commit"').code !== 0) {
44 shell.echo('Error: Git commit failed')
49 Taken from the [Readme](https://github.com/shelljs/shelljs).
54 const sh = require('shelljs')
72 sh.cp('-rf', 'src', 'dest')
82 sh.mv(['src1','src2'], 'dest')
86 sh.chmod('644', 'file')
88 sh.chmod('u+x', 'file')
94 sh.test('-b', 'path') // block device
95 sh.test('-d', 'path') // dir
96 sh.test('-e', 'path') // exists
97 sh.test('-f', 'path') // file
98 sh.test('-L', 'path') // symlink
104 src = sh.cat('file*.txt')
108 'hello'.to('output.txt')
109 'hello'.toEnd('append.txt')
113 sh.cat('input.txt').to('output.txt')
128 sh.exec('node --version').code
129 sh.exec('node --version').output
130 sh.exec('node --version', { silent: true }).output
134 sh.exec('node --version', (code, output) => {
135 sh.echo(`exit code ${code}`)
144 sh.error() // null if no error
149 * <https://github.com/shelljs/shelljs>