feat: Store the server version on start

This commit is contained in:
Joachim Van Herwegen
2022-02-17 11:30:48 +01:00
parent 62e2210023
commit 2dc20fe3bc
7 changed files with 72 additions and 22 deletions

View File

@@ -0,0 +1,30 @@
import { readJson } from 'fs-extra';
import type { KeyValueStorage } from '../storage/keyvalue/KeyValueStorage';
import { modulePathPlaceholder, resolveAssetPath } from '../util/PathUtil';
import { Initializer } from './Initializer';
const PACKAGE_JSON_PATH = `${modulePathPlaceholder}package.json`;
/**
* This initializer simply writes the version number of the server to the storage.
* This will be relevant in the future when we look into migration initializers.
*
* It automatically parses the version number from the `package.json`.
*/
export class ModuleVersionVerifier extends Initializer {
private readonly storageKey: string;
private readonly storage: KeyValueStorage<string, string>;
public constructor(storageKey: string, storage: KeyValueStorage<string, string>) {
super();
this.storageKey = storageKey;
this.storage = storage;
}
public async handle(): Promise<void> {
const path = resolveAssetPath(PACKAGE_JSON_PATH);
const pkg = await readJson(path);
await this.storage.set(this.storageKey, pkg.version);
}
}