是否有可能提示用户输入任何grunt任务
Is it possible to prompt user for input in any grunt task?
我正在尝试使用Grunt在一个项目中创建一个目录,用于博客的新帖子。它实际上会在posts
目录中创建一个名为YYYYMMDDDD-PostNameInPascalCase
的目录。
为了做到这一点,我必须在每次执行任务时提示用户输入帖子名。我知道grunt-init提示用户从项目模板创建项目,但我很好奇是否有一种方法可以在Gruntfile.js
文件中为已经建立的项目做到这一点。
任何想法吗?
自从上次问这个问题以来已经有一段时间了,但是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。
相关文章:
- 函数参数中的数据与指定变量之间的任何性能差异
- 有没有任何方法可以将控制器从文件加载到ui路由器$stateProvider中
- jQuery中是否内置了任何字符串格式化函数
- 在单击任何位置时隐藏元素,而不检查每次DOM单击
- 是否有任何snippet或jQuery插件可以列出easylist.txt模式匹配的DOM中的所有元素
- Grunt匹配正则表达式
- 有任何可能将facebook实时信使整合到一个网站中
- 是否有任何方法可以使用jQuery替换在数组中定义值的文本
- 为什么grunt contrib connect的中间件选项的第三个参数是未定义的
- 如何将package.json数组传递给grunt.js
- AJAX:$_GET不返回任何值
- 在同一个服务工作者中处理service-worker.js有任何影响吗
- 将事件处理程序绑定到任何可能的事件
- 在Highcharts中,我们可以通过任何方式在渲染图表之前获得plotWidth和plotHeight
- 任何方式使AJAX调用Gmail API,而无需通过JS库
- document.styleSheets不返回任何内容
- 为什么我的 grunt-contrib-requirejs 没有优化任何东西
- Grunt-webpack说它“没有错误”,但没有捆绑任何东西
- 是否有可能提示用户输入任何grunt任务
- 任何使用grunt-contrib-jasmine输出规范运行程序的方法