Created
May 6, 2014 21:43
-
-
Save jcmoore/09478cd19ba356687227 to your computer and use it in GitHub Desktop.
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
/* | |
* grunt-git-tag-parse | |
* https://github.com/dlasky/grunt-git-tag-parse | |
* | |
* Copyright (c) 2014 Dan Lasky | |
* Licensed under the MIT license. | |
*/ | |
'use strict'; | |
var when = require('when'), | |
co = require('co'); | |
module.exports = function(grunt) { | |
function spawn(options) { | |
var def = when.defer(); | |
grunt.util.spawn(options, function(err, result, code) { | |
if (err) { def.reject(err); } | |
if (result) { def.resolve(String(result)); } | |
}); | |
return def.promise; | |
} | |
grunt.registerMultiTask('git_tag_parse', 'write the current git tag to a variable', function() { | |
var options = this.options({ | |
number: 6, | |
revision: "HEAD", | |
property: "meta.revision" | |
}), | |
done = this.async(); | |
function writeResult(data) { | |
var dirty = data[0].split("\n"), | |
tag = data[1], | |
rev = data[2], | |
output = ""; | |
dirty = dirty.filter(function(item) { | |
var f = item.slice(0,2); | |
return f === "??" || f === " M"; | |
}); | |
if (tag !== "no tag") { | |
output += tag; | |
} else { | |
output += rev; | |
} | |
if (dirty.length) { | |
output += "(dirty)"; | |
} | |
grunt.log.ok(output); | |
grunt.config.set(options.property, output); | |
return output | |
} | |
co(function * () { | |
var list = yield when.all([ | |
spawn({ | |
cmd:"git", | |
args: ["status","--porcelain"] | |
}), | |
spawn({ | |
cmd:"git", | |
args: ["describe", "--exact-match", options.revision] | |
}).else("no tag"), | |
spawn({ | |
cmd:"git", | |
args: ["rev-parse", "--verify", "--short=" + options.number, options.revision] | |
}) | |
]); | |
writeResult(list); | |
}) (done); | |
}); | |
}; |
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
/* | |
* grunt-git-tag-parse | |
* https://github.com/dlasky/grunt-git-tag-parse | |
* | |
* Copyright (c) 2014 Dan Lasky | |
* Licensed under the MIT license. | |
*/ | |
'use strict'; | |
var when = require('when'), | |
co = require('co'); | |
module.exports = function(grunt) { | |
function spawn(options) { | |
var def = when.defer(); | |
grunt.util.spawn(options, function(err, result, code) { | |
if (err) { def.reject(err); } | |
if (result) { def.resolve(String(result)); } | |
}); | |
return def.promise; | |
} | |
grunt.registerMultiTask('git_tag_parse', 'write the current git tag to a variable', function() { | |
var options = this.options({ | |
number: 6, | |
revision: "HEAD", | |
property: "meta.revision" | |
}), | |
done = this.async(); | |
function writeResult(input, tag, rev) { | |
var dirty = input.split("\n"), | |
output = ""; | |
dirty = dirty.filter(function(item) { | |
var f = item.slice(0,2); | |
return f === "??" || f === " M"; | |
}); | |
if (tag !== "no tag") { | |
output += tag; | |
} else { | |
output += rev; | |
} | |
if (dirty.length) { | |
output += "(dirty)"; | |
} | |
grunt.log.ok(output); | |
grunt.config.set(options.property, output); | |
return output | |
} | |
co(function * () { | |
var input = spawn({ | |
cmd:"git", | |
args: ["status","--porcelain"] | |
}), | |
tag = spawn({ | |
cmd:"git", | |
args: ["describe", "--exact-match", options.revision] | |
}).else("no tag"), | |
rev = spawn({ | |
cmd:"git", | |
args: ["rev-parse", "--verify", "--short=" + options.number, options.revision] | |
}); | |
writeResult(yield input, yield tag, yield rev); | |
}) (done); | |
}); | |
}; |
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
/* | |
* grunt-git-tag-parse | |
* https://github.com/dlasky/grunt-git-tag-parse | |
* | |
* Copyright (c) 2014 Dan Lasky | |
* Licensed under the MIT license. | |
*/ | |
'use strict'; | |
var when = require('when'), | |
co = require('co'), | |
nodefn = require('when/node'); | |
module.exports = function(grunt) { | |
var spawn = nodefn.lift(grunt.util.spawn); | |
grunt.registerMultiTask('git_tag_parse', 'write the current git tag to a variable', function() { | |
var options = this.options({ | |
number: 6, | |
revision: "HEAD", | |
property: "meta.revision" | |
}), | |
done = this.async(); | |
function writeResult(input, tag, rev) { | |
var dirty = input.split("\n"), | |
output = ""; | |
dirty = dirty.filter(function(item) { | |
var f = item.slice(0,2); | |
return f === "??" || f === " M"; | |
}); | |
if (tag !== "no tag") { | |
output += tag; | |
} else { | |
output += rev; | |
} | |
if (dirty.length) { | |
output += "(dirty)"; | |
} | |
grunt.log.ok(output); | |
grunt.config.set(options.property, output); | |
return output | |
} | |
co(function * () { | |
var input = spawn({ | |
cmd:"git", | |
args: ["status","--porcelain"] | |
}), | |
tag = spawn({ | |
cmd:"git", | |
args: ["describe", "--exact-match", options.revision] | |
}).else("no tag"), | |
rev = spawn({ | |
cmd:"git", | |
args: ["rev-parse", "--verify", "--short=" + options.number, options.revision] | |
}); | |
writeResult(yield input, yield tag, yield rev); | |
}) (done); | |
}); | |
}; |
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
/* | |
* grunt-git-tag-parse | |
* https://github.com/dlasky/grunt-git-tag-parse | |
* | |
* Copyright (c) 2014 Dan Lasky | |
* Licensed under the MIT license. | |
*/ | |
'use strict'; | |
var when = require('when'); | |
module.exports = function(grunt) { | |
function spawn(options) { | |
var def = when.defer(); | |
grunt.util.spawn(options, function(err, result, code) { | |
if (err) { def.reject(err); } | |
if (result) { def.resolve(String(result)); } | |
}); | |
return def.promise; | |
} | |
grunt.registerMultiTask('git_tag_parse', 'write the current git tag to a variable', function() { | |
var options = this.options({ | |
number: 6, | |
revision: "HEAD", | |
property: "meta.revision" | |
}), | |
done = this.async(); | |
function writeResult(data) { | |
var def = when.defer(), | |
dirty = data[0].split("\n"), | |
tag = data[1], | |
rev = data[2], | |
output = ""; | |
dirty = dirty.filter(function(item) { | |
var f = item.slice(0,2); | |
return f === "??" || f === " M"; | |
}); | |
if (tag !== "no tag") { | |
output += tag; | |
} else { | |
output += rev; | |
} | |
if (dirty.length) { | |
output += "(dirty)"; | |
} | |
grunt.log.ok(output); | |
grunt.config.set(options.property, output); | |
def.resolve(output); | |
return def.promise; | |
} | |
when.all([ | |
spawn({ | |
cmd:"git", | |
args: ["status","--porcelain"] | |
}), | |
spawn({ | |
cmd:"git", | |
args: ["describe", "--exact-match", options.revision] | |
}).else("no tag"), | |
spawn({ | |
cmd:"git", | |
args: ["rev-parse", "--verify", "--short=" + options.number, options.revision] | |
}) | |
]) | |
.then(writeResult) | |
.done(done); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment