Skip to content

Instantly share code, notes, and snippets.

@robey
Created July 23, 2015 18:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robey/8a774f32dc50456843a4 to your computer and use it in GitHub Desktop.
Save robey/8a774f32dc50456843a4 to your computer and use it in GitHub Desktop.
make a build.json with git history.
#!/usr/bin/env node
"use strict";
var child_process = require("child_process");
var fs = require("fs");
var path = require("path");
var strftime = require("strftime");
var util = require("util");
var pjson = JSON.parse(fs.readFileSync("package.json", "utf8"));
function main(argv) {
getGitHistory(function (history) {
var build = {};
build.version = pjson.version;
build.history = history;
build.date = strftime("%Y-%m-%d %H:%M:%S %Z", new Date());
build.timestamp = Math.floor(Date.now() / 1000);
fs.writeFileSync("./build.json", JSON.stringify(build, null, 2));
})
}
function getGitHistory(callback) {
child_process.exec("git log --decorate --oneline HEAD~10..HEAD", function (error, stdout, stderr) {
if (error) {
console.log("Couldn't get 10 commits: " + stderr);
// sometimes there aren't enough commits, and git will explode. just use all commits then.
child_process.exec("git log --decorate --oneline", function (error, stdout) {
if (error) {
console.log("Error running git log: " + error.stack);
process.exit(1);
}
return callback(stdout);
});
} else {
return callback(stdout);
}
});
}
main(process.argv.slice(2));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment