运行Grunt任务之前进行确认

我在Gruntfile.js中有一个任务可能会擦掉我的项目,我想用“你确定要运行这个任务吗?”来保护它。 运行之前的问题,只是为了安全。 就像是:

grunt.registerTask('install', 'Run this only once when starting a project!', function() { console.log('Are you sure? Y/n:'); // If yes, continue with task grunt.task.run('copy_install'); }); 

但我不知道如何使它等待键盘input和读取input。 无法find这个logging。

不要这样做! 你会后悔的!

Grunt是一个构build工具,你的grunt脚本应该只能擦除它创build的内容。 无论现在状态背后的原因是什么,都要改变它。 使用这个工具是为了做什么,而不是抹去你不想丢失的东西。

看看grunt-prompt或grunt-confirm 。