-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathversion.js
30 lines (25 loc) · 958 Bytes
/
version.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
'use strict';
var exec = require('child_process').exec;
const server = require('path').basename(__dirname);
var contentPromise = null;
// This is not used in production. Instead, the post-receive hook creates a static version.js.
module.exports = function (req, res) {
let content = `window.server = "${server}";`
if (contentPromise == null) {
contentPromise = new Promise(function (resolve, reject) {
exec('git describe --tags --long', {cwd: __dirname}, function (err, stdout) {
if (err) {
content += 'window.version = "";';
} else {
var v = stdout.replace(/[\r\n]/g, '');
content += `window.version = "${v}";`;
}
resolve(content);
});
});
}
contentPromise.then(function (content) {
res.set('Content-type', 'text/javascript');
res.send(content)
});
};