NPM软件包grunt-scaffoldThe docs确实缺少有关其after()属性/功能的任何信息。 。期望完成grunt scaffold:new_script命令并使它注销新生成的文件夹的位置。

Gruntfile.js

  module.exports = function(grunt) {
  grunt.initConfig({
  scaffold: {
    new_script: {
        options: {
            questions: [{
                name: 'script_name',
                type: 'input',
                message: 'Script name, catterpillar_case?(e.g. \'new_script\'):'
            }],
            template: {
                "scripts/etl_template/": "scripts/{{script_name}}/",
            },
            after: function(){

                console.log("New script generated in new folder scripts/{{script_name}}")
            }
        }
      }
    }
  });
  grunt.loadNpmTasks('grunt-scaffold');
  grunt.registerTask('default', ['scaffold']);
};


但是,输出是

-bash-4.1$ grunt scaffold:new_script
Running "scaffold:new_script" (scaffold) task
? Script name, catterpillar_case?(e.g. 'new_script'): test_grunt
New script generated in new folder scripts/{{script_name}}
Done.


这并没有像创建scripts/test_grunt文件夹时那样替换字符串!如您所见,the documentation对于after()功能几乎不存在,我想知道是否可以使用javascript“ system argume

最佳答案

文档中没有提供after()函数的示例,但是如果您使用与filter()示例相同的结果参数,则可以通过答案名称访问答案值。

Gruntfile.js

  module.exports = function(grunt) {
  grunt.initConfig({
  scaffold: {
    new_script: {
        options: {
            questions: [{
                name: 'script_name',
                type: 'input',
                message: 'Script name, catterpillar_case?(e.g. \'new_script\'):'
            }],
            template: {
                "scripts/etl_template/": "scripts/{{script_name}}/",
            },
            after: function(result){
                console.log("New script generated in new folder scripts/" + result.script_name)
            }
        }
      }
    }
  });
  grunt.loadNpmTasks('grunt-scaffold');
  grunt.registerTask('default', ['scaffold']);
};


输出量

-bash-4.1$ grunt scaffold:new_script
Running "scaffold:new_script" (scaffold) task
? Script name, catterpillar_case?(e.g. 'new_script'): test_grunt
New script generated in new folder scripts/test_grunt
Done.

关于javascript - Grunt-scaffold after()函数访问提示答案,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37471499/

10-13 02:12
查看更多