diff --git a/scripts/inspectStudioLayers.ts b/scripts/inspectStudioLayers.ts new file mode 100644 index 0000000000..a42aacaff0 --- /dev/null +++ b/scripts/inspectStudioLayers.ts @@ -0,0 +1,78 @@ +import Script from "./Script" +import ScriptUtils from "./ScriptUtils" +import { LayerConfigJson } from "../src/Models/ThemeConfig/Json/LayerConfigJson" +import { readFileSync, statSync } from "fs" +import LayerConfig from "../src/Models/ThemeConfig/LayerConfig" +import { PrepareLayer } from "../src/Models/ThemeConfig/Conversion/PrepareLayer" +import { TagUtils } from "../src/Logic/Tags/TagUtils" + +class CompareLayer { + private _knownLayers: Map + + constructor(knownLayers: Map) { + this._knownLayers = knownLayers + } + + public compare(layer: LayerConfigJson, path: string) { + const candidate = this._knownLayers.get(layer.id) + if (!layer.source?.["osmTags"]) { + return + } + layer.tagRenderings = layer.tagRenderings?.filter(tr => tr !== "images") ?? [] + if(layer.tagRenderings.length === 0){ + return + } + if (!candidate) { + console.log("## " + layer.id + " (unique)") + const info = statSync(path) + console.log(`\n[${layer.id}](${path}) Last edited ${info.mtime.toISOString()}\n\n`) + const source = TagUtils.Tag(layer.source?.["osmTags"]) + console.log(source.asHumanString(true, false)) + if (layer.tagRenderings.length === 0) { + console.log("MINIMAL") + } + console.log("> "+layer.description?.["en"]) + } + } + +} + +class InspectStudioLayers extends Script { + + constructor() { + super("Iterates over all the studio layers and tries to match it with an already existing layer and list differences") + } + + + async main(args: string[]): Promise { + const path = args[0] ?? "/home/pietervdvn/data/mapcomplete-custom-themes" + const files = ScriptUtils.readDirRecSync(path) + .filter(p => p.endsWith(".json")) + .filter(p => p.indexOf("/themes/") < 0) + .filter(p => !p.endsWith("license_info.json") && p.indexOf(".stversions") < 0) + const officialFiles = new Map() + const unofficial: { layer: LayerConfigJson, path: string }[] = [] + for (const file of files) { + const rest = file.substring(path.length + 1) + console.log("Loading ", rest) + try { + const config = JSON.parse(readFileSync(file, "utf-8")) + if (rest.indexOf("layers") < 3) { + officialFiles.set(config.id, config) + } else { + unofficial.push({ layer: config, path: file }) + } + } catch (e) { + console.error("COULD NOT READ/PARSE", file, "ignoring it") + } + } + console.log("Loaded", unofficial.length, "custom layers and ", officialFiles.size, "official layers") + const comp = new CompareLayer(officialFiles) + for (const layerConfigJson of unofficial) { + comp.compare(layerConfigJson.layer, layerConfigJson.path) + } + } + +} + +new InspectStudioLayers().run()