我正在尝试使用 Grunt 在项目中为博客的新帖子创建一个目录。它实际上会在名为 YYYYMMDDDD-PostNameInPascalCase
的 posts
目录中创建一个目录。
为此,我必须在每次执行任务时提示用户输入帖子名称。我知道 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
}
]
}
},
},
})
关于javascript - 是否可以提示用户在任何 grunt 任务中输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16631332/