Skip to content

Commit

Permalink
Git revision JSON now includes version info about NodeJS and NPM buil…
Browse files Browse the repository at this point in the history
…d environment
  • Loading branch information
danielweck committed Nov 12, 2018
1 parent 7632fca commit 3670bb6
Showing 1 changed file with 55 additions and 33 deletions.
88 changes: 55 additions & 33 deletions tools/gitrev.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,64 @@ let json = {
"urlDiff": "NOT A GIT REPO?",
};

try {
var git = require("git-rev-sync");
var exec = require("child_process").exec;
exec("npm --version", function(execError, stdin, stderr) {
var npmVersion = "?";
if (execError) {
console.log(execError);

var fs = require("fs");
var path = require("path");
if (execError.code === 127) {
console.log("NPM not found?");
}
if (stderr) {
console.log(stderr.trim());
}
if (stdin) {
console.log(stdin.trim());
}
} else {
npmVersion = stdin.toString().trim(); // .split('\n')[0].trim();
}

try {
var git = require("git-rev-sync");

var fs = require("fs");
var path = require("path");

// console.log("process.cwd():");
// console.log(process.cwd());
// console.log("path.resolve(\".\")");
// console.log(path.resolve("."));

// console.log("process.cwd():");
// console.log(process.cwd());
// console.log("path.resolve(\".\")");
// console.log(path.resolve("."));
// console.log("__dirname:");
// console.log(__dirname);

// console.log("__dirname:");
// console.log(__dirname);
// const args = process.argv.slice(2);
// console.log("args:");
// console.log(args);

// const args = process.argv.slice(2);
// console.log("args:");
// console.log(args);
const detached = "Detached: ";
let branch = git.branch();
if (branch.indexOf(detached) === 0) {
branch = branch.substr(detached.length);
}
const gitUrlBase = "https://github.com/readium/r2-shared-js/";
json = {
"node": process.version.replace("v", ""),
"npm": npmVersion,
"short": git.short(),
"long": git.long(),
"branch": branch,
"date": git.date(),
// "dirty": git.isTagDirty(),
};
json["urlHistory"] = gitUrlBase + "commits/" + json.long;
json["urlDiff"] = gitUrlBase + "compare/" + json.long + "..." + json.branch;

const detached = "Detached: ";
let branch = git.branch();
if (branch.indexOf(detached) === 0) {
branch = branch.substr(detached.length);
// relative to process.cwd(), not __dirname
fs.writeFileSync("./dist/gitrev.json", JSON.stringify(json, null, " "), "utf8");
} catch (err) {
console.log(err);
}
const gitUrlBase = "https://github.com/readium/r2-shared-js/";
json = {
"short": git.short(),
"long": git.long(),
"branch": branch,
"date": git.date(),
"dirty": git.isTagDirty(),
};
json["urlHistory"] = gitUrlBase + "commits/" + json.long;
json["urlDiff"] = gitUrlBase + "compare/" + json.long + "..." + json.branch;

// relative to process.cwd(), not __dirname
fs.writeFileSync("./dist/gitrev.json", JSON.stringify(json, null, " "), "utf8");
} catch (err) {
console.log(err);
}
});

0 comments on commit 3670bb6

Please sign in to comment.