1.0.6 • Published 7 years ago

git-version-json v1.0.6

Weekly downloads
6
License
MIT
Repository
github
Last release
7 years ago

git-version-json

npm version Build Status

Generate a json variable with git version informations.

It is NOT a gulp plugin, but gulp friendly. It is usually use with gulp-replace, gulp-header or gulp-footer. It is also can use separatedly.

The generated json looks like as:

var gitVersion={"branch":"master","rev":"2","hash":"53d4271","hash160":"53d4271d8d7e7647fabc0d5086acd4f000a04046"};

Check index.js

Sample

var gulp = require('gulp');
var concat = require('gulp-concat');
var replace = require('gulp-replace');
var header = require('gulp-header');
var footer = require('gulp-footer');
var GitVersionJson = require('git-version-json');

// automatic use git-rev in version field of package.json
gulp.task('build-auto', [GitVersionJson.taskPkgVersion], function(){
    // TODO: do others building logic
});

// this is the same to use 'GitVersionJson.taskPkgVersion'
gulp.task('build-manual', [GitVersionJson.task], ()=>{
    return gulp.src('package.json')
        .pipe(replace(/(\"version\"\s*:\s*\"\d+\.\d+\.)(\d+)(\-.+)?(\")/,
            "$1" + MarkGitVersion.gitVer.rev + "$3$4"))
        .pipe(gulp.dest('.'))
});

// add a header json variable
gulp.task('build-header', [GitVersionJson.task], function(){
    return gulp.src('js/**/*')
        .pipe(concat('all.min.js'))
        .pipe(header("var gitVersion=${version};\n",
            { version: GitVersionJson.getGitVerStr() }))
        .pipe(gulp.dest('build/js'));
});

// add a footer
gulp.task('build-footer', [GitVersionJson.task], function(){
    return gulp.src('js/**/*')
        .pipe(concat('all.min.js'))
        .pipe(footer("var gitVersion=<%=version%>;\n",
            { version: JSON.stringify(GitVersionJson.gitVer) }))
        .pipe(gulp.dest('build/js'));
});

A complete sample locates in ali-mns/gulpfile.js

Privacy Policy

We collect information about how you use the git-version-json packages for better service.

By default a tracing information is sent to google analytics when fetching version number, The tracing information contains only a rev number. Any of your data will not be sent. You can check code about data collection.

You can always disable data collection as you wish.

    var GitVersionJson = require('git-version-json');
    // Disable google analytics data collection
    GitVersionJson.disableGA(true);
    

License

MIT