From 310b973846f087a6e5648659673dfc486e21d22f Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Fri, 10 Jan 2025 22:11:18 +0100 Subject: [PATCH] Performance: drop "known_themes"-file --- scripts/generateLayerOverview.ts | 10 ---------- scripts/generateLayouts.ts | 15 ++++++--------- scripts/initFiles.sh | 1 - src/Customizations/AllKnownLayouts.ts | 14 +++++++++----- 4 files changed, 15 insertions(+), 25 deletions(-) diff --git a/scripts/generateLayerOverview.ts b/scripts/generateLayerOverview.ts index b8dd21cc7e..7cce54ff5f 100644 --- a/scripts/generateLayerOverview.ts +++ b/scripts/generateLayerOverview.ts @@ -577,15 +577,6 @@ class LayerOverviewUtils extends Script { ) } - if (recompiledThemes.length > 0) { - writeFileSync( - "./src/assets/generated/known_themes.json", - JSON.stringify({ - themes: Array.from(sharedThemes.values()), - }) - ) - } - if (AllSharedLayers.getSharedLayersConfigs().size == 0) { console.error("This was a bootstrapping-run. Run generate layeroverview again!") } @@ -649,7 +640,6 @@ class LayerOverviewUtils extends Script { const sharedLayer = JSON.parse(readFileSync(targetPath, "utf8")) sharedLayers.set(sharedLayer.id, sharedLayer) skippedLayers.push(sharedLayer.id) - ScriptUtils.erasableLog("Loaded " + sharedLayer.id) continue } catch (e) { throw "Could not parse " + targetPath + " : " + e diff --git a/scripts/generateLayouts.ts b/scripts/generateLayouts.ts index aaeb96210b..a8158658e3 100644 --- a/scripts/generateLayouts.ts +++ b/scripts/generateLayouts.ts @@ -2,7 +2,6 @@ import { appendFileSync, existsSync, mkdirSync, readFileSync, writeFile, writeFi import Locale from "../src/UI/i18n/Locale" import Translations from "../src/UI/i18n/Translations" import { Translation } from "../src/UI/i18n/Translation" -import all_known_layouts from "../src/assets/generated/known_themes.json" import { ThemeConfigJson } from "../src/Models/ThemeConfig/Json/ThemeConfigJson" import ThemeConfig from "../src/Models/ThemeConfig/ThemeConfig" import xml2js from "xml2js" @@ -12,7 +11,6 @@ import SpecialVisualizations from "../src/UI/SpecialVisualizations" import Constants from "../src/Models/Constants" import { AvailableRasterLayers, - EditorLayerIndexProperties, RasterLayerPolygon, } from "../src/Models/RasterLayers" import { ImmutableStore } from "../src/Logic/UIEventSource" @@ -122,7 +120,7 @@ class GenerateLayouts extends Script { return path } const svg = await ScriptUtils.ReadSvg(layout.icon) - let width: string = svg.$.width + let width: string = svg["$"].width if (width === undefined) { throw "The logo at " + layout.icon + " does not have a defined width" } @@ -185,8 +183,8 @@ class GenerateLayouts extends Script { "./public/assets/generated/images/theme_" + layout.id + "_white_background.svg" { const svg = await ScriptUtils.ReadSvg(icon) - const width: string = svg.$.width - const height: string = svg.$.height + const width: string = svg["$"].width + const height: string = svg["$"].height const builder = new xml2js.Builder() const withRect = { rect: { $: { width, height, style: "fill:#ffffff;" } }, ...svg } @@ -637,15 +635,14 @@ class GenerateLayouts extends Script { "custom", "theme", ] - // @ts-ignore - const all: ThemeConfigJson[] = all_known_layouts.themes const args = process.argv const theme = args[2] if (theme !== undefined) { console.warn("Only generating layout " + theme) } - for (const i in all) { - const layoutConfigJson: ThemeConfigJson = all[i] + const paths = ScriptUtils.readDirRecSync("./src/assets/generated/themes/",1) + for (const i in paths) { + const layoutConfigJson = JSON.parse(readFileSync(paths[i], "utf8")) if (theme !== undefined && layoutConfigJson.id !== theme) { continue } diff --git a/scripts/initFiles.sh b/scripts/initFiles.sh index 95d0c93178..fde4a51f9c 100755 --- a/scripts/initFiles.sh +++ b/scripts/initFiles.sh @@ -3,7 +3,6 @@ # Creates various empty (stub) version of files mkdir -p ./src/assets/generated/layers -echo '{"themes":[]}' > ./src/assets/generated/known_themes.json echo '{"layers": []}' > ./src/assets/generated/known_layers.json rm -f ./src/assets/generated/layers/*.json rm -f ./src/assets/generated/themes/*.json diff --git a/src/Customizations/AllKnownLayouts.ts b/src/Customizations/AllKnownLayouts.ts index c4004e2dad..9d41f97640 100644 --- a/src/Customizations/AllKnownLayouts.ts +++ b/src/Customizations/AllKnownLayouts.ts @@ -1,9 +1,10 @@ -import known_themes from "../assets/generated/known_themes.json" import ThemeConfig from "../Models/ThemeConfig/ThemeConfig" import favourite from "../assets/generated/layers/favourite.json" import { ThemeConfigJson } from "../Models/ThemeConfig/Json/ThemeConfigJson" import { AllSharedLayers } from "./AllSharedLayers" import Constants from "../Models/Constants" +import ScriptUtils from "../../scripts/ScriptUtils" +import { readFileSync } from "fs" /** * Somewhat of a dictionary, which lazily parses needed themes @@ -13,11 +14,14 @@ export class AllKnownLayoutsLazy { private readonly dict: Map = new Map() constructor(includeFavouriteLayer = true) { - for (const layoutConfigJson of known_themes["themes"]) { + const paths = ScriptUtils.readDirRecSync("./src/assets/generated/themes/",1) + + for (const path of paths) { + const themeConfigJson = JSON.parse(readFileSync(path, "utf8")) for (const layerId of Constants.added_by_default) { if (layerId === "favourite" && favourite.id) { if (includeFavouriteLayer) { - layoutConfigJson.layers.push(favourite) + themeConfigJson.layers.push(favourite) } continue } @@ -26,9 +30,9 @@ export class AllKnownLayoutsLazy { console.error("Could not find builtin layer", layerId) continue } - layoutConfigJson.layers.push(defaultLayer) + themeConfigJson.layers.push(defaultLayer) } - this.raw.set(layoutConfigJson.id, layoutConfigJson) + this.raw.set(themeConfigJson.id, themeConfigJson) } }