| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
parent directory.. | ||||
Requires grunt 0.4. Use version 0.1.4 for grunt 0.3 compatibility
Grunt task to 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.
If you haven't used grunt before, be sure to check out the Getting Started guide, as it explains how to create a gruntfile as well as install and use grunt plugins. Once you're familiar with that process, install this plugin with this command:
npm install --save-dev grunt-shellOnce the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-shell');grunt.initConfig({
shell: { // Task
listFolders: { // Target
options: { // Options
stdout: true
},
command: 'ls'
}
}
});
grunt.loadNpmTasks('grunt-shell');
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: {
makeDir: {
command: function () {
return 'echo hello';
}
}
}
});Which can also take arguments:
shell: {
makeDir: {
command: function (greeting) {
return 'echo ' + greeting;
}
}
}
grunt.loadNpmTasks('grunt-shell');
grunt.registerTask('default', ['shell:hello']);Output a directory listing in your Terminal.
grunt.initConfig({
shell: {
dirListing: {
command: 'ls',
options: {
stdout: true
}
}
}
});Do whatever you want with the output.
function log(err, stdout, stderr, cb) {
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: {
stdout: true,
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 succeded. 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
The command you want to run or a function which returns it. Supports underscore templates.
Default: false
Type: Boolean
Show stdout in the Terminal.
Default: false
Type: Boolean
Show stderr in the Terminal.
Default: false
Type: Boolean
Fail task if it encounters an error. Does not apply if you specify a callback.
Default: function () {}
Type: Function
Lets you override the default callback with your own.
Make sure to call the cb method when you're done.
Default: undefined
Accepts: Object
Specify some options to be passed to the .exec() method:
Because of the transition to grunt 0.4 there are some changes. To conform to new grunt standards, all options are now to be specified in an options object. I also took the opportunity to improve the task. The stdout and stderr options now only supports a boolean. If you want to do something with the result use the callback option. The callback option also changed.
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.
MIT License • © Sindre Sorhus
| Back | FazBrowse Home | New Git URL |