forked from MapComplete/MapComplete
Improve validation of tagRenderings
This commit is contained in:
parent
ee9646a176
commit
7a68e83afa
1 changed files with 39 additions and 29 deletions
|
@ -4,7 +4,12 @@ import * as licenses from "../assets/generated/license_info.json"
|
||||||
import {LayoutConfigJson} from "../Models/ThemeConfig/Json/LayoutConfigJson";
|
import {LayoutConfigJson} from "../Models/ThemeConfig/Json/LayoutConfigJson";
|
||||||
import {LayerConfigJson} from "../Models/ThemeConfig/Json/LayerConfigJson";
|
import {LayerConfigJson} from "../Models/ThemeConfig/Json/LayerConfigJson";
|
||||||
import Constants from "../Models/Constants";
|
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 {Translation} from "../UI/i18n/Translation";
|
||||||
import {TagRenderingConfigJson} from "../Models/ThemeConfig/Json/TagRenderingConfigJson";
|
import {TagRenderingConfigJson} from "../Models/ThemeConfig/Json/TagRenderingConfigJson";
|
||||||
import * as questions from "../assets/tagRenderings/questions.json";
|
import * as questions from "../assets/tagRenderings/questions.json";
|
||||||
|
@ -77,16 +82,19 @@ class LayerOverviewUtils {
|
||||||
writeFileSync(`./assets/generated/layers/${layer.id}.json`, JSON.stringify(layer, null, " "), "UTF8");
|
writeFileSync(`./assets/generated/layers/${layer.id}.json`, JSON.stringify(layer, null, " "), "UTF8");
|
||||||
}
|
}
|
||||||
|
|
||||||
getSharedTagRenderings(): Map<string, TagRenderingConfigJson> {
|
getSharedTagRenderings(knownImagePaths: Set<string>): Map<string, TagRenderingConfigJson> {
|
||||||
const dict = new Map<string, TagRenderingConfigJson>();
|
const dict = new Map<string, TagRenderingConfigJson>();
|
||||||
|
|
||||||
|
const validator = new ValidateTagRenderings(undefined, knownImagePaths);
|
||||||
for (const key in questions["default"]) {
|
for (const key in questions["default"]) {
|
||||||
if (key === "id") {
|
if (key === "id") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
questions[key].id = key;
|
questions[key].id = key;
|
||||||
questions[key]["source"] = "shared-questions"
|
questions[key]["source"] = "shared-questions"
|
||||||
dict.set(key, <TagRenderingConfigJson>questions[key])
|
const config = <TagRenderingConfigJson>questions[key]
|
||||||
|
validator.convertStrict(config, "generate-layer-overview:tagRenderings/questions.json:"+key)
|
||||||
|
dict.set(key, config)
|
||||||
}
|
}
|
||||||
for (const key in icons["default"]) {
|
for (const key in icons["default"]) {
|
||||||
if (key === "id") {
|
if (key === "id") {
|
||||||
|
@ -96,7 +104,9 @@ class LayerOverviewUtils {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
icons[key].id = key;
|
icons[key].id = key;
|
||||||
dict.set(key, <TagRenderingConfigJson>icons[key])
|
const config = <TagRenderingConfigJson>icons[key]
|
||||||
|
validator.convertStrict(config, "generate-layer-overview:tagRenderings/icons.json:"+key)
|
||||||
|
dict.set(key,config)
|
||||||
}
|
}
|
||||||
|
|
||||||
dict.forEach((value, key) => {
|
dict.forEach((value, key) => {
|
||||||
|
@ -183,7 +193,7 @@ class LayerOverviewUtils {
|
||||||
// At the same time, an index of available layers is built.
|
// At the same time, an index of available layers is built.
|
||||||
console.log(" ---------- VALIDATING BUILTIN LAYERS ---------")
|
console.log(" ---------- VALIDATING BUILTIN LAYERS ---------")
|
||||||
|
|
||||||
const sharedTagRenderings = this.getSharedTagRenderings();
|
const sharedTagRenderings = this.getSharedTagRenderings(knownImagePaths);
|
||||||
const layerFiles = ScriptUtils.getLayerFiles();
|
const layerFiles = ScriptUtils.getLayerFiles();
|
||||||
const sharedLayers = new Map<string, LayerConfigJson>()
|
const sharedLayers = new Map<string, LayerConfigJson>()
|
||||||
const state: DesugaringContext = {
|
const state: DesugaringContext = {
|
||||||
|
@ -194,7 +204,7 @@ class LayerOverviewUtils {
|
||||||
for (const sharedLayerJson of layerFiles) {
|
for (const sharedLayerJson of layerFiles) {
|
||||||
const context = "While building builtin layer " + sharedLayerJson.path
|
const context = "While building builtin layer " + sharedLayerJson.path
|
||||||
const fixed = prepLayer.convertStrict(sharedLayerJson.parsed, context)
|
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)
|
validator.convertStrict(fixed, context)
|
||||||
|
|
||||||
if (sharedLayers.has(fixed.id)) {
|
if (sharedLayers.has(fixed.id)) {
|
||||||
|
@ -243,7 +253,7 @@ class LayerOverviewUtils {
|
||||||
|
|
||||||
const convertState: DesugaringContext = {
|
const convertState: DesugaringContext = {
|
||||||
sharedLayers,
|
sharedLayers,
|
||||||
tagRenderings: this.getSharedTagRenderings(),
|
tagRenderings: this.getSharedTagRenderings(knownImagePaths),
|
||||||
publicLayers
|
publicLayers
|
||||||
}
|
}
|
||||||
for (const themeInfo of themeFiles) {
|
for (const themeInfo of themeFiles) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue