
Security News
Crates.io Implements Trusted Publishing Support
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
grunt-shell
Advanced tools
Grunt task to run shell commands.
E.g. compile Compass (compass compile
) or get the current git branch (git branch
).
Install this grunt plugin next to your project's grunt.js gruntfile with: npm install grunt-shell
Then add this line to your project's grunt.js
gruntfile:
grunt.loadNpmTasks('grunt-shell');
This grunt task is a multi task, which means you can specify multiple subtasks and grunt will iterate over them. The dist
below is a subtask, you could e.g. create a dev
subtask to handle stuff while developing. You can also add a special subtask named _options
that can contain options for all your subtasks.
Create a folder named test
.
shell: {
make_directory: {
command: 'mkdir test'
}
}
Output a directory listing to your Terminal.
shell: {
directory_listing: {
command: 'ls',
stdout: true
}
}
Do whatever you want with the stdout.
function log() {
console.log( this );
}
...
shell: {
directory_listing: {
command: 'ls',
stdout: log
}
}
Run a command in another directory. In this example we run it in a subfolder using the cwd
option.
shell: {
subfolder_ls: {
command: 'ls',
stdout: true,
execOptions: {
cwd: './tasks'
}
}
}
Define custom callback method to handle everything yourself. Check out shell.js to see how it's handled by default.
function customHandler() {
console.log( this, this.data.stdout );
}
...
shell: {
ls: {
command: 'ls',
callback: customHandler
}
}
This task is a multi task, which means you can specify multiple subtasks and grunt will iterate over them.
shell: {
directory_listing: {
command: 'ls',
stdout: true
},
compile_coffescript: {
command: 'coffee main.coffee',
failOnError: true
}
}
You can define global options in a subtask called _options
. Your subtasks will then inherit those options with the ability to override them.
shell: {
directory_listing: {
command: 'ls',
stdout: true
},
create_folder: {
command: 'mkdir test',
failOnError: false
},
_options: {
failOnError: true
}
}
Required
Accepts: String
Your command is my wish.
Default: false
Accepts: Boolean / Function
Show stdout in the Terminal. You can supply a function to handle the output.
Default: false
Accepts: Boolean / Function
Show stderr in the Terminal. You can supply a function to handle the output.
Default: false
Accepts: Boolean
Fail task if it encounters an error.
Default: undefined
Accepts: 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')Default: undefined
Accepts: Function
Lets you override the default callback with your own. Everything you need is available on this
.
Grunt currently doesn't have a way to test tasks directly. You can test this task by running grunt
and manually verify that it works.
In lieu of a formal styleguide, take care to maintain the existing coding style.
MIT License (c) Sindre Sorhus
FAQs
Run shell commands
The npm package grunt-shell receives a total of 68,412 weekly downloads. As such, grunt-shell popularity was classified as popular.
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
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.