Gruntjs 通过grunt提示任务组合任务(grunt bump)在提示后启动

Gruntjs 通过grunt提示任务组合任务(grunt bump)在提示后启动,gruntjs,grunt-prompt,Gruntjs,Grunt Prompt,使用Grunt,我正在运行一项任务,该任务会在package.json文件中增加我的版本号。但是我想提示用户他/她想要更新哪个版本。如果是正常更新,则运行较小的增量(x.+1.x),如果是补丁或修补程序,则应运行(x.x.+1)。为此,我有两个grunt任务: /* * Bump the version number to a new version */ bump: { options: { files: ['package

使用Grunt,我正在运行一项任务,该任务会在package.json文件中增加我的版本号。但是我想提示用户他/她想要更新哪个版本。如果是正常更新,则运行较小的增量(x.+1.x),如果是补丁或修补程序,则应运行(x.x.+1)。为此,我有两个grunt任务:

    /*
     * Bump the version number to a new version
     */

    bump: {
       options: {
         files: ['package.json'],
         updateConfigs: [],
         commit: true,
         commitMessage: 'Release v<%= pkg.version %>',
         commitFiles: ['package.json'],
         createTag: true,
         tagName: 'v<%= pkg.version %>',
         tagMessage: 'Version <%= pkg.version %>',
         push: true,
         pushTo: '<%= aws.gitUrl %>',
         gitDescribeOptions: '--tags --always --abbrev=1 --dirty=-d',
         globalReplace: false,
         prereleaseName: false,
         regExp: false
       }
     },

     /*
      * Prompt to see which bump should happen
      */

     prompt: {
       bumptype: {
         options: {
           questions: [
             {
               config: 'bump.increment',
               type: 'list',
               message: 'Bump version from ' + '<%= pkg.version %> to:',
               choices: [
                  {
                      value: 'patch',
                      name: 'Patch: Backwards-compatible bug fixes.'
                  },
                  {
                      value: 'minor',
                      name: 'Minor: Add functionality in a backwards-compatible manner.'
                  },
                ],
               } 
             ], 
            then: function(results) {
                 console.log(results['bump.increment']); // this outputs 'minor' and 'patch' to the console
             }
           }, // options
         } // bumptype
       }, // prompt
但是现在,当我运行
$grunt test
命令时,我确实会得到提示,之后无论您选择哪个选项,它都会运行bump minor任务


“grunt凹凸”选项通常采用以下参数:

$ grunt bump:minor
$ grunt bump:patch

因此,您应该在提示选项中或在registerTask命令中运行条件吗?

您可以像这样向registerTask发送参数

grunt.registerTask('test', function (bumptype) {
    if(bumptype)
      grunt.task.run('bumpup:' + bumptype);
});
你可以这样做

$ grunt test minor
$ grunt test patch

您可以像这样向registerTask发送参数

grunt.registerTask('test', function (bumptype) {
    if(bumptype)
      grunt.task.run('bumpup:' + bumptype);
});
你可以这样做

$ grunt test minor
$ grunt test patch

您可以像这样向registerTask发送参数

grunt.registerTask('test', function (bumptype) {
    if(bumptype)
      grunt.task.run('bumpup:' + bumptype);
});
你可以这样做

$ grunt test minor
$ grunt test patch

您可以像这样向registerTask发送参数

grunt.registerTask('test', function (bumptype) {
    if(bumptype)
      grunt.task.run('bumpup:' + bumptype);
});
你可以这样做

$ grunt test minor
$ grunt test patch

grunt任务可以添加到grunt提示符的“then”属性中:

then: function(results) {

    // console.log(results['bump.increment']);

    // run the correct bump version based on answer
    if (results['bump.increment'] === 'patch') {
      grunt.task.run('bump:patch'); 
    } else {
      grunt.task.run('bump:minor');
    }

}

grunt任务可以添加到grunt提示符的“then”属性中:

then: function(results) {

    // console.log(results['bump.increment']);

    // run the correct bump version based on answer
    if (results['bump.increment'] === 'patch') {
      grunt.task.run('bump:patch'); 
    } else {
      grunt.task.run('bump:minor');
    }

}

grunt任务可以添加到grunt提示符的“then”属性中:

then: function(results) {

    // console.log(results['bump.increment']);

    // run the correct bump version based on answer
    if (results['bump.increment'] === 'patch') {
      grunt.task.run('bump:patch'); 
    } else {
      grunt.task.run('bump:minor');
    }

}

grunt任务可以添加到grunt提示符的“then”属性中:

then: function(results) {

    // console.log(results['bump.increment']);

    // run the correct bump version based on answer
    if (results['bump.increment'] === 'patch') {
      grunt.task.run('bump:patch'); 
    } else {
      grunt.task.run('bump:minor');
    }

}


但是提示中的答案也需要调用,对吗?场景是
$grunt test
。然后,终端向用户提示问题“次要”或“补丁”。通过选择其中一个,您可以定义运行的任务。我认为像您所说的那样调用参数是朝着正确方向迈出的一步,尽管这种方法的优点是您甚至不需要提示。由于用户无论如何都要在终端提示符中键入版本,他们也可以在命令
$grunt test
中编写版本,但是这种提示符方法的思想是,您只需要一个命令,然后使用用户友好的选择。将来不仅仅是这两个。好的建议。调用它的方法应该是:grunt test:arg,但是也需要调用来自提示符的答案,对吗?场景是
$grunt test
。然后,终端向用户提示问题“次要”或“补丁”。通过选择其中一个,您可以定义运行的任务。我认为像您所说的那样调用参数是朝着正确方向迈出的一步,尽管这种方法的优点是您甚至不需要提示。由于用户无论如何都要在终端提示符中键入版本,他们也可以在命令
$grunt test
中编写版本,但是这种提示符方法的思想是,您只需要一个命令,然后使用用户友好的选择。将来不仅仅是这两个。好的建议。调用它的方法应该是:grunt test:arg,但是也需要调用来自提示符的答案,对吗?场景是
$grunt test
。然后,终端向用户提示问题“次要”或“补丁”。通过选择其中一个,您可以定义运行的任务。我认为像您所说的那样调用参数是朝着正确方向迈出的一步,尽管这种方法的优点是您甚至不需要提示。由于用户无论如何都要在终端提示符中键入版本,他们也可以在命令
$grunt test
中编写版本,但是这种提示符方法的思想是,您只需要一个命令,然后使用用户友好的选择。将来不仅仅是这两个。好的建议。调用它的方法应该是:grunt test:arg,但是也需要调用来自提示符的答案,对吗?场景是
$grunt test
。然后,终端向用户提示问题“次要”或“补丁”。通过选择其中一个,您可以定义运行的任务。我认为像您所说的那样调用参数是朝着正确方向迈出的一步,尽管这种方法的优点是您甚至不需要提示。由于用户无论如何都要在终端提示符中键入版本,他们也可以在命令
$grunt test
中编写版本,但是这种提示符方法的思想是,您只需要一个命令,然后使用用户友好的选择。将来不仅仅是这两个。好的建议。调用它的方法应该是:grunt test:arg