javascript - 是否可以提示用户在任何 grunt 任务中输入?

标签 javascript node.js gruntjs

我正在尝试使用 Grunt 在项目中为博客的新帖子创建一个目录。它实际上会在名为 YYYYMMDDDD-PostNameInPascalCaseposts 目录中创建一个目录。

为此,我必须在每次执行任务时提示用户输入帖子名称。我知道 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/

相关文章:

javascript - 在所有动画方法之间进行选择

javascript - 获取上传文件到S3的URL(文件上传后)

基于 grunt 的工作流程的 Flask 项目结构

node.js - 测试 Grunt 任务

linux - Grunt Package cmd 在运行 minall 任务时失败(ubuntu 和 windows)

javascript - 使用选择框在 div 之间交换类

javascript - 根据第一个单词对对象数组进行排序

javascript - 在 Javascript 中定义一个没有对象的 getter?

javascript - body :not(div. 类)不起作用

node.js - NodeJS Sequelize : Association with alias [alias] does not exist on [model]