Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Gruntjs Grunt bump package.json版本_Gruntjs - Fatal编程技术网

Gruntjs Grunt bump package.json版本

Gruntjs Grunt bump package.json版本,gruntjs,Gruntjs,我想添加“发布”任务: grunt.initConfig({ ... 外壳:{ 发布:{ 命令:函数(版本){ 返回'git checkout-b release-'+version+'devel'; } } } ... grunt.loadNpmTasks(“grunt-bumpup”); grunt.loadNpmTasks(“grunt-shell”); ... registerTask('release',function()){ grunt.task.run('bumpup'); va

我想添加“发布”任务:

grunt.initConfig({
...
外壳:{
发布:{
命令:函数(版本){
返回'git checkout-b release-'+version+'devel';
}
}
}
...
grunt.loadNpmTasks(“grunt-bumpup”);
grunt.loadNpmTasks(“grunt-shell”);
...
registerTask('release',function()){
grunt.task.run('bumpup');
var version=grunt.config.get('pkg').version;
run('shell:release:'+version);
});
但我有以下几点:

Running "release" task

Running "bumpup" task
Bumped to: 1.2.5

Running "shell:release:1.2.4" (shell) task
Switched to a new branch 'release-1.2.4'
M   Gruntfile.js
M   package.json
M   src/manifest.json

Done, without errors.
所以版本被升级了,但分支是为以前的版本创建的

我想是因为package.json被缓存了。我可以重读它吗

 var version = grunt.file.readJSON('package.json').version; // old version too
编辑:

将“updateProps”添加到bumpup配置将更改pkg版本属性,但:

grunt.registerTask('release', function() {
  grunt.task.run('bumpup');

  var version = grunt.config.get('pkg').version;
  grunt.log.writeln(version); // old version, because tasks run async?

  grunt.task.run('shell:release:' + version);
});
效果很好:

grunt.initConfig({
  pkg: grunt.file.readJSON('package.json'),
  ...
  bumpup: {
    options: {
      updateProps: {
        pkg: 'package.json'
      }
    },
    files: ['package.json', 'src/manifest.json']
  },
  shell: {
    release: {
      command: function() {
        return 'git checkout -b release-' + grunt.config.get('pkg').version + ' devel';
      }
    }
  },
  ...
  grunt.loadNpmTasks('grunt-bumpup');
  grunt.loadNpmTasks('grunt-shell');
  ...
  grunt.registerTask('release', ['lint', 'bumpup', 'shell:release']);

您确定已设置grunt bumpup插件的
updateProps
选项吗?这将允许您在
bumpup
任务完成后指定要用新的bumped版本更新的文件

grunt.initConfig({
  ...
  bumpup: {
    options: {
      updateProps: {
        pkg: 'package.json'
      }
    },
    file: 'package.json'
  }
  ...
});