运行 一个 Grunt 任务之前的确认

Confirmation before running a Grunt task

我在 Gruntfile.js 中有一个任务可能会擦除我的项目,为了安全起见,我想在 运行 之前用 "Are you sure you want to run this task?" 问题来保护它。类似于:

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');
});

但我不知道如何让它等待键盘输入并读取输入。也找不到这个记录。

看看grunt-prompt or grunt-confirm

别这样!你会后悔的!

Grunt 是一个构建工具,您的 grunt 脚本应该只能擦除它创建的内容。不管你当前状态背后的原因是什么,改变它。将工具用于其本来的用途,而不是用于擦除您不想丢失的东西。