Skip to content

Commit

Permalink
Добавил VersionHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
JoCat committed Aug 3, 2020
1 parent 01dcc8a commit fcba600
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 6 deletions.
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -50,4 +51,4 @@
"parser": "typescript"
}
}
}
}
5 changes: 2 additions & 3 deletions src/main/LauncherServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
)
)
Expand Down
4 changes: 2 additions & 2 deletions src/main/commands/basic/AboutCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -15,7 +15,7 @@ export class AboutCommand extends AbstractCommand {
colors.cyan("AuroraLauncher ") +
colors.green("LauncherServer ") +
"v" +
colors.yellow(`${App.Version} `)
colors.yellow(`${VersionHelper.getVersion()} `)
)
)

Expand Down
39 changes: 39 additions & 0 deletions src/main/helpers/VersionHelper.ts
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit fcba600

Please sign in to comment.