gruntjs:如何移动文件

时间:2013-09-30 06:26:01

标签: gruntjs

我需要在我的一个Grunt任务运行之前将文件移开,然后在任务完成后将其放回。

如何使用GruntJS执行此操作?

基本上我想运行这个命令:

# move node-webkit out of the way
mv app/node-webkit ./tmp

# run grunt task

# move node-webkit back
mv ./tmp/node-webkit ./app/

1 个答案:

答案 0 :(得分:3)

是的,请看grunt-shell。在你的init配置中:

shell: {
    move: {
        command: 'mv app/node-webkit ./tmp'
    },
    moveback: {
        command: 'mv ./tmp/node-webkit ./app/'
    }
}

然后,在您要运行的其他任务之前注册一个运行move命令的函数,然后运行moveback任务。

module.exports = function(grunt) {
    'use strict';
    grunt.registerTask('mytask', [
        'shell:move',
        'othertaskshere',
        'shell:moveback'
    ]);
};