forked from MapComplete/MapComplete
Refactoring: simplify working with 'DoesImageExist'
This commit is contained in:
parent
47f52e4513
commit
54e1f5d44c
2 changed files with 21 additions and 19 deletions
|
@ -1,6 +1,5 @@
|
|||
import ScriptUtils from "./ScriptUtils"
|
||||
import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "fs"
|
||||
import licenses from "../src/assets/generated/license_info.json"
|
||||
import { ThemeConfigJson } from "../src/Models/ThemeConfig/Json/ThemeConfigJson"
|
||||
import { LayerConfigJson } from "../src/Models/ThemeConfig/Json/LayerConfigJson"
|
||||
import Constants from "../src/Models/Constants"
|
||||
|
@ -14,11 +13,7 @@ import {
|
|||
import { Translation } from "../src/UI/i18n/Translation"
|
||||
import { PrepareLayer } from "../src/Models/ThemeConfig/Conversion/PrepareLayer"
|
||||
import { PrepareTheme } from "../src/Models/ThemeConfig/Conversion/PrepareTheme"
|
||||
import {
|
||||
Conversion,
|
||||
DesugaringContext,
|
||||
DesugaringStep,
|
||||
} from "../src/Models/ThemeConfig/Conversion/Conversion"
|
||||
import { Conversion, DesugaringContext, DesugaringStep } from "../src/Models/ThemeConfig/Conversion/Conversion"
|
||||
import { Utils } from "../src/Utils"
|
||||
import Script from "./Script"
|
||||
import { AllSharedLayers } from "../src/Customizations/AllSharedLayers"
|
||||
|
@ -35,10 +30,7 @@ import { Translatable } from "../src/Models/ThemeConfig/Json/Translatable"
|
|||
import { ValidateThemeAndLayers } from "../src/Models/ThemeConfig/Conversion/ValidateThemeAndLayers"
|
||||
import { ExtractImages } from "../src/Models/ThemeConfig/Conversion/FixImages"
|
||||
import { TagRenderingConfigJson } from "../src/Models/ThemeConfig/Json/TagRenderingConfigJson"
|
||||
import {
|
||||
LayerConfigDependencyGraph,
|
||||
LevelInfo,
|
||||
} from "../src/Models/ThemeConfig/LayerConfigDependencyGraph"
|
||||
import { LayerConfigDependencyGraph, LevelInfo } from "../src/Models/ThemeConfig/LayerConfigDependencyGraph"
|
||||
|
||||
// This scripts scans 'src/assets/layers/*.json' for layer definition files and 'src/assets/themes/*.json' for theme definition files.
|
||||
// It spits out an overview of those to be used to load them
|
||||
|
@ -650,11 +642,7 @@ class LayerOverviewUtils extends Script {
|
|||
|
||||
const forceReload = args.some((a) => a == "--force")
|
||||
|
||||
const licensePaths = new Set<string>()
|
||||
for (const i in licenses) {
|
||||
licensePaths.add(licenses[i].path)
|
||||
}
|
||||
const doesImageExist = new DoesImageExist(licensePaths, existsSync)
|
||||
const doesImageExist = DoesImageExist.constructWithLicenses(existsSync)
|
||||
const sharedLayers = this.buildLayerIndex(doesImageExist)
|
||||
|
||||
const priviliged = new Set<string>(Constants.priviliged_layers)
|
||||
|
@ -677,7 +665,6 @@ class LayerOverviewUtils extends Script {
|
|||
}
|
||||
const recompiledThemes: string[] = []
|
||||
const sharedThemes = this.buildThemeIndex(
|
||||
licensePaths,
|
||||
sharedLayers,
|
||||
recompiledThemes,
|
||||
forceReload,
|
||||
|
@ -990,7 +977,6 @@ class LayerOverviewUtils extends Script {
|
|||
}
|
||||
|
||||
private buildThemeIndex(
|
||||
licensePaths: Set<string>,
|
||||
sharedLayers: Map<string, LayerConfigJson>,
|
||||
recompiledThemes: string[],
|
||||
forceReload: boolean,
|
||||
|
@ -1004,7 +990,7 @@ class LayerOverviewUtils extends Script {
|
|||
themeFiles.map((th) => th.parsed)
|
||||
)
|
||||
|
||||
const trs = this.getSharedTagRenderings(new DoesImageExist(licensePaths, existsSync))
|
||||
const trs = this.getSharedTagRenderings(DoesImageExist.constructWithLicenses(existsSync))
|
||||
|
||||
const convertState: DesugaringContext = {
|
||||
sharedLayers,
|
||||
|
@ -1076,7 +1062,7 @@ class LayerOverviewUtils extends Script {
|
|||
ConversionContext.construct([themePath], ["PrepareLayer"])
|
||||
)
|
||||
new ValidateThemeAndLayers(
|
||||
new DoesImageExist(licensePaths, existsSync, knownTagRenderings),
|
||||
DoesImageExist.constructWithLicenses(existsSync, knownTagRenderings),
|
||||
themePath,
|
||||
true,
|
||||
knownTagRenderings
|
||||
|
|
|
@ -22,6 +22,7 @@ import PointRenderingConfigJson from "../Json/PointRenderingConfigJson"
|
|||
import { PrevalidateLayer } from "./PrevalidateLayer"
|
||||
import { AvailableRasterLayers } from "../../RasterLayers"
|
||||
import { eliCategory } from "../../RasterLayerProperties"
|
||||
import licenses from "../../../assets/generated/license_info.json"
|
||||
|
||||
export class ValidateLanguageCompleteness extends DesugaringStep<ThemeConfig> {
|
||||
private readonly _languages: string[]
|
||||
|
@ -126,6 +127,21 @@ export class DoesImageExist extends DesugaringStep<string> {
|
|||
}
|
||||
return image
|
||||
}
|
||||
|
||||
private static licensePaths: 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)
|
||||
}
|
||||
DoesImageExist.licensePaths = licensePaths
|
||||
}
|
||||
return new DoesImageExist(DoesImageExist.licensePaths, checkExistsSync, ignore)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class OverrideShadowingCheck extends DesugaringStep<ThemeConfigJson> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue