首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >咕哝、碰撞和提示提交消息

咕哝、碰撞和提示提交消息
EN

Stack Overflow用户
提问于 2018-04-01 19:02:53
回答 1查看 731关注 0票数 0

我是Grunt新手,但我尝试将咕噜声咕噜声结合起来,以便提示用户输入提交消息,然后将其添加到提交中。

我在Gruntfile.js中使用了来自这个职位的代码,但是提示元素不起作用。知道我做错什么了吗?

代码语言:javascript
复制
module.exports = function(grunt) {

  grunt.loadNpmTasks('grunt-bump');
  grunt.loadNpmTasks('grunt-prompt');

  grunt.initConfig({
    prompt: {
    commit: {
      options: {
        questions: [{
                   config: 'gitmessage',
                   type: 'input',
                   message: 'Commit Message'
                   }]
        }
      }
    },
    bump: {
    options: {
      files: ['package.json'],
      updateConfigs: [],
      commit: true,
      commitMessage: '<%=grunt.config("prompt.gitmessage")%>',
      commitFiles: ['package.json'],
      createTag: true,
      tagName: 'v%VERSION%',
      tagMessage: 'Version %VERSION%',
      push: true,
      pushTo: 'origin',
      gitDescribeOptions: '--tags --always --abbrev=1 --dirty=-d',
      globalReplace: false,
      prereleaseName: false,
      metadata: '',
      regExp: false
    }
  },
  });

};

这是终端输出:

代码语言:javascript
复制
$ grunt bump
Running "bump" task
>> Version bumped to 7.0.39 (in package.json)
>> Committed as " v7.0.39"
>> Tagged as "v7.0.39"
>> Pushed to origin

Done.
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-04-05 14:34:51

解决方案A:

您需要对您的Gruntfile.js进行一些更改,如下面的示例所示(参见注释1和2)

Gruntfile.js

代码语言:javascript
复制
module.exports = function(grunt) {

  grunt.loadNpmTasks('grunt-bump');
  grunt.loadNpmTasks('grunt-prompt');

  grunt.initConfig({

    prompt: {
      commit: {
        options: {
          questions: [{
            config: 'gitmessage',
            type: 'input',
            message: 'Commit Message'
          }]
        }
      }
    },
    bump: {
      options: {
        files: ['package.json'],
        updateConfigs: [],
        commit: true,
        commitMessage: '<%=grunt.config("gitmessage")%>',// 1) Change this.
        commitFiles: ['package.json'],
        createTag: true,
        tagName: 'v%VERSION%',
        tagMessage: 'Version %VERSION%',
        push: true,
        pushTo: 'origin',
        gitDescribeOptions: '--tags --always --abbrev=1 --dirty=-d',
        globalReplace: false,
        prereleaseName: false,
        metadata: '',
        regExp: false
      }
    }

  });

  grunt.registerTask('myBump', ['prompt:commit', 'bump']);// 2) Register new task.
}

Notes

  1. 首先,将commitMessage属性在bump任务中的值更改为: '<%=grunt.config("gitmessage")%>‘ 您当前在prompt.中的光栅模板部分被省略了。它应该是仅在config任务中指定的prompt属性的值。
  2. 接下来,注册一个新任务,我们称之为myBump。也就是说。 grunt.registerTask('myBump','prompt:commit','bump'); 重要:您可以为任务选择另一个名称,而不是myBump__,但是它不能被命名为bump,因为它将与现有任务发生冲突。 通过执行以下操作,这个新注册的任务确保prompt:commit任务在bump之前运行:
代码语言:javascript
复制
- [Alias Tasks](https://gruntjs.com/creating-tasks#alias-tasks) the `commit` [Target](https://gruntjs.com/configuring-tasks#task-configuration-and-targets) of your `prompt` task (i.e. `prompt:commit`).
- Then aliases the `bump` task.

运行任务

而不是通过CLI运行grunt bump,而是需要运行;grunt myBump

通过您的CLI运行grunt myBump将:

  1. 首先,提示您输入提交消息。例如: Running "prompt:commit" (prompt) task ? Commit Message,我的关于颠簸的消息
  2. 然后运行您的bump任务。例如: Running "bump" task >> Version bumped to 1.0.1 (in package.json) >> Committed as,我的关于颠簸的消息 >> Tagged as "v1.0.1"

解决方案B:

虽然解决方案A工作得很好,但它不适合所有的符号学版本。目前,每次运行PATCH时,它只会弹出grunt myBump版本。

也许,您的意图是启用一种处理各种类型的流量凸起的方法。其分类如下:

  • 当您进行不兼容的API更改时,主要版本,
  • 当您以向后兼容的方式添加功能时,次要版本,
  • 当您进行向后兼容的bug修复时,修补程序版本。

下面的Gruntfile.js显示了处理上面列出的任何一个版本类型的配置。

Gruntfile.js

代码语言:javascript
复制
module.exports = function(grunt) {

  grunt.loadNpmTasks('grunt-bump');
  grunt.loadNpmTasks('grunt-prompt');

  grunt.initConfig({

    prompt: {
      patch: {
        options: {
          questions: [{
            config: 'gitmessage',
            type: 'input',
            message: 'Commit message for PATCH version bump:'
          }]
        }
      },
      minor: {
        options: {
          questions: [{
            config: 'gitmessage',
            type: 'input',
            message: 'Commit message for MINOR version bump:'
          }]
        }
      },
      major: {
        options: {
          questions: [{
            config: 'gitmessage',
            type: 'input',
            message: 'Commit message for MAJOR version bump:'
          }]
        }
      }
    },
    bump: {
      options: {
        files: ['package.json'],
        updateConfigs: [],
        commit: true,
        commitMessage: '<%=grunt.config("gitmessage")%>',
        commitFiles: ['package.json'],
        createTag: true,
        tagName: 'v%VERSION%',
        tagMessage: 'Version %VERSION%',
        push: true,
        pushTo: 'origin',
        gitDescribeOptions: '--tags --always --abbrev=1 --dirty=-d',
        globalReplace: false,
        prereleaseName: false,
        metadata: '',
        regExp: false
      }
    }

  });

  grunt.registerTask('bump-patch', ['prompt:patch', 'bump:patch']);
  grunt.registerTask('bump-minor', ['prompt:minor', 'bump:minor']);
  grunt.registerTask('bump-major', ['prompt:major', 'bump:major']);
}

运行

使用上面所示的配置,您可以酌情通过CLI运行以下命令:

  • 若要运行PATCH版本,请运行: 凹凸补片
  • 若要运行MINOR版本,请运行: 凹凸小调
  • 若要运行MAJOR版本,请运行: 咕噜颠簸
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49601623

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档