From 9b7ec1e516c49b2f1842c8189b71279a0ca75295 Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Sat, 25 Apr 2020 09:34:02 +0200 Subject: [PATCH] Nunjucks: distinguish application version from core version --- src/Application.ts | 7 ++++++- src/ApplicationComponent.ts | 6 ++++++ src/components/NunjucksComponent.ts | 3 ++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Application.ts b/src/Application.ts index ec0f38b..091988b 100644 --- a/src/Application.ts +++ b/src/Application.ts @@ -7,8 +7,8 @@ import ApplicationComponent from "./ApplicationComponent"; import Controller from "./Controller"; import MysqlConnectionManager from "./db/MysqlConnectionManager"; import Migration from "./db/Migration"; -import TemplateError = lib.TemplateError; import {Type} from "./Utils"; +import TemplateError = lib.TemplateError; export default abstract class Application { private readonly version: string; @@ -34,6 +34,7 @@ export default abstract class Application { this.webSocketListeners[path] = thing; Logger.info(`Added websocket listener on ${path}`); } else { + thing.setApp(this); this.components.push(thing); } } @@ -156,4 +157,8 @@ export default abstract class Application { public isReady(): boolean { return this.ready; } + + public getVersion(): string { + return this.version; + } } \ No newline at end of file diff --git a/src/ApplicationComponent.ts b/src/ApplicationComponent.ts index 183303e..c34b1cf 100644 --- a/src/ApplicationComponent.ts +++ b/src/ApplicationComponent.ts @@ -1,9 +1,11 @@ import {Express, Router} from "express"; import Logger from "./Logger"; import {sleep} from "./Utils"; +import Application from "./Application"; export default abstract class ApplicationComponent { private val?: T; + protected app?: Application; public abstract async start(app: Express, router: Router): Promise; @@ -18,6 +20,10 @@ export default abstract class ApplicationComponent { return this.val; } + public setApp(app: Application) { + this.app = app; + } + protected async prepare(name: string, prepare: () => Promise): Promise { let err; do { diff --git a/src/components/NunjucksComponent.ts b/src/components/NunjucksComponent.ts index dff672a..0af66ce 100644 --- a/src/components/NunjucksComponent.ts +++ b/src/components/NunjucksComponent.ts @@ -18,7 +18,8 @@ export default class NunjucksComponent extends ApplicationComponent { if (path === null) throw new ServerError(`Route ${route} not found.`); return path; }) - .addGlobal('app_version', require('../package.json').version) + .addGlobal('app_version', this.app!.getVersion()) + .addGlobal('core_version', require('../package.json').version) .addFilter('hex', (v: number) => { return v.toString(16); });