インストール
$ npm install --save-dev grunt-shell
単純にコマンドを出力する
Gruntfile.js
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-shell');
grunt.initConfig({
shell: {
hello: {
command: 'echo hello world!'
}
}
});
grunt.registerTask('default', ['shell']);
};
実行
$ grunt
> Running "shell:makeDir" (shell) task
> hello world!
> Done, without errors.
コールバックを実行する
Gruntfile.js
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-shell');
grunt.registerTask('ls', function() {
var exec = require('child_process').exec;
var done = this.async();
// 実行するコマンド
var command = 'ls';
var options = {
timeout: 10000
};
var callback = function(err, stdout, stderr) {
// コールバック処理
console.log(stdout);
done();
};
exec(command, options, callback);
});
};