diff --git a/scripts/generateLayerOverview.ts b/scripts/generateLayerOverview.ts index 70c70739bf..55bd7f4d36 100644 --- a/scripts/generateLayerOverview.ts +++ b/scripts/generateLayerOverview.ts @@ -4,7 +4,12 @@ import * as licenses from "../assets/generated/license_info.json" import {LayoutConfigJson} from "../Models/ThemeConfig/Json/LayoutConfigJson"; import {LayerConfigJson} from "../Models/ThemeConfig/Json/LayerConfigJson"; import Constants from "../Models/Constants"; -import {PrevalidateTheme, ValidateLayer, ValidateThemeAndLayers} from "../Models/ThemeConfig/Conversion/Validation"; +import { + PrevalidateTheme, + ValidateLayer, + ValidateTagRenderings, + ValidateThemeAndLayers +} from "../Models/ThemeConfig/Conversion/Validation"; import {Translation} from "../UI/i18n/Translation"; import {TagRenderingConfigJson} from "../Models/ThemeConfig/Json/TagRenderingConfigJson"; import * as questions from "../assets/tagRenderings/questions.json"; @@ -20,18 +25,18 @@ import {Utils} from "../Utils"; class LayerOverviewUtils { - writeSmallOverview(themes: { id: string, title: any, shortDescription: any, icon: string, hideFromOverview: boolean, mustHaveLanguage: boolean, layers: (LayerConfigJson | string | {builtin})[] }[]) { + writeSmallOverview(themes: { id: string, title: any, shortDescription: any, icon: string, hideFromOverview: boolean, mustHaveLanguage: boolean, layers: (LayerConfigJson | string | { builtin })[] }[]) { const perId = new Map(); for (const theme of themes) { - - const keywords : {}[] = [] + + const keywords: {}[] = [] for (const layer of (theme.layers ?? [])) { - const l = layer; + const l = layer; keywords.push({"*": l.id}) keywords.push(l.title) keywords.push(l.description) } - + const data = { id: theme.id, title: theme.title, @@ -77,16 +82,19 @@ class LayerOverviewUtils { writeFileSync(`./assets/generated/layers/${layer.id}.json`, JSON.stringify(layer, null, " "), "UTF8"); } - getSharedTagRenderings(): Map { + getSharedTagRenderings(knownImagePaths: Set): Map { const dict = new Map(); - + + const validator = new ValidateTagRenderings(undefined, knownImagePaths); for (const key in questions["default"]) { if (key === "id") { continue } questions[key].id = key; questions[key]["source"] = "shared-questions" - dict.set(key, questions[key]) + const config = questions[key] + validator.convertStrict(config, "generate-layer-overview:tagRenderings/questions.json:"+key) + dict.set(key, config) } for (const key in icons["default"]) { if (key === "id") { @@ -96,7 +104,9 @@ class LayerOverviewUtils { continue } icons[key].id = key; - dict.set(key, icons[key]) + const config = icons[key] + validator.convertStrict(config, "generate-layer-overview:tagRenderings/icons.json:"+key) + dict.set(key,config) } dict.forEach((value, key) => { @@ -114,9 +124,9 @@ class LayerOverviewUtils { .filter(path => path.endsWith(".svg")) .filter(path => !path.startsWith("./assets/generated")) let errCount = 0; - const exempt = ["assets/SocialImageTemplate.svg","assets/SocialImageTemplateWide.svg","assets/SocialImageBanner.svg", "assets/svg/osm-logo.svg"]; + const exempt = ["assets/SocialImageTemplate.svg", "assets/SocialImageTemplateWide.svg", "assets/SocialImageBanner.svg", "assets/svg/osm-logo.svg"]; for (const path of allSvgs) { - if(exempt.some(p => "./"+p === path)) { + if (exempt.some(p => "./" + p === path)) { continue } @@ -128,7 +138,7 @@ class LayerOverviewUtils { throw "A core SVG is actually a PNG. Don't do this!" } } - if(contents.indexOf("0){ + if (contents.indexOf(" 0) { console.warn("The SVG at " + path + " contains a `text`-tag. This is highly discouraged. Every machine viewing your theme has their own font libary, and the font you choose might not be present, resulting in a different font being rendered. Solution: open your .svg in inkscape (or another program), select the text and convert it to a path") errCount++; @@ -183,7 +193,7 @@ class LayerOverviewUtils { // At the same time, an index of available layers is built. console.log(" ---------- VALIDATING BUILTIN LAYERS ---------") - const sharedTagRenderings = this.getSharedTagRenderings(); + const sharedTagRenderings = this.getSharedTagRenderings(knownImagePaths); const layerFiles = ScriptUtils.getLayerFiles(); const sharedLayers = new Map() const state: DesugaringContext = { @@ -194,7 +204,7 @@ class LayerOverviewUtils { for (const sharedLayerJson of layerFiles) { const context = "While building builtin layer " + sharedLayerJson.path const fixed = prepLayer.convertStrict(sharedLayerJson.parsed, context) - const validator = new ValidateLayer(sharedLayerJson.path, true); + const validator = new ValidateLayer(sharedLayerJson.path, true, knownImagePaths); validator.convertStrict(fixed, context) if (sharedLayers.has(fixed.id)) { @@ -208,25 +218,25 @@ class LayerOverviewUtils { } return sharedLayers; } - - private static publicLayerIdsFrom(themefiles: LayoutConfigJson[]): Set{ + + private static publicLayerIdsFrom(themefiles: LayoutConfigJson[]): Set { const publicLayers = [].concat(...themefiles .filter(th => !th.hideFromOverview) .map(th => th.layers)) const publicLayerIds = new Set() for (const publicLayer of publicLayers) { - if(typeof publicLayer === "string"){ + if (typeof publicLayer === "string") { publicLayerIds.add(publicLayer) continue } - if(publicLayer["builtin"] !== undefined){ + if (publicLayer["builtin"] !== undefined) { const bi = publicLayer["builtin"] - if(typeof bi === "string"){ + if (typeof bi === "string") { publicLayerIds.add(bi) continue } - bi.forEach(id=>publicLayerIds.add(id)) + bi.forEach(id => publicLayerIds.add(id)) continue } publicLayerIds.add(publicLayer.id) @@ -243,7 +253,7 @@ class LayerOverviewUtils { const convertState: DesugaringContext = { sharedLayers, - tagRenderings: this.getSharedTagRenderings(), + tagRenderings: this.getSharedTagRenderings(knownImagePaths), publicLayers } for (const themeInfo of themeFiles) { @@ -251,20 +261,20 @@ class LayerOverviewUtils { const themePath = themeInfo.path new PrevalidateTheme().convertStrict(themeFile, themePath) - try{ - + try { + themeFile = new PrepareTheme(convertState).convertStrict(themeFile, themePath) - - if(knownImagePaths === undefined){ + + if (knownImagePaths === undefined) { throw "Could not load known images/licenses" } new ValidateThemeAndLayers(knownImagePaths, themePath, true, convertState.tagRenderings) .convertStrict(themeFile, themePath) - + this.writeTheme(themeFile) fixed.set(themeFile.id, themeFile) - }catch(e){ - console.error("ERROR: could not prepare theme "+themePath+" due to "+e) + } catch (e) { + console.error("ERROR: could not prepare theme " + themePath + " due to " + e) throw e; } }