Including gitCommit and version in frontend build. Backend now sending a backendInfo object containing commit, version and hostname. All printed on About page.

This commit is contained in:
softsimon
2021-04-12 22:17:13 +04:00
parent f61e3d8cec
commit 7a4ad0ee2f
12 changed files with 74 additions and 25 deletions

View File

@@ -5,6 +5,8 @@ const GENERATED_CONFIG_FILE_NAME = 'generated-config.js';
let settings = [];
let configContent = {};
let gitCommitHash = '';
let packetJsonVersion = '';
try {
const rawConfig = fs.readFileSync(CONFIG_FILE_NAME);
@@ -15,6 +17,13 @@ try {
}
}
try {
const packageJson = fs.readFileSync('package.json');
packetJsonVersion = JSON.parse(packageJson).version;
} catch (e) {
throw new Error(e);
}
for (setting in configContent) {
settings.push({
key: setting,
@@ -22,9 +31,17 @@ for (setting in configContent) {
});
}
try {
gitCommitHash = fs.readFileSync('../.git/refs/heads/master').toString().trim();
} catch (e) {
console.log('Could not load git commit info: ' + e.message || e);
}
const code = `(function (window) {
window.__env = window.__env || {};${settings.reduce((str, obj) => `${str}
window.__env.${obj.key} = ${ typeof obj.value === 'string' ? `'${obj.value}'` : obj.value };`, '')}
window.__env.GIT_COMMIT_HASH = '${gitCommitHash}';
window.__env.PACKAGE_JSON_VERSION = '${packetJsonVersion}';
}(global || this));`;
try {