Performance: drop "known_themes"-file

This commit is contained in:
Pieter Vander Vennet 2025-01-10 22:11:18 +01:00
parent b913ea867f
commit 310b973846
4 changed files with 15 additions and 25 deletions

View file

@ -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) { if (AllSharedLayers.getSharedLayersConfigs().size == 0) {
console.error("This was a bootstrapping-run. Run generate layeroverview again!") 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")) const sharedLayer = JSON.parse(readFileSync(targetPath, "utf8"))
sharedLayers.set(sharedLayer.id, sharedLayer) sharedLayers.set(sharedLayer.id, sharedLayer)
skippedLayers.push(sharedLayer.id) skippedLayers.push(sharedLayer.id)
ScriptUtils.erasableLog("Loaded " + sharedLayer.id)
continue continue
} catch (e) { } catch (e) {
throw "Could not parse " + targetPath + " : " + e throw "Could not parse " + targetPath + " : " + e

View file

@ -2,7 +2,6 @@ import { appendFileSync, existsSync, mkdirSync, readFileSync, writeFile, writeFi
import Locale from "../src/UI/i18n/Locale" import Locale from "../src/UI/i18n/Locale"
import Translations from "../src/UI/i18n/Translations" import Translations from "../src/UI/i18n/Translations"
import { Translation } from "../src/UI/i18n/Translation" 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 { ThemeConfigJson } from "../src/Models/ThemeConfig/Json/ThemeConfigJson"
import ThemeConfig from "../src/Models/ThemeConfig/ThemeConfig" import ThemeConfig from "../src/Models/ThemeConfig/ThemeConfig"
import xml2js from "xml2js" import xml2js from "xml2js"
@ -12,7 +11,6 @@ import SpecialVisualizations from "../src/UI/SpecialVisualizations"
import Constants from "../src/Models/Constants" import Constants from "../src/Models/Constants"
import { import {
AvailableRasterLayers, AvailableRasterLayers,
EditorLayerIndexProperties,
RasterLayerPolygon, RasterLayerPolygon,
} from "../src/Models/RasterLayers" } from "../src/Models/RasterLayers"
import { ImmutableStore } from "../src/Logic/UIEventSource" import { ImmutableStore } from "../src/Logic/UIEventSource"
@ -122,7 +120,7 @@ class GenerateLayouts extends Script {
return path return path
} }
const svg = await ScriptUtils.ReadSvg(layout.icon) const svg = await ScriptUtils.ReadSvg(layout.icon)
let width: string = svg.$.width let width: string = svg["$"].width
if (width === undefined) { if (width === undefined) {
throw "The logo at " + layout.icon + " does not have a defined width" 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" "./public/assets/generated/images/theme_" + layout.id + "_white_background.svg"
{ {
const svg = await ScriptUtils.ReadSvg(icon) const svg = await ScriptUtils.ReadSvg(icon)
const width: string = svg.$.width const width: string = svg["$"].width
const height: string = svg.$.height const height: string = svg["$"].height
const builder = new xml2js.Builder() const builder = new xml2js.Builder()
const withRect = { rect: { $: { width, height, style: "fill:#ffffff;" } }, ...svg } const withRect = { rect: { $: { width, height, style: "fill:#ffffff;" } }, ...svg }
@ -637,15 +635,14 @@ class GenerateLayouts extends Script {
"custom", "custom",
"theme", "theme",
] ]
// @ts-ignore
const all: ThemeConfigJson[] = all_known_layouts.themes
const args = process.argv const args = process.argv
const theme = args[2] const theme = args[2]
if (theme !== undefined) { if (theme !== undefined) {
console.warn("Only generating layout " + theme) console.warn("Only generating layout " + theme)
} }
for (const i in all) { const paths = ScriptUtils.readDirRecSync("./src/assets/generated/themes/",1)
const layoutConfigJson: ThemeConfigJson = all[i] for (const i in paths) {
const layoutConfigJson = <ThemeConfigJson> JSON.parse(readFileSync(paths[i], "utf8"))
if (theme !== undefined && layoutConfigJson.id !== theme) { if (theme !== undefined && layoutConfigJson.id !== theme) {
continue continue
} }

View file

@ -3,7 +3,6 @@
# Creates various empty (stub) version of files # Creates various empty (stub) version of files
mkdir -p ./src/assets/generated/layers mkdir -p ./src/assets/generated/layers
echo '{"themes":[]}' > ./src/assets/generated/known_themes.json
echo '{"layers": []}' > ./src/assets/generated/known_layers.json echo '{"layers": []}' > ./src/assets/generated/known_layers.json
rm -f ./src/assets/generated/layers/*.json rm -f ./src/assets/generated/layers/*.json
rm -f ./src/assets/generated/themes/*.json rm -f ./src/assets/generated/themes/*.json

View file

@ -1,9 +1,10 @@
import known_themes from "../assets/generated/known_themes.json"
import ThemeConfig from "../Models/ThemeConfig/ThemeConfig" import ThemeConfig from "../Models/ThemeConfig/ThemeConfig"
import favourite from "../assets/generated/layers/favourite.json" import favourite from "../assets/generated/layers/favourite.json"
import { ThemeConfigJson } from "../Models/ThemeConfig/Json/ThemeConfigJson" import { ThemeConfigJson } from "../Models/ThemeConfig/Json/ThemeConfigJson"
import { AllSharedLayers } from "./AllSharedLayers" import { AllSharedLayers } from "./AllSharedLayers"
import Constants from "../Models/Constants" import Constants from "../Models/Constants"
import ScriptUtils from "../../scripts/ScriptUtils"
import { readFileSync } from "fs"
/** /**
* Somewhat of a dictionary, which lazily parses needed themes * Somewhat of a dictionary, which lazily parses needed themes
@ -13,11 +14,14 @@ export class AllKnownLayoutsLazy {
private readonly dict: Map<string, ThemeConfig> = new Map() private readonly dict: Map<string, ThemeConfig> = new Map()
constructor(includeFavouriteLayer = true) { 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 = <ThemeConfigJson> JSON.parse(readFileSync(path, "utf8"))
for (const layerId of Constants.added_by_default) { for (const layerId of Constants.added_by_default) {
if (layerId === "favourite" && favourite.id) { if (layerId === "favourite" && favourite.id) {
if (includeFavouriteLayer) { if (includeFavouriteLayer) {
layoutConfigJson.layers.push(favourite) themeConfigJson.layers.push(favourite)
} }
continue continue
} }
@ -26,9 +30,9 @@ export class AllKnownLayoutsLazy {
console.error("Could not find builtin layer", layerId) console.error("Could not find builtin layer", layerId)
continue continue
} }
layoutConfigJson.layers.push(defaultLayer) themeConfigJson.layers.push(defaultLayer)
} }
this.raw.set(layoutConfigJson.id, layoutConfigJson) this.raw.set(themeConfigJson.id, themeConfigJson)
} }
} }