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