From 47f294a982e078358f360c970add4aaf918a36f0 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Fri, 21 Oct 2022 13:50:11 +0200 Subject: [PATCH] Improved set version for frontend #70 --- kdb-web/package.json | 2 +- kdb-web/src/assets/config.json | 4 +- kdb-web/update-version.ts | 102 ++++++++++++++++++--------------- 3 files changed, 58 insertions(+), 50 deletions(-) diff --git a/kdb-web/package.json b/kdb-web/package.json index d4f71ecdba..f8c849a940 100644 --- a/kdb-web/package.json +++ b/kdb-web/package.json @@ -1,6 +1,6 @@ { "name": "kdb-web", - "version": "0.3.0", + "version": "0.3.dev70", "scripts": { "ng": "ng", "update-version": "ts-node -O '{\"module\": \"commonjs\"}' update-version.ts", diff --git a/kdb-web/src/assets/config.json b/kdb-web/src/assets/config.json index f135341693..c4b8e593b0 100644 --- a/kdb-web/src/assets/config.json +++ b/kdb-web/src/assets/config.json @@ -2,8 +2,8 @@ "ApiURL": "http://localhost:5000", "WebVersion": { "Major": "0", - "Minor": "0", - "Micro": "0" + "Minor": "3", + "Micro": "dev70" }, "Themes": [ { diff --git a/kdb-web/update-version.ts b/kdb-web/update-version.ts index 9131c49960..fd4955f13b 100644 --- a/kdb-web/update-version.ts +++ b/kdb-web/update-version.ts @@ -1,54 +1,62 @@ -import { Appsettings } from 'src/app/models/config/appsettings'; -import { SoftwareVersion } from './src/app/models/config/software-version'; +import { Appsettings } from "./src/app/models/config/appsettings"; +import { SoftwareVersion } from "./src/app/models/config/software-version"; -const jsonFilePath = './src/assets/config.json'; +const jsonFilePath = "./src/assets/config.json"; function Main(): void { - getVersion() - .then(version => { - setVersion(version); - }) - .catch(err => { - throw err; - }); -} - -async function getVersion(): Promise { - const util = require('util'); - const exec = util.promisify(require('child_process').exec); - - let major = '0'; - let minor = '0'; - let micro = '0'; - - const branch: string = (await exec('git rev-parse --abbrev-ref HEAD')).stdout.toString().trim(); - if (branch.includes('.')) { - const versions = branch.split('.'); - if (versions.length > 0) { - major = versions[0]; - } - - if (versions.length > 1) { - minor = versions[1]; - } - - if (versions.length > 2) { - micro = versions[2]; - } - } - return new SoftwareVersion(major, minor, micro); -} - -async function setVersion(version: SoftwareVersion) { - var fs = require('fs'); - fs.readFile(jsonFilePath, 'utf8', (err: Error, data: string) => { - if (err) { - throw err; - } - const settings: Appsettings = JSON.parse(data); - settings.WebVersion = version; - fs.writeFile(jsonFilePath, JSON.stringify(settings, null, 4), 'utf8', () => {}); + getVersion() + .then(version => { + setVersion(version); + }) + .catch(err => { + throw err; }); } +async function getVersion(): Promise { + const util = require("util"); + const exec = util.promisify(require("child_process").exec); + + let major = "0"; + let minor = "0"; + let micro = "0"; + + const branch: string = (await exec("git rev-parse --abbrev-ref HEAD")).stdout.toString().trim(); + if (branch.includes(".")) { + const versions = branch.split("."); + if (versions.length > 0) { + major = versions[0]; + } + + if (versions.length > 1) { + minor = versions[1]; + } + + if (versions.length > 2) { + micro = versions[2]; + } + } else if (branch.startsWith("#")) { + const fs = require("fs"); + const config: Appsettings = JSON.parse(fs.readFileSync(jsonFilePath, 'utf-8')) + major = config.WebVersion.Major; + minor = config.WebVersion.Minor; + micro = `dev${branch.split("#")[1]}`; + } + return new SoftwareVersion(major, minor, micro); +} + + +async function setVersion(version: SoftwareVersion) { + const fs = require("fs"); + fs.readFile(jsonFilePath, "utf8", (err: Error, data: string) => { + if (err) { + throw err; + } + const settings: Appsettings = JSON.parse(data); + settings.WebVersion = version; + fs.writeFile(jsonFilePath, JSON.stringify(settings, null, 4), "utf8", () => { + }); + }); +} + Main();