From 03d801733b4ffe4b74c56a4bc4e3417ccac4a519 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Sat, 4 Sep 2021 18:59:51 +0200 Subject: [PATCH] Porting fixes from stale branch --- assets/themes/grb.json | 2 +- scripts/ScriptUtils.ts | 20 +++++++++++--------- scripts/generateLayerOverview.ts | 19 +++++++++++-------- scripts/generateTranslations.ts | 2 +- 4 files changed, 24 insertions(+), 19 deletions(-) diff --git a/assets/themes/grb.json b/assets/themes/grb.json index 536b694e7..37efacae0 100644 --- a/assets/themes/grb.json +++ b/assets/themes/grb.json @@ -101,7 +101,7 @@ { "if": { "and": [ - "addr:housenumber:=", + "addr:housenumber=", "not:addr:housenumber=yes", "fixme=" ] diff --git a/scripts/ScriptUtils.ts b/scripts/ScriptUtils.ts index b5b7a6903..f0ba016bb 100644 --- a/scripts/ScriptUtils.ts +++ b/scripts/ScriptUtils.ts @@ -1,5 +1,6 @@ import {lstatSync, readdirSync, readFileSync} from "fs"; import {Utils} from "../Utils"; + Utils.runningFromConsole = true import * as https from "https"; import * as fs from "fs"; @@ -56,12 +57,12 @@ export default class ScriptUtils { const headers = options?.headers ?? {} headers.accept = "application/json" - + const urlObj = new URL(url) https.get({ host: urlObj.host, path: urlObj.pathname + urlObj.search, - + port: urlObj.port, headers: headers }, (res) => { @@ -88,9 +89,9 @@ export default class ScriptUtils { }) } - + public static erasableLog(...text) { - process.stdout.write("\r "+text.join(" ")+" \r") + process.stdout.write("\r " + text.join(" ") + " \r") } public static sleep(ms) { @@ -107,14 +108,15 @@ export default class ScriptUtils { public static getLayerFiles(): { parsed: LayerConfigJson, path: string }[] { return ScriptUtils.readDirRecSync("./assets/layers") .filter(path => path.indexOf(".json") > 0) + .filter(path => path.indexOf(".proto.json") < 0) .filter(path => path.indexOf("license_info.json") < 0) .map(path => { try { const contents = readFileSync(path, "UTF8") - if(contents === ""){ - throw "The file "+path+" is empty, did you properly save?" + if (contents === "") { + throw "The file " + path + " is empty, did you properly save?" } - + const parsed = JSON.parse(contents); return {parsed: parsed, path: path} } catch (e) { @@ -130,8 +132,8 @@ export default class ScriptUtils { .map(path => { try { const contents = readFileSync(path, "UTF8"); - if(contents === ""){ - throw "The file "+path+" is empty, did you properly save?" + if (contents === "") { + throw "The file " + path + " is empty, did you properly save?" } const parsed = JSON.parse(contents); return {parsed: parsed, path: path} diff --git a/scripts/generateLayerOverview.ts b/scripts/generateLayerOverview.ts index 06e6b3e96..490fef339 100644 --- a/scripts/generateLayerOverview.ts +++ b/scripts/generateLayerOverview.ts @@ -25,6 +25,9 @@ class LayerOverviewUtils { const themeFiles: LayoutConfigJson[] = ScriptUtils.getThemeFiles().map(x => x.parsed); console.log("Discovered", layerFiles.length, "layers and", themeFiles.length, "themes\n") + if (layerFiles.length + themeFiles.length === 0) { + throw "Panic: no themes and layers loaded!" + } return { layers: layerFiles, themes: themeFiles @@ -56,10 +59,10 @@ class LayerOverviewUtils { if (path != undefined && path.indexOf(expected) < 0) { errorCount.push("Layer is in an incorrect place. The path is " + path + ", but expected " + expected) } - if(layerJson["hideUnderlayingFeaturesMinPercentage"] !== undefined){ - errorCount.push("Layer "+layer.id+" contains an old 'hideUnderlayingFeaturesMinPercentage'") - } - + if (layerJson["hideUnderlayingFeaturesMinPercentage"] !== undefined) { + errorCount.push("Layer " + layer.id + " contains an old 'hideUnderlayingFeaturesMinPercentage'") + } + for (const image of images) { if (image.indexOf("{") >= 0) { @@ -146,11 +149,11 @@ class LayerOverviewUtils { themeErrorCount.push("Theme ids should be in lowercase, but it is " + theme.id) } let filename = themePath.substring(themePath.lastIndexOf("/") + 1, themePath.length - 5) - if(theme.id !== filename){ - themeErrorCount.push("Theme ids should be the same as the name.json, but we got id: " + theme.id + " and filename "+filename+" ("+themePath+")") + if (theme.id !== filename) { + themeErrorCount.push("Theme ids should be the same as the name.json, but we got id: " + theme.id + " and filename " + filename + " (" + themePath + ")") } - - + + } catch (e) { themeErrorCount.push("Could not parse theme " + themeFile["id"] + "due to", e) } diff --git a/scripts/generateTranslations.ts b/scripts/generateTranslations.ts index b66c97cde..8b689ef54 100644 --- a/scripts/generateTranslations.ts +++ b/scripts/generateTranslations.ts @@ -235,7 +235,7 @@ function MergeTranslation(source: any, target: any, language: string, context: s } if (typeof targetV === "string") { - throw `At context ${context}: Could not add a translation. The target object has a string at the given path, whereas the translation contains an object.\n String at target: ${targetV}\n Object at translation source: ${JSON.stringify(sourceV)}` + throw `At context ${context}: Could not add a translation in language ${language}. The target object has a string at the given path, whereas the translation contains an object.\n String at target: ${targetV}\n Object at translation source: ${JSON.stringify(sourceV)}` } targetV[language] = sourceV;