Security News
NIST Misses 2024 Deadline to Clear NVD Backlog
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
grunt-shell
Advanced tools
Run shell commands
A good way to interact with other CLI tools. E.g. compiling Compass compass compile
or get the current git branch git branch
.
Use Stack Overflow for support questions.
🔥 Want to strengthen your core JavaScript skills and master ES6?
I would personally recommend this awesome ES6 course by Wes Bos.
$ npm install --save-dev grunt-shell
require('load-grunt-tasks')(grunt); // npm install --save-dev load-grunt-tasks
grunt.initConfig({
shell: {
options: {
stderr: false
},
target: {
command: 'ls'
},
another: 'ls ./src' // shorthand
}
});
grunt.registerTask('default', ['shell']);
Create a folder named test
.
grunt.initConfig({
shell: {
makeDir: {
command: 'mkdir test'
}
}
});
The command
property supports templates:
grunt.initConfig({
testDir: 'test',
shell: {
makeDir: {
command: 'mkdir <%= testDir %>'
}
}
});
You can also supply a function that returns the command:
grunt.initConfig({
shell: {
hello: {
command: () => 'echo hello'
}
}
});
Which can also take arguments:
module.exports = grunt => {
grunt.loadNpmTasks('grunt-shell');
grunt.initConfig({
shell: {
greet: {
command: greeting => 'echo ' + greeting
}
}
});
grunt.registerTask('default', ['shell:greet:hello']);
}
Output a directory listing in your Terminal.
grunt.initConfig({
shell: {
dirListing: {
command: 'ls'
}
}
});
Do whatever you want with the output.
function log(err, stdout, stderr, cb) {
if (err) {
cb(err);
return;
}
console.log(stdout);
cb();
}
grunt.initConfig({
shell: {
dirListing: {
command: 'ls',
options: {
callback: log
}
}
}
});
Run a command in another directory. In this example we run it in a subfolder using the cwd
(current working directory) option.
grunt.initConfig({
shell: {
subfolderLs: {
command: 'ls',
options: {
stderr: false,
execOptions: {
cwd: 'tasks'
}
}
}
}
});
Run multiple commands by placing them in an array which is joined using &&
or ;
. &&
means run this only if the previous command succeeded. You can also use &
to have the commands run concurrently (by executing all commands except the last one in a subshell).
grunt.initConfig({
shell: {
multiple: {
command: [
'mkdir test',
'cd test',
'ls'
].join('&&')
}
}
});
Required
Type: String
Function
Command to run or a function which returns the command. Supports underscore templates.
Command can be omitted by directly setting the target with the command.
Type: Boolean
Default: true
Show stdout in the terminal.
Type: Boolean
Default: true
Show stderr in the terminal.
Type: Boolean
Default: true
Forward the terminal's stdin to the command.
Type: Boolean
Default: true
Fail task if it encounters an error. Doesn't apply if you specify a callback
.
Type: Boolean
Default: false
Set stdin
to act as a raw device.
Type: Function
Lets you override the default callback with your own.
Make sure to call the cb
method when you're done. Supply an error as the first argument to cb
to print a warning and cause the task to fail.
Type: Boolean
Default: false
Execute local binaries by name like npm run-script.
Type: Object
Specify some options to be passed to the .exec() method:
cwd
String Current working directory of the child processenv
Object Environment key-value pairssetsid
Booleanencoding
String (Default: 'utf8')timeout
Number (Default: 0)maxBuffer
Number (Default: 200*1024)killSignal
String (Default: 'SIGTERM')MIT © Sindre Sorhus
FAQs
Run shell commands
We found that grunt-shell demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.