chore: automated housekeeping...

This commit is contained in:
Pieter Vander Vennet 2025-07-10 18:26:31 +02:00
parent a190597905
commit 087e639020
382 changed files with 29496 additions and 2675 deletions

View file

@ -47,7 +47,7 @@ export default class AddPrefixToTagRenderingConfig extends DesugaringStep<Questi
result += leftover
}
}
if(txt !== result){
if (txt !== result) {
console.log(">>> Rewritten", txt, "into", result)
}
return result

View file

@ -190,7 +190,7 @@ export class On<S extends string, P, T extends Record<S, P>> extends DesugaringS
json = { ...json }
const step = this.step(json)
const converted = step.convert(value, context.enter(key).inOperation("on[" + key + "]"))
json[key] = <T[S]> converted
json[key] = <T[S]>converted
return json
}
}

View file

@ -33,8 +33,11 @@ export class PruneFilters extends DesugaringStep<LayerConfigJson> {
): FilterConfigJson {
if (filter.options.length === 1) {
const option = filter.options[0]
if(!option.osmTags){
context.err("Found a filter without osmTags. Did you forget to add them? The filter is:", JSON.stringify(option))
if (!option.osmTags) {
context.err(
"Found a filter without osmTags. Did you forget to add them? The filter is:",
JSON.stringify(option)
)
}
const tags = TagUtils.Tag(option.osmTags)
const optimized = TagUtils.removeKnownParts(tags, sourceTags, true)

View file

@ -10,7 +10,7 @@ import { ConversionContext } from "./ConversionContext"
export class ExtractImages extends Conversion<
ThemeConfigJson,
{ path: string; context: string; location: (string|number)[] }[]
{ path: string; context: string; location: (string | number)[] }[]
> {
private static readonly layoutMetaPaths = metapaths.filter((mp) => {
const typeHint = mp.hints.typehint
@ -111,8 +111,9 @@ export class ExtractImages extends Conversion<
convert(
json: ThemeConfigJson,
context: ConversionContext
): { path: string; context: string, location: (string | number)[] }[] {
const allFoundImages: { path: string; context: string, location: (string | number)[] }[] = []
): { path: string; context: string; location: (string | number)[] }[] {
const allFoundImages: { path: string; context: string; location: (string | number)[] }[] =
[]
for (const metapath of ExtractImages.layoutMetaPaths) {
const mightBeTr = ExtractImages.mightBeTagRendering(<any>metapath)
@ -143,7 +144,11 @@ export class ExtractImages extends Conversion<
continue
}
allFoundImages.push({ path: foundImage, context: context + "." + path, location: path })
allFoundImages.push({
path: foundImage,
context: context + "." + path,
location: path,
})
} else {
// This is a tagRendering.
// Either every rendered value might be an icon
@ -177,7 +182,7 @@ export class ExtractImages extends Conversion<
allFoundImages.push({
path: img.leaf,
context: context + "." + path,
location: img.path
location: img.path,
})
}
}
@ -192,7 +197,7 @@ export class ExtractImages extends Conversion<
.map((path) => ({
path,
context: context + "." + path,
location:img.path
location: img.path,
}))
)
}
@ -213,13 +218,13 @@ export class ExtractImages extends Conversion<
allFoundImages.push({
context: context.path.join(".") + "." + foundElement.path.join("."),
path: foundElement.leaf,
location: foundElement.path
location: foundElement.path,
})
}
}
}
const cleanedImages: { path: string; context: string, location: (string | number)[] }[] = []
const cleanedImages: { path: string; context: string; location: (string | number)[] }[] = []
for (const foundImage of allFoundImages) {
if (foundImage.path.startsWith("<") && foundImage.path.endsWith(">")) {
@ -228,8 +233,11 @@ export class ExtractImages extends Conversion<
const images = Array.from(doc.getElementsByTagName("img"))
const paths = images.map((i) => i.getAttribute("src"))
cleanedImages.push(
...paths.map((path) => ({ path, context: foundImage.context + " (in html)",
location: foundImage.location }))
...paths.map((path) => ({
path,
context: foundImage.context + " (in html)",
location: foundImage.location,
}))
)
continue
}
@ -246,7 +254,11 @@ export class ExtractImages extends Conversion<
)
)
for (const path of allPaths) {
cleanedImages.push({ path, context: foundImage.context , location:foundImage.location})
cleanedImages.push({
path,
context: foundImage.context,
location: foundImage.location,
})
}
}
@ -260,7 +272,7 @@ export class FixImages extends DesugaringStep<ThemeConfigJson> {
constructor(knownImages: Set<string>) {
super(
"fixImages",
"Walks over the entire theme and replaces images to the relative URL. Only works if the ID of the theme is an URL",
"Walks over the entire theme and replaces images to the relative URL. Only works if the ID of the theme is an URL"
)
this._knownImages = knownImages
}

View file

@ -427,7 +427,7 @@ export class AddEditingElements extends DesugaringStep<LayerConfigJson> {
})
}
const spacerIndex = json.tagRenderings.findIndex(item => item?.["id"] === "spacer")
const spacerIndex = json.tagRenderings.findIndex((item) => item?.["id"] === "spacer")
if (spacerIndex >= 0) {
json.tagRenderings.splice(spacerIndex, 1)
}
@ -1087,13 +1087,12 @@ class DeriveSource extends DesugaringStep<LayerConfigJson> {
return json
}
json.source = { osmTags: {and: [osmTags]} }
json.source = { osmTags: { and: [osmTags] } }
return json
}
}
export class OrderLayer extends DesugaringStep<LayerConfigJson>{
export class OrderLayer extends DesugaringStep<LayerConfigJson> {
private static readonly layerAttributesOrder: ReadonlyArray<string> = Utils.Dedup(
(<ConfigMeta[]>layerconfig).filter((c) => c.path.length === 1).map((c) => c.path[0])
)

View file

@ -29,7 +29,7 @@ class SubstituteLayer extends Conversion<string | LayerConfigJson, LayerConfigJs
constructor(state: DesugaringContext) {
super(
"SubstituteLayer",
"Converts the identifier of a builtin layer into the actual layer, or converts a 'builtin' syntax with override in the fully expanded form. Note that 'tagRenderings+' will be inserted before 'leftover-questions'",
"Converts the identifier of a builtin layer into the actual layer, or converts a 'builtin' syntax with override in the fully expanded form. Note that 'tagRenderings+' will be inserted before 'leftover-questions'"
)
this._state = state
}
@ -72,8 +72,16 @@ class SubstituteLayer extends Conversion<string | LayerConfigJson, LayerConfigJs
for (const name of names) {
const found = Utils.Clone(state.sharedLayers.get(name))
if (found === undefined) {
const nearbyNames = Utils.sortedByLevenshteinDistance(name, Array.from(state.sharedLayers.keys()))
context.err("Layer with name " + name + " not found. Dit you mean one of "+nearbyNames.slice(0, 3))
const nearbyNames = Utils.sortedByLevenshteinDistance(
name,
Array.from(state.sharedLayers.keys())
)
context.err(
"Layer with name " +
name +
" not found. Dit you mean one of " +
nearbyNames.slice(0, 3)
)
reportNotFound(name)
continue
}
@ -504,7 +512,7 @@ class WarnForUnsubstitutedLayersInTheme extends DesugaringStep<ThemeConfigJson>
if (layer["builtin"] !== undefined) {
continue
}
if(layer["override"]!==undefined){
if (layer["override"] !== undefined) {
context.err("Got an `override` block without a `builtin`-specification")
continue
}
@ -603,8 +611,7 @@ class PostvalidateTheme extends DesugaringStep<ThemeConfigJson> {
return json
}
}
export class OrderTheme extends DesugaringStep<ThemeConfigJson>{
export class OrderTheme extends DesugaringStep<ThemeConfigJson> {
private static readonly themeAttributesOrder: ReadonlyArray<string> = Utils.Dedup(
(<ConfigMeta[]>themeconfig).filter((c) => c.path.length === 1).map((c) => c.path[0])
)
@ -622,7 +629,10 @@ class DeriveDescription extends DesugaringStep<ThemeConfigJson> {
private readonly _key: string
private readonly _sourceKey: "name"
constructor(key: "icon" | "description" | "title", sourceKey?: "name") {
super("DeriveDescription", "If a single layer and no description is given, steal the description from the layer")
super(
"DeriveDescription",
"If a single layer and no description is given, steal the description from the layer"
)
this._key = key
this._sourceKey = sourceKey
}
@ -631,11 +641,15 @@ class DeriveDescription extends DesugaringStep<ThemeConfigJson> {
if (json[this._key]) {
return json
}
const msg = "This theme has no "+this._key+". If there is only a single layer, we can steal it from this layer though. Current layers are "+json.layers.map(l => l["id"]).join("; ")
const msg =
"This theme has no " +
this._key +
". If there is only a single layer, we can steal it from this layer though. Current layers are " +
json.layers.map((l) => l["id"]).join("; ")
if (json.layers.length !== 1) {
context.err(msg)
}
const l = <LayerConfigJson> json.layers[0] // Already expanded
const l = <LayerConfigJson>json.layers[0] // Already expanded
context.info(`Added '${this._key}' to theme ${json.id} based on single layer`)
return {
...json,
@ -659,9 +673,9 @@ export class PrepareTheme extends Fuse<ThemeConfigJson> {
new PreparePersonalTheme(state),
new WarnForUnsubstitutedLayersInTheme(),
new On("layers", new Concat(new SubstituteLayer(state))),
new DeriveDescription( "description"),
new DeriveDescription( "icon"),
new DeriveDescription( "title", "name"),
new DeriveDescription("description"),
new DeriveDescription("icon"),
new DeriveDescription("title", "name"),
new SetDefault("socialImage", "assets/SocialImage.png", true),
// We expand all tagrenderings first...

View file

@ -330,14 +330,14 @@ export class PrevalidateLayer extends DesugaringStep<LayerConfigJson> {
}
if (json.filter && Array.isArray(json.filter)) {
new On("filter", new Each(new ValidateFilter())).convert(<any> json, context)
new On("filter", new Each(new ValidateFilter())).convert(<any>json, context)
}
if (json.tagRenderings !== undefined) {
new On(
"tagRenderings",
new Each(new ValidateTagRenderings(json, this._doesImageExist))
).convert(<any> json, context)
).convert(<any>json, context)
}
if (json.pointRendering !== null && json.pointRendering !== undefined) {

View file

@ -130,9 +130,11 @@ export class DoesImageExist extends DesugaringStep<string> {
private static licensePaths: Set<string>
public static constructWithLicenses(checkExistsSync?: (path: string) => boolean, ignore?: Set<string>) {
public static constructWithLicenses(
checkExistsSync?: (path: string) => boolean,
ignore?: Set<string>
) {
if (!DoesImageExist.licensePaths) {
const licensePaths = new Set<string>()
for (const i in licenses) {
licensePaths.add(licenses[i].path)
@ -141,7 +143,6 @@ export class DoesImageExist extends DesugaringStep<string> {
}
return new DoesImageExist(DoesImageExist.licensePaths, checkExistsSync, ignore)
}
}
class OverrideShadowingCheck extends DesugaringStep<ThemeConfigJson> {
@ -906,7 +907,10 @@ export class ValidateFilter extends DesugaringStep<string | FilterConfigJson> {
super("ValidateFilter", "Detect common errors in the filters")
}
convert(filter: string | FilterConfigJson, context: ConversionContext): string | FilterConfigJson {
convert(
filter: string | FilterConfigJson,
context: ConversionContext
): string | FilterConfigJson {
if (typeof filter === "string") {
// Calling another filter, we skip
return filter