Moved version settings to version.json #294
This commit is contained in:
parent
a869ee4780
commit
a3229848ef
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "kdb-web",
|
||||
"version": "1.0.dev268_achievements",
|
||||
"version": "1.0.dev294_frontend_version",
|
||||
"scripts": {
|
||||
"ng": "ng",
|
||||
"update-version": "ts-node-esm update-version.ts",
|
||||
|
21
kdb-web/src/app/models/config/app-settings.ts
Normal file
21
kdb-web/src/app/models/config/app-settings.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import { SoftwareVersion } from "./software-version";
|
||||
import { Theme } from '../view/theme';
|
||||
|
||||
export interface AppAndVersionSettings {
|
||||
ApiURL: string;
|
||||
PrivacyURL: string;
|
||||
ImprintURL: string;
|
||||
Themes: Theme[];
|
||||
WebVersion: SoftwareVersion;
|
||||
}
|
||||
|
||||
export interface AppSettings {
|
||||
ApiURL: string;
|
||||
PrivacyURL: string;
|
||||
ImprintURL: string;
|
||||
Themes: Theme[];
|
||||
}
|
||||
|
||||
export interface VersionSettings {
|
||||
WebVersion: SoftwareVersion;
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
import { SoftwareVersion } from "./software-version";
|
||||
import { Theme } from '../view/theme';
|
||||
|
||||
export interface Appsettings {
|
||||
ApiURL: string;
|
||||
PrivacyURL: string;
|
||||
ImprintURL: string;
|
||||
WebVersion: SoftwareVersion;
|
||||
Themes: Theme[];
|
||||
}
|
@ -1,76 +1,86 @@
|
||||
import { HttpClient } from "@angular/common/http";
|
||||
import { Injectable } from "@angular/core";
|
||||
import { throwError } from "rxjs";
|
||||
import { forkJoin, throwError } from "rxjs";
|
||||
import { catchError } from "rxjs/operators";
|
||||
import { Appsettings } from "src/app/models/config/appsettings";
|
||||
import { AppAndVersionSettings, AppSettings, VersionSettings } from "src/app/models/config/app-settings";
|
||||
import { SoftwareVersion } from "src/app/models/config/software-version";
|
||||
import { Theme } from "src/app/models/view/theme";
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
providedIn: "root"
|
||||
})
|
||||
export class SettingsService {
|
||||
appsettings!: Appsettings;
|
||||
appSettings!: AppSettings;
|
||||
versionSettings!: VersionSettings;
|
||||
|
||||
constructor(
|
||||
private http: HttpClient
|
||||
) { }
|
||||
) {
|
||||
}
|
||||
|
||||
loadSettings(): Promise<Appsettings> {
|
||||
loadSettings(version: boolean = false): Promise<AppAndVersionSettings> {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.http.get<Appsettings>('../../assets/config.json')
|
||||
forkJoin([
|
||||
this.http.get<AppSettings>("../../assets/config.json")
|
||||
.pipe(catchError(error => {
|
||||
reject(error);
|
||||
return throwError(() => error);
|
||||
})).subscribe(settings => {
|
||||
this.appsettings = settings;
|
||||
resolve(settings);
|
||||
})),
|
||||
this.http.get<VersionSettings>("../../assets/version.json")
|
||||
.pipe(catchError(error => {
|
||||
reject(error);
|
||||
return throwError(() => error);
|
||||
}))
|
||||
]).subscribe(settings => {
|
||||
this.appSettings = settings[0];
|
||||
this.versionSettings = settings[1];
|
||||
resolve({...settings[0], ...settings[1]});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public getApiURL(): string {
|
||||
if (!this.appsettings || !this.appsettings.ApiURL) {
|
||||
console.error('ApiUrl is not set!');
|
||||
if (!this.appSettings || !this.appSettings.ApiURL) {
|
||||
console.error("ApiUrl is not set!");
|
||||
return "";
|
||||
}
|
||||
return this.appsettings.ApiURL;
|
||||
return this.appSettings.ApiURL;
|
||||
}
|
||||
|
||||
public getPrivacyURL(): string {
|
||||
if (!this.appsettings || !this.appsettings.PrivacyURL) {
|
||||
console.error('PrivacyURL is not set!');
|
||||
if (!this.appSettings || !this.appSettings.PrivacyURL) {
|
||||
console.error("PrivacyURL is not set!");
|
||||
return "";
|
||||
}
|
||||
return this.appsettings.PrivacyURL;
|
||||
return this.appSettings.PrivacyURL;
|
||||
}
|
||||
|
||||
public getImprintURL(): string {
|
||||
if (!this.appsettings || !this.appsettings.ImprintURL) {
|
||||
console.error('ImprintURL is not set!');
|
||||
if (!this.appSettings || !this.appSettings.ImprintURL) {
|
||||
console.error("ImprintURL is not set!");
|
||||
return "";
|
||||
}
|
||||
return this.appsettings.ImprintURL;
|
||||
return this.appSettings.ImprintURL;
|
||||
}
|
||||
|
||||
public getWebVersion(): SoftwareVersion | null {
|
||||
if (!this.appsettings || !this.appsettings.WebVersion) {
|
||||
console.error('WebVersion is not set!');
|
||||
if (!this.versionSettings || !this.versionSettings.WebVersion) {
|
||||
console.error("WebVersion is not set!");
|
||||
return null;
|
||||
}
|
||||
return new SoftwareVersion(
|
||||
this.appsettings.WebVersion.Major,
|
||||
this.appsettings.WebVersion.Minor,
|
||||
this.appsettings.WebVersion.Micro
|
||||
this.versionSettings.WebVersion.Major,
|
||||
this.versionSettings.WebVersion.Minor,
|
||||
this.versionSettings.WebVersion.Micro
|
||||
);
|
||||
}
|
||||
|
||||
public getThemes(): Theme[] | null {
|
||||
if (!this.appsettings || !this.appsettings.Themes) {
|
||||
console.error('Themes is not set!');
|
||||
if (!this.appSettings || !this.appSettings.Themes) {
|
||||
console.error("Themes is not set!");
|
||||
return null;
|
||||
}
|
||||
return this.appsettings.Themes;
|
||||
return this.appSettings.Themes;
|
||||
}
|
||||
}
|
||||
|
||||
|
7
kdb-web/src/assets/version.json
Normal file
7
kdb-web/src/assets/version.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"WebVersion": {
|
||||
"Major": "1",
|
||||
"Minor": "0",
|
||||
"Micro": "dev294_frontend_version"
|
||||
}
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
import { Appsettings } from "./src/app/models/config/appsettings";
|
||||
import { VersionSettings } from "./src/app/models/config/app-settings";
|
||||
import { SoftwareVersion } from "./src/app/models/config/software-version";
|
||||
import fs from "fs";
|
||||
|
||||
const jsonFilePath = "./src/assets/config.json";
|
||||
const jsonFilePath = "./src/assets/version.json";
|
||||
|
||||
function Main(): void {
|
||||
getVersion()
|
||||
@ -38,13 +38,13 @@ async function getVersion(): Promise<SoftwareVersion> {
|
||||
}
|
||||
} else if (branch.startsWith("#")) {
|
||||
const fs = require("fs");
|
||||
const config: Appsettings = JSON.parse(fs.readFileSync(jsonFilePath, "utf-8"));
|
||||
const config: VersionSettings = JSON.parse(fs.readFileSync(jsonFilePath, "utf-8"));
|
||||
major = config.WebVersion.Major;
|
||||
minor = config.WebVersion.Minor;
|
||||
micro = `dev${branch.split("#")[1]}`;
|
||||
} else {
|
||||
const fs = require("fs");
|
||||
const config: Appsettings = JSON.parse(fs.readFileSync(jsonFilePath, "utf-8"));
|
||||
const config: VersionSettings = JSON.parse(fs.readFileSync(jsonFilePath, "utf-8"));
|
||||
major = config.WebVersion.Major;
|
||||
minor = config.WebVersion.Minor;
|
||||
micro = config.WebVersion.Micro;
|
||||
@ -59,7 +59,7 @@ async function setVersion(version: SoftwareVersion) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
const settings: Appsettings = JSON.parse(data);
|
||||
const settings: VersionSettings = JSON.parse(data);
|
||||
settings.WebVersion = version;
|
||||
fs.writeFile(jsonFilePath, JSON.stringify(settings, null, 4), "utf8", () => {
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user