Created
July 23, 2015 18:14
-
-
Save robey/8a774f32dc50456843a4 to your computer and use it in GitHub Desktop.
make a build.json with git history.
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
#!/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