Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including git-version-json with all npm packages installed. Try it out:

var gitVersionJson = require("git-version-json")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

git-version-json v1.0.6

A gulp friendly component for generating a json string that contains git version information.

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

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free