-
Notifications
You must be signed in to change notification settings - Fork 2
/
create_service_info.js
58 lines (51 loc) · 1.62 KB
/
create_service_info.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
const childProcess = require("child_process");
const packageData = require("./package.json");
const nodeEnv = process.env.NODE_ENV || "production";
const serviceType = {
group: "ca.c3g.bento",
artifact: "web",
version: packageData.version,
};
const serviceID = process.env.SERVICE_ID || `${serviceType.group}:${serviceType.artifact}`;
const serviceInfo = {
id: serviceID,
name: "Bento Web",
description: "Private-access web interface for the Bento platform.",
type: serviceType,
version: packageData.version,
environment: nodeEnv === "production" ? "prod" : "dev",
organization: {
name: "C3G",
url: "https://www.computationalgenomics.ca",
},
contactUrl: "mailto:[email protected]",
bento: {
serviceKind: "web",
},
};
const hasGit = (() => {
try {
return childProcess.execSync("which git").toString().trim() === "";
} catch (_e) {
// Exit code 1 (git not found)
return false;
}
})();
const git = cmd => childProcess.execSync(`git ${cmd}`).toString().trim();
if (nodeEnv === "development" && hasGit) {
try {
serviceInfo.bento.gitTag = git("describe --tags --abbrev=0");
serviceInfo.bento.gitBranch = git("branch --show-current");
serviceInfo.bento.gitCommit = git("rev-parse HEAD");
} catch (e) {
console.warn(`Could not get git information (${e})`);
}
} else if (!hasGit) {
console.warn("Could not get git information (missing git)");
}
if (typeof require !== "undefined" && require.main === module) {
console.log(JSON.stringify(serviceInfo, null, 2));
}
module.exports = {
serviceInfo,
};