Use package.json version if version.txt is missing.

This commit is contained in:
gnuxie authored and Gnuxie committed 2023-02-11 15:59:50 +00:00
1 parent b7139b398c
commit fea67c3821
1 file changed
+10 -10
+10 -10
View File
@@ -285,9 +285,18 @@ export function getProvisionedMjolnirConfig(managementRoomId: string): IConfig {
return config;
}
export const PACKAGE_JSON = (() => {
try {
return JSON.parse(fs.readFileSync(path.join(__dirname, '../package.json'), 'utf-8'));
} catch (e) {
LogService.error("config", "Could not read Draupnir package.json", e);
return {};
}
})();
export const SOFTWARE_VERSION = (() => {
let versionFile;
const defaultText = "A version was either not provided when building Draupnir or could not be read.";
const defaultText = PACKAGE_JSON.version ?? "A version was either not provided when building Draupnir or could not be read.";
try {
versionFile = fs.readFileSync(path.join(__dirname, '../version.txt'), 'utf-8');
} catch (e) {
@@ -298,12 +307,3 @@ export const SOFTWARE_VERSION = (() => {
// into <pre> or <code> where it will create an unnecessary newline.
return /^(.*)$/m.exec(versionFile)?.at(0) ?? defaultText;
})();
export const PACKAGE_JSON = (() => {
try {
return JSON.parse(fs.readFileSync(path.join(__dirname, '../package.json'), 'utf-8'));
} catch (e) {
LogService.error("config", "Could not read Draupnir package.json", e);
return {};
}
})();