diff --git a/package-lock.json b/package-lock.json index 3dbc0fc7..aa7848e8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -295,6 +295,15 @@ "@types/node": "*" } }, + "@types/semver": { + "version": "7.3.1", + "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.3.1.tgz", + "integrity": "sha512-ooD/FJ8EuwlDKOI6D9HWxgIgJjMg2cuziXm/42npDC8y4NjxplBUn9loewZiBNCt44450lHAU0OSb51/UqXeag==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, "@types/ws": { "version": "7.2.6", "resolved": "https://registry.npmjs.org/@types/ws/-/ws-7.2.6.tgz", diff --git a/package.json b/package.json index 4ffdb224..5b3e2e99 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "@types/decompress": "^4.2.3", "@types/node": "^12.12.21", "@types/rimraf": "^3.0.0", + "@types/semver": "^7.3.1", "@types/ws": "^7.2.6", "cli-progress": "^3.8.2", "colors": "^1.4.0", @@ -50,4 +51,4 @@ "parser": "typescript" } } -} \ No newline at end of file +} diff --git a/src/main/LauncherServer.ts b/src/main/LauncherServer.ts index 7e276da5..3ebe807a 100644 --- a/src/main/LauncherServer.ts +++ b/src/main/LauncherServer.ts @@ -11,6 +11,7 @@ import { MirrorManager } from "./mirror/MirrorManager" import { ModulesManager } from "./modules/ModulesManager" import { SocketManager } from "./requests/SocketManager" import { UpdatesManager } from "./updates/UpdatesManager" +import { VersionHelper } from "./helpers/VersionHelper" export class LauncherServer { readonly ConfigManager: ConfigManager @@ -20,16 +21,14 @@ export class LauncherServer { readonly ModulesManager: ModulesManager readonly SocketManager: SocketManager readonly UpdatesManager: UpdatesManager - readonly Version: string // TODO Version constructor() { - this.Version = "0.0.1-dev" LogHelper.raw( colors.bold( colors.cyan("AuroraLauncher ") + colors.green("LauncherServer ") + "v" + - colors.yellow(`${this.Version} `) + + colors.yellow(`${VersionHelper.getVersion()} `) + colors.blue("https://gitlab.com/aurorateam") ) ) diff --git a/src/main/commands/basic/AboutCommand.ts b/src/main/commands/basic/AboutCommand.ts index 8573dffe..0f1c8714 100644 --- a/src/main/commands/basic/AboutCommand.ts +++ b/src/main/commands/basic/AboutCommand.ts @@ -2,7 +2,7 @@ import * as colors from "colors/safe" import { LogHelper } from "../../helpers/LogHelper" import { AbstractCommand, Category } from "../AbstractCommand" -import { App } from "../../LauncherServer" +import { VersionHelper } from "../../helpers/VersionHelper" export class AboutCommand extends AbstractCommand { constructor() { @@ -15,7 +15,7 @@ export class AboutCommand extends AbstractCommand { colors.cyan("AuroraLauncher ") + colors.green("LauncherServer ") + "v" + - colors.yellow(`${App.Version} `) + colors.yellow(`${VersionHelper.getVersion()} `) ) ) diff --git a/src/main/helpers/VersionHelper.ts b/src/main/helpers/VersionHelper.ts new file mode 100644 index 00000000..44847909 --- /dev/null +++ b/src/main/helpers/VersionHelper.ts @@ -0,0 +1,39 @@ +import { valid, SemVer } from "semver"; + +export enum VersionType { + RELEASE = "release", // or STABLE? + DEV = "dev", + TESTING = "testing", + LTS = "lts" + // etc? +} + +export class VersionHelper { + static MAJOR: number = 0 + static MINOR: number = 0 + static PATCH: number = 1 + static TYPE: VersionType = VersionType.DEV + + /** + * Получить обработанную версию лаунчсервера в виде строки + * @returns `string` + */ + static getVersion(): string { + if (!this.TYPE) { + return `${this.MAJOR}.${this.MINOR}.${this.PATCH}` + } else { + return `${this.MAJOR}.${this.MINOR}.${this.PATCH}-${this.TYPE}` + } + } + + /** + * **Обёртка над `semver.valid`** + * + * Возвращает обработанную версию в виде строки или null, если она недействительна + * @param version - Версия в виде строки или объекта SemVer + * @returns `string` или `null` + */ + static versionValidate(version: string | SemVer | null | undefined): string | null { + return valid(version) + } +}