-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathgitrev.js
71 lines (62 loc) · 2.07 KB
/
gitrev.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
let json = {
"short": "NOT A GIT REPO?",
"long": "NOT A GIT REPO?",
"branch": "NOT A GIT REPO?",
"date": "NOT A GIT REPO?",
"dirty": "NOT A GIT REPO?",
"urlHistory": "NOT A GIT REPO?",
"urlDiff": "NOT A GIT REPO?",
};
var exec = require("child_process").exec;
exec("npm --version", function(execError, stdin, stderr) {
var npmVersion = "?";
if (execError) {
console.log(execError);
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("__dirname:");
// console.log(__dirname);
// 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-streamer-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;
// relative to process.cwd(), not __dirname
fs.writeFileSync("./dist/gitrev.json", JSON.stringify(json, null, " "), "utf8");
} catch (err) {
console.log(err);
}
});