Created
August 26, 2015 15:06
-
-
Save lukin0110/4ebe4462cef79d26e043 to your computer and use it in GitHub Desktop.
Gulp git version, fetches the latest git commit hash. Can be used as version for your application. Inject/replace it in your html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var gulp = require('gulp'); | |
var spawn = require('child_process').spawn; | |
var GIT_VERSION = "na"; | |
gulp.task('version', function(){ | |
//git --git-dir=.git log --pretty='%ct %h' -1 | |
//git --git-dir=.git log --pretty='%h' -1 | |
var child = spawn("git", ["--git-dir=.git", "log", "--pretty=%h", "-1"], {cwd: process.cwd()}), | |
stdout = '', | |
stderr = ''; | |
child.stdout.setEncoding('utf8'); | |
child.stdout.on('data', function (data) { | |
stdout += data; | |
}); | |
child.stderr.setEncoding('utf8'); | |
child.stderr.on('data', function (data) { | |
stderr += data; | |
}); | |
child.on('close', function(code) { | |
var normalized = stdout.replace(/(?:\r\n|\r|\n)/g, "") | |
console.log("Version: " + normalized); | |
GIT_VERSION = normalized; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment