Easy way to run shell commands, batch files or executable files in grunt.
This plugin requires Grunt ~0.4.0
.
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, you may install this plugin with this command:
npm install grunt-commands --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-commands');
This plugin was designed to work with Grunt 0.4.x. If you're still using grunt v0.3.x it's strongly recommended that you upgrade.
Run this task with the grunt commands
command.
Task targets, options may be specified according to the grunt Configuring tasks guide.
Type: Boolean
Default: true
watch: {
// ...
},
// this task (grunt-commands)
commands: {
options: {force: false},
target_1: {
cmd: 'xxx.js', // detected to nodejs
},
target_2: {
cmd: [
'xxx.sh', // detected to shell
{
cmd: 'xxx.bat', // detected to batch commands
force: true
},
'cd ./xxx/a' // any commands of OS supports
]
}
}
jshint: {
// ...
}
Use nodejs file as commands
commands : {
// Run tests via nodejs
tests: {
cmd: './test/tests.js'
},
// If file name has space chars
// you must write it like this.
// this is usually by Windows users
test2: {
cmd: './test/include\\ space.js'
},
}
Use shell file as commands (Only for Linux/Unix platform)
commands : {
// Deploy project via ShellScript
deploy: {
cmd : './test/deploy.sh',
force: true
}
}
Use batch commands file (Only for Windows platform).
commands : {
// Package to zip file via Windows batch file
zip: {
cmd : './test/zip.bat'
}
}
Custom commands your OS supports.
// this task
commands: {
someOthorCommands: {
cmd: [
// commands one
{
cmd: 'cd tmp && echo "Time `date`" > cmd.log',
// if dir `tmp` exists will throw an error,
// so set `force: true` to igone the error.
force: true
},
// commands two
'cd tmp && echo "Time `date`" > cmd2.log',
// Rename js file, special the extend name is `.js`
renameNodejsFile: {
cmd : 'mv ./tmp/nodejs.js ./tmp/nodejs-md.js'
},
// Delete shell file, special the extend name is `.sh`
renameNodejsFile: {
cmd : 'rm ./tmp/shell-md.sh'
}
]
}
},
grunt-contrib-commands
to grunt-commands
.node.child_process
.commands
.Task submitted by Colin Luo
This file was generated on Fri Jul 19 2013 0:29:15.