forked from MapComplete/MapComplete
Reformat all files with prettier
This commit is contained in:
parent
e22d189376
commit
b541d3eab4
382 changed files with 50893 additions and 35566 deletions
|
@ -1,49 +1,56 @@
|
|||
import {readFileSync, writeFileSync} from "fs";
|
||||
import {DesugaringStep} from "../Models/ThemeConfig/Conversion/Conversion";
|
||||
import {LayerConfigJson} from "../Models/ThemeConfig/Json/LayerConfigJson";
|
||||
import {Utils} from "../Utils";
|
||||
import Translations from "../UI/i18n/Translations";
|
||||
import { readFileSync, writeFileSync } from "fs"
|
||||
import { DesugaringStep } from "../Models/ThemeConfig/Conversion/Conversion"
|
||||
import { LayerConfigJson } from "../Models/ThemeConfig/Json/LayerConfigJson"
|
||||
import { Utils } from "../Utils"
|
||||
import Translations from "../UI/i18n/Translations"
|
||||
|
||||
class ConvertImagesToIcon extends DesugaringStep<LayerConfigJson> {
|
||||
private _iconClass: string;
|
||||
private _iconClass: string
|
||||
|
||||
constructor(iconClass: string) {
|
||||
super("Searches for images in the 'then' path, removes the <img> block and extracts the image itself a 'icon'",
|
||||
[], "ConvertImagesToIcon")
|
||||
this._iconClass = iconClass;
|
||||
super(
|
||||
"Searches for images in the 'then' path, removes the <img> block and extracts the image itself a 'icon'",
|
||||
[],
|
||||
"ConvertImagesToIcon"
|
||||
)
|
||||
this._iconClass = iconClass
|
||||
}
|
||||
|
||||
convert(json: LayerConfigJson, context: string): { result: LayerConfigJson; errors?: string[]; warnings?: string[]; information?: string[] } {
|
||||
convert(
|
||||
json: LayerConfigJson,
|
||||
context: string
|
||||
): { result: LayerConfigJson; errors?: string[]; warnings?: string[]; information?: string[] } {
|
||||
const information = []
|
||||
const errors = []
|
||||
json = Utils.Clone(json)
|
||||
Utils.WalkPath(
|
||||
["tagRenderings", "mappings"],
|
||||
json,
|
||||
mapping => {
|
||||
const then = Translations.T(mapping.then)
|
||||
const images = Utils.Dedup(then.ExtractImages())
|
||||
if (images.length == 0) {
|
||||
return mapping
|
||||
}
|
||||
if (images.length > 1) {
|
||||
errors.push("The mapping " + mapping.then + " has multiple images: " + images.join(", "))
|
||||
}
|
||||
information.push("Replaced image " + images[0])
|
||||
const replaced = then.OnEveryLanguage((s) => {
|
||||
return s.replace(/(<div [^>]*>)?<img [^>]*> ?/, "").replace(/<\/div>$/, "").trim()
|
||||
})
|
||||
|
||||
mapping.then = replaced.translations
|
||||
mapping.icon = {path: images[0], class: this._iconClass}
|
||||
Utils.WalkPath(["tagRenderings", "mappings"], json, (mapping) => {
|
||||
const then = Translations.T(mapping.then)
|
||||
const images = Utils.Dedup(then.ExtractImages())
|
||||
if (images.length == 0) {
|
||||
return mapping
|
||||
}
|
||||
)
|
||||
if (images.length > 1) {
|
||||
errors.push(
|
||||
"The mapping " + mapping.then + " has multiple images: " + images.join(", ")
|
||||
)
|
||||
}
|
||||
information.push("Replaced image " + images[0])
|
||||
const replaced = then.OnEveryLanguage((s) => {
|
||||
return s
|
||||
.replace(/(<div [^>]*>)?<img [^>]*> ?/, "")
|
||||
.replace(/<\/div>$/, "")
|
||||
.trim()
|
||||
})
|
||||
|
||||
mapping.then = replaced.translations
|
||||
mapping.icon = { path: images[0], class: this._iconClass }
|
||||
return mapping
|
||||
})
|
||||
|
||||
return {
|
||||
information,
|
||||
result: json
|
||||
};
|
||||
result: json,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -57,9 +64,12 @@ function main() {
|
|||
const iconClass = args[1] ?? "small"
|
||||
const targetFile = args[2] ?? path + ".autoconverted.json"
|
||||
const parsed = JSON.parse(readFileSync(path, "UTF8"))
|
||||
const converted = new ConvertImagesToIcon(iconClass).convertStrict(parsed, "While running the fixImagesInTagRenderings-script")
|
||||
const converted = new ConvertImagesToIcon(iconClass).convertStrict(
|
||||
parsed,
|
||||
"While running the fixImagesInTagRenderings-script"
|
||||
)
|
||||
writeFileSync(targetFile, JSON.stringify(converted, null, " "))
|
||||
console.log("Written fixed version to " + targetFile)
|
||||
}
|
||||
|
||||
main();
|
||||
main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue