From f2517e919cae4d97454549f1ebd0d09f80ceff51 Mon Sep 17 00:00:00 2001 From: Kris Kowal Date: Tue, 20 Aug 2013 17:27:17 -0700 Subject: [PATCH] Compute a release name for S3 --- Gruntfile.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Gruntfile.js b/Gruntfile.js index 8f007fc0..c3f48494 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -3,6 +3,28 @@ var fs = require("fs"); var path = require("path"); +// compute a release name for S3 based on the version in package.json and +// whether the git HEAD matches the tag for the corresponding version +var config = require("./package.json"); +var headPath = path.join(__dirname, ".git", "HEAD"); +var tagPath = path.join(__dirname, ".git", "refs", "tags", "v" + config.version); +var releaseName; +if (fs.existsSync(headPath)) { + var headHash = fs.readFileSync(headPath, "ascii").trim(); + if (fs.existsSync(tagPath)) { + var tagHash = fs.readFileSync(tagPath, "ascii").trim(); + if (tagHash === headHash) { + releaseName = config.version; + } else { + releaseName = headHash; + } + } else { + releaseName = headHash; + } +} else { + releaseName = "default"; +} + module.exports = function (grunt) { ["grunt-contrib-uglify", "grunt-contrib-clean",