forked from MapComplete/MapComplete
Add binoculars theme, auto reformat everything
This commit is contained in:
parent
38dea806c5
commit
78d6482c88
586 changed files with 115573 additions and 111842 deletions
|
|
@ -3,7 +3,6 @@
|
|||
*/
|
||||
import {Utils} from "../Utils"
|
||||
Utils.runningFromConsole = true;
|
||||
|
||||
import {readFileSync, writeFileSync} from "fs";
|
||||
import SmallLicense from "../Models/smallLicense";
|
||||
import AllKnownLayers from "../Customizations/AllKnownLayers";
|
||||
|
|
@ -13,9 +12,10 @@ import {LayoutConfigJson} from "../Models/ThemeConfig/Json/LayoutConfigJson";
|
|||
import LayerConfig from "../Models/ThemeConfig/LayerConfig";
|
||||
|
||||
|
||||
|
||||
ScriptUtils.fixUtils()
|
||||
|
||||
if(process.argv.length == 2){
|
||||
if (process.argv.length == 2) {
|
||||
console.log("USAGE: ts-node scripts/fixTheme <path to theme>")
|
||||
throw "No path specified"
|
||||
}
|
||||
|
|
@ -25,33 +25,33 @@ const dir = path.substring(0, path.lastIndexOf("/"))
|
|||
|
||||
console.log("Fixing up ", path)
|
||||
|
||||
const themeConfigJson : LayoutConfigJson = JSON.parse(readFileSync(path, "UTF8"))
|
||||
const themeConfigJson: LayoutConfigJson = JSON.parse(readFileSync(path, "UTF8"))
|
||||
|
||||
const licenses : SmallLicense[] = []
|
||||
const licenses: SmallLicense[] = []
|
||||
|
||||
const replacements: {source: string, destination: string}[] = []
|
||||
const replacements: { source: string, destination: string }[] = []
|
||||
|
||||
for (const layerConfigJson of themeConfigJson.layers) {
|
||||
if(typeof (layerConfigJson) === "string"){
|
||||
if (typeof (layerConfigJson) === "string") {
|
||||
continue;
|
||||
}
|
||||
if(layerConfigJson["overpassTags"] !== undefined){
|
||||
if (layerConfigJson["overpassTags"] !== undefined) {
|
||||
const tags = layerConfigJson["overpassTags"];
|
||||
layerConfigJson["overpassTags"] = undefined;
|
||||
layerConfigJson["source"] = { osmTags : tags}
|
||||
layerConfigJson["source"] = {osmTags: tags}
|
||||
}
|
||||
// @ts-ignore
|
||||
const layerConfig = new LayerConfig(layerConfigJson, AllKnownLayers.sharedUnits, "fix theme",true)
|
||||
const images : string[] = Array.from(layerConfig.ExtractImages())
|
||||
const layerConfig = new LayerConfig(layerConfigJson, AllKnownLayers.sharedUnits, "fix theme", true)
|
||||
const images: string[] = Array.from(layerConfig.ExtractImages())
|
||||
const remoteImages = images.filter(img => img.startsWith("http"))
|
||||
|
||||
|
||||
for (const remoteImage of remoteImages) {
|
||||
|
||||
|
||||
|
||||
|
||||
const filename = remoteImage.substring(remoteImage.lastIndexOf("/"))
|
||||
ScriptUtils.DownloadFileTo(remoteImage, dir + "/" + filename)
|
||||
|
||||
|
||||
|
||||
|
||||
const imgPath = remoteImage.substring(remoteImage.lastIndexOf("/") + 1)
|
||||
|
||||
for (const attributionSrc of AllImageProviders.ImageAttributionSource) {
|
||||
|
|
@ -61,26 +61,26 @@ for (const layerConfigJson of themeConfigJson.layers) {
|
|||
licenses.push({
|
||||
path: imgPath,
|
||||
license: license?.license ?? "",
|
||||
authors:Utils.NoNull([license?.artist]),
|
||||
authors: Utils.NoNull([license?.artist]),
|
||||
sources: [remoteImage]
|
||||
})
|
||||
})
|
||||
}catch(e){
|
||||
} catch (e) {
|
||||
// Hush hush
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
replacements.push({source: remoteImage, destination: `${dir}/${imgPath}`})
|
||||
}
|
||||
}
|
||||
|
||||
let fixedThemeJson = JSON.stringify(themeConfigJson, null , " ")
|
||||
let fixedThemeJson = JSON.stringify(themeConfigJson, null, " ")
|
||||
for (const replacement of replacements) {
|
||||
fixedThemeJson = fixedThemeJson.replace(new RegExp(replacement.source, "g"), replacement.destination)
|
||||
}
|
||||
|
||||
writeFileSync(dir + "/generated.license_info.json", JSON.stringify(licenses, null, " "))
|
||||
writeFileSync(path+".autofixed.json", fixedThemeJson)
|
||||
writeFileSync(path + ".autofixed.json", fixedThemeJson)
|
||||
|
||||
console.log(`IMPORTANT:
|
||||
1) Copy generated.license_info.json over into license_info.json and add the missing attributions and authors
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue