chore: automated housekeeping...

This commit is contained in:
Pieter Vander Vennet 2025-08-13 23:06:38 +02:00
parent 9cd7ad597d
commit 69ab755f29
520 changed files with 16616 additions and 13483 deletions

View file

@ -37,9 +37,15 @@ import { Translatable } from "../src/Models/ThemeConfig/Json/Translatable"
import { ValidateThemeAndLayers } from "../src/Models/ThemeConfig/Conversion/ValidateThemeAndLayers"
import { ExtractImages } from "../src/Models/ThemeConfig/Conversion/FixImages"
import { TagRenderingConfigJson } from "../src/Models/ThemeConfig/Json/TagRenderingConfigJson"
import { LayerConfigDependencyGraph, LevelInfo } from "../src/Models/ThemeConfig/LayerConfigDependencyGraph"
import {
LayerConfigDependencyGraph,
LevelInfo,
} from "../src/Models/ThemeConfig/LayerConfigDependencyGraph"
import { Lists } from "../src/Utils/Lists"
import { LayerConfigDependencyGraph, LevelInfo } from "../src/Models/ThemeConfig/LayerConfigDependencyGraph"
import {
LayerConfigDependencyGraph,
LevelInfo,
} from "../src/Models/ThemeConfig/LayerConfigDependencyGraph"
import { AddContextToTranslations } from "../src/Models/ThemeConfig/Conversion/AddContextToTranslations"
// This scripts scans 'src/assets/layers/*.json' for layer definition files and 'src/assets/themes/*.json' for theme definition files.
@ -126,18 +132,20 @@ class AddIconSummary extends DesugaringStep<{ raw: LayerConfigJson; parsed: Laye
pr.location.has("point")
)
const defaultTags = layerConfig.baseTags
fixed["_layerIcon"] = Lists.noNull((pointRendering?.marker ?? []).map((i) => {
const icon = i.icon?.GetRenderValue(defaultTags)?.txt
if (!icon) {
return undefined
}
const result = { icon }
const c = i.color?.GetRenderValue(defaultTags)?.txt
if (c) {
result["color"] = c
}
return result
}))
fixed["_layerIcon"] = Lists.noNull(
(pointRendering?.marker ?? []).map((i) => {
const icon = i.icon?.GetRenderValue(defaultTags)?.txt
if (!icon) {
return undefined
}
const result = { icon }
const c = i.color?.GetRenderValue(defaultTags)?.txt
if (c) {
result["color"] = c
}
return result
})
)
return { raw: fixed, parsed: layerConfig }
}
}
@ -224,10 +232,7 @@ class LayerBuilder extends Conversion<object, Map<string, LayerConfigJson>> {
const prepped = this.prepareLayer.convert(config, context)
const withContext = new AddContextToTranslations<LayerConfigJson>("layers:").convertStrict(
prepped,
ConversionContext.construct(
[prepped.id],
["AddContextToTranslations"]
)
ConversionContext.construct([prepped.id], ["AddContextToTranslations"])
)
this._loadedIds.add(id)
this._desugaringState.sharedLayers.set(id, withContext)
@ -641,10 +646,16 @@ class LayerOverviewUtils extends Script {
writeFileSync(
"./src/assets/generated/theme_overview.json",
JSON.stringify({
"#":"Generated by generateLayerOverview",
"#version": new Date().toISOString(),
layers: layerKeywords, themes: sorted }, null, " "),
JSON.stringify(
{
"#": "Generated by generateLayerOverview",
"#version": new Date().toISOString(),
layers: layerKeywords,
themes: sorted,
},
null,
" "
),
{ encoding: "utf8" }
)
}
@ -696,7 +707,10 @@ class LayerOverviewUtils extends Script {
const path = "assets/layers/questions/questions.json"
const sharedQuestionsRaw = this.parseLayer(doesImageExist, prepareLayer, path).raw
const sharedQuestions = new AddContextToTranslations("").convertStrict(sharedQuestionsRaw, ConversionContext.construct(["layers:questions"], []))
const sharedQuestions = new AddContextToTranslations("").convertStrict(
sharedQuestionsRaw,
ConversionContext.construct(["layers:questions"], [])
)
const dict = new Map<string, QuestionableTagRenderingConfigJson>()
for (const tr of sharedQuestions.tagRenderings) {
@ -779,7 +793,7 @@ class LayerOverviewUtils extends Script {
)
const forceReload = args.some((a) => a == "--force") || labelBlacklist.size > 0
const printAssets = args.some(a => a === "--print-needed-assets")
const printAssets = args.some((a) => a === "--print-needed-assets")
console.log("Arguments are:", { labelBlacklist, themeWhitelist, forceReload })
const doesImageExist = DoesImageExist.constructWithLicenses(existsSync)
const sharedLayers = this.buildLayerIndex(doesImageExist, labelBlacklist)
@ -868,8 +882,10 @@ class LayerOverviewUtils extends Script {
(l) => Constants.added_by_default.indexOf(l["id"]) < 0
)
}
if(printAssets){
const images = Lists.dedup(Array.from(sharedThemes.values()).flatMap(th => th._usedImages ?? []))
if (printAssets) {
const images = Lists.dedup(
Array.from(sharedThemes.values()).flatMap((th) => th._usedImages ?? [])
)
writeFileSync("needed_assets.csv", images.join("\n"))
console.log("Written needed_assets.csv")
}
@ -1283,9 +1299,11 @@ class LayerOverviewUtils extends Script {
}
}
const usedImages = Lists.dedup(new ExtractImages(true, knownTagRenderings)
.convertStrict(themeFile)
.map((x) => x.path))
const usedImages = Lists.dedup(
new ExtractImages(true, knownTagRenderings)
.convertStrict(themeFile)
.map((x) => x.path)
)
usedImages.sort()
themeFile["_usedImages"] = usedImages
@ -1307,7 +1325,8 @@ class LayerOverviewUtils extends Script {
...t,
hideFromOverview: t.hideFromOverview ?? false,
shortDescription:
t.shortDescription ?? new Translation(t.description).FirstSentence(true),
t.shortDescription ??
new Translation(t.description).FirstSentence(true),
mustHaveLanguage: t.mustHaveLanguage?.length > 0,
}
}),