是否有可能提示用户input任何咕噜任务?

我试图使用Grunt在一个项目中创build一个新的博客文章目录。 它本质上将创build一个名为YYYYMMDDDD-PostNameInPascalCaseposts目录内的目录。

为了做到这一点,我每次执行任务时都必须提示用户input用户名。 我知道grunt-init提示用户从项目模板创build项目,但我很好奇,如果有一种方法可以在Gruntfile.js文件中为已经build立的项目执行此操作。

有什么想法吗?

自从这个问题最后一次被问到,已经有一段时间了,但是Github上有一个项目,试图去做提问者正在寻找的东西。 它叫做grunt-prompt ,这里是url: https : //github.com/dylang/grunt-prompt 。 这基本上是一种将提示集成到Gruntfile的方法。 从项目自述你会做这样的事情:

 grunt.initConfig({ prompt: { target: { options: { questions: [ { config: 'config.name', // arbitray name or config for any other grunt task type: '<question type>', // list, checkbox, confirm, input, password message: 'Question to ask the user', default: 'value', // default value if nothing is entered choices: 'Array|function(answers)', validate: function(value), // return true if valid, error message if invalid filter: function(value), // modify the answer when: function(answers) // only ask this question when this function returns true } ] } }, }, }) 

是的,你可以做这样的事情:

 grunt.registerTask('makePost', 'Make a new post dir.', function(n) { if (n == null) { grunt.log.warn('Post name must be specified, like makePost:PostNameGoesHere.'); } // Run other tasks here grunt.task.run('foo:' + n, 'bar:' + n, 'baz:' + n); }); 

有关如何传递一些参数的更多信息和来源,请参阅Grunt FAQ 。