凹凸的SVN使用咕噜特定的版本号 [英] Bump a specific version number on SVN using Grunt

查看:165
本文介绍了凹凸的SVN使用咕噜特定的版本号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个AngularJS模块,具有内置咕噜。该模块的版本是在管理的的的package.json 的文件。

I have an AngularJS module, built with Grunt. The version of this module is managed in the package.json file.

我需要做什么

我需要创建一个咕噜任务在需要时释放模块。在这里,这是什么任务,必须做到:

I need to create a grunt task to release the module when needed. Here what this task must do :


  1. 上SVN执行当前模块的文件的标记(和它必须是SVN,不GIT)。

  2. 升级中的package.json版本给定的版本(例如,我会把--version = X.Y.Z作为选项繁重的任务)。我不想仅仅根据补丁,未成年人或重大的升级解决方案。

  3. 提交上的的package.json 的文件。
  4. 变更
  1. Perform a tag of the current module files on SVN (and it has to be SVN, not GIT).
  2. Upgrade the version in package.json to a given version (for example, I will pass --version = X.Y.Z as option to the grunt task). I don't want a solution based only on "patch", "minor" or "major" upgrades.
  3. Commit the change on the package.json file.

我发现至今

咕噜焊球可以让我通过一个特定的版本,使用--setversion选项。但它不能犯SVN上的变化,它只是与GIT的工作。

grunt-bump allows me to pass a specific version, using --setversion option. But it cannot commit the change on SVN, it's only working with GIT.

咕噜 - svn的焊球让我犯的SVN,但我能不能找到一种方法来指定一个版本。而且它不能执行标记的一部分。

grunt-svn-bump allows me to commit on SVN, but I can't find a way to specify the next version. And it cannot perform the "tag" part.

咕噜-SVN-标记可以让我上标记SVN库中的文件

grunt-svn-tag allows me to tag the files on SVN repository.

你知道另一个咕噜插件,可以适合?任何帮助将AP preciated。

Do you know another grunt plugin that could fit ? Any help will be appreciated.

推荐答案

我很无聊寻找现有任务,将适合,所以我终于创造了它的基础上,咕噜焊球和咕噜-SVN的code -bump:

I was bored looking for an existing task that would fit, so I finally created it, based on the code of grunt-bump and grunt-svn-bump :

grunt.registerTask('custom_bump', 'Custom task for bumping version after a release', function(){
    var semver = require('semver');
    var shell = require('shelljs');

    function shellRun( cmd ){
        if (grunt.option('dryRun')) {
            grunt.log.writeln('Command (not running because of dryRun option): ' + cmd);
        } else {
            grunt.verbose.writeln('Running: ' + cmd);
            var result = shell.exec(cmd, {silent:true});
            if (result.code !== 0) {
                grunt.log.error('Error (' + result.code + ') ' + result.output);
            }
        }
    }

    // Options
    var options = this.options({
        filepath: 'package.json',
        commit: true,
        commitMessage : 'New version following a release'
    });

    // Recover the next version of the component
    var nextVersion = grunt.option('nextVersion');
    if( !nextVersion ){
        grunt.fatal( 'Next version is not defined.', 3 );
    }
    else if( !semver.valid( nextVersion ) ){
        grunt.warn( 'Next version is invalid.', 3 );
    }

    // Upgrade version into package.json
    var filepath = options.filepath;
    var file = grunt.file.readJSON( filepath );
    var currentVersion = file.version;
    if( semver.lte( nextVersion, currentVersion ) ){
        grunt.warn( 'Next version is lesser or equal than current version.' );
    }
    file.version = nextVersion;
    grunt.log.write( 'Bumping version in ' + filepath + ' from ' + currentVersion + ' to ' + nextVersion + '... ' );
    grunt.file.write( filepath, JSON.stringify( file, null, 2 ) );
    grunt.log.ok();

    // Commit the changed package.json file
    if( options.commit ){
        var message =
        grunt.log.write( 'Committing ' +  filepath + '... ' );
        shellRun( 'svn commit "' + filepath + '" -m "' + options.commitMessage + '"' );
        grunt.log.ok();
    }

    // Update the config for next tasks
    var configProperty = 'pkg';
    grunt.log.write( 'Updating version in ' + configProperty + ' config... ' );
    var config = grunt.config( configProperty );
    if( config ){
        config.version = nextVersion;
        grunt.config( configProperty, config );
        grunt.log.ok();
    } else {
        grunt.log.warn( "Cannot update pkg config !" );
    }

    grunt.log.ok( 'Version updated from ' +  currentVersion + ' to ' + nextVersion + '.' );
});

我的'释放'任务使用咕噜-SVN-标记和我的自定义凹凸任务。

My 'release' task uses grunt-svn-tag and my custom bump task.

grunt.initConfig({
    // ...
    svn_tag: {
      current: {
        options: {
          tag: '<%= pkg.name %>-<%= pkg.version %>'
        }
      }
    }
});

grunt.registerTask('release', [
  'svn_tag:current',
  'custom_bump'
]);

这篇关于凹凸的SVN使用咕噜特定的版本号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆