我正在尝试使用Grunt在一个项目中为博客的新帖子创建一个目录。它实际上会在名为YYYYMMDDDD-PostNameInPascalCase的posts目录中创建一个目录。
为了做到这一点,我必须在每次执行任务时提示用户输入帖子名称。我知道grunt-init会提示用户从项目模板创建项目,但是我很好奇在已经建立的项目的Gruntfile.js文件中有没有这样做的方法。
有什么想法吗?
发布于 2013-10-03 02:40:22
距离上一次问这个问题已经有一段时间了,但是Github上有一个项目试图做提问者正在寻找的事情。它的名字是grunt-prompt,网址是: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
}
]
}
},
},
})发布于 2013-08-07 16:03:05
是的,你可以这样做:
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。
https://stackoverflow.com/questions/16631332
复制相似问题