forked from MapComplete/MapComplete
chore: automated housekeeping...
This commit is contained in:
parent
a190597905
commit
087e639020
382 changed files with 29496 additions and 2675 deletions
|
|
@ -37,7 +37,10 @@ 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
|
||||
|
|
@ -157,7 +160,7 @@ class LayerBuilder extends Conversion<object, Map<string, LayerConfigJson>> {
|
|||
levels: LevelInfo[],
|
||||
states: Map<string, "clean" | "dirty" | "changed">,
|
||||
sharedTagRenderings: QuestionableTagRenderingConfigJson[],
|
||||
labelBlacklist: ReadonlySet<string>,
|
||||
labelBlacklist: ReadonlySet<string>
|
||||
) {
|
||||
super("LayerBuilder", "Builds all the layers, writes them to file")
|
||||
this._levels = levels
|
||||
|
|
@ -184,7 +187,7 @@ class LayerBuilder extends Conversion<object, Map<string, LayerConfigJson>> {
|
|||
}
|
||||
|
||||
writeLayer(layer: LayerConfigJson) {
|
||||
if (layer.labels?.some(l => this._labelBlacklist.has(l))) {
|
||||
if (layer.labels?.some((l) => this._labelBlacklist.has(l))) {
|
||||
console.log("Not writing layer " + layer.id + ", censored")
|
||||
return
|
||||
}
|
||||
|
|
@ -329,24 +332,27 @@ class ReorderFiles extends Script {
|
|||
super("Reorders the attributes in the layers and theme files")
|
||||
}
|
||||
|
||||
private lintAll<T>(items: {parsed: T, path: string}[], reorder: DesugaringStep<T>){
|
||||
private lintAll<T>(items: { parsed: T; path: string }[], reorder: DesugaringStep<T>) {
|
||||
for (const item of items) {
|
||||
const l = reorder.convertStrict(item.parsed, ConversionContext.construct([item.path], ["reorder"]))
|
||||
const l = reorder.convertStrict(
|
||||
item.parsed,
|
||||
ConversionContext.construct([item.path], ["reorder"])
|
||||
)
|
||||
const content = JSON.stringify(l, null, " ")
|
||||
const contentOld = JSON.stringify(item.parsed, null, " ")
|
||||
if(contentOld === content){
|
||||
if (contentOld === content) {
|
||||
continue
|
||||
}
|
||||
const orig = readFileSync(item.path, "utf-8")
|
||||
const ending = orig.endsWith("\n")? "\n" : ""
|
||||
writeFileSync(item.path, content+ending, "utf-8")
|
||||
const ending = orig.endsWith("\n") ? "\n" : ""
|
||||
writeFileSync(item.path, content + ending, "utf-8")
|
||||
}
|
||||
}
|
||||
|
||||
async main(){
|
||||
async main() {
|
||||
console.log("Reordering layers and themes")
|
||||
const orderL = new OrderLayer()
|
||||
const layers =ScriptUtils.getLayerFiles()
|
||||
const layers = ScriptUtils.getLayerFiles()
|
||||
this.lintAll(layers, orderL)
|
||||
|
||||
const orderT = new OrderTheme()
|
||||
|
|
@ -365,12 +371,19 @@ class CensorLayer extends DesugaringStep<LayerConfigJson> {
|
|||
|
||||
convert(json: LayerConfigJson, context: ConversionContext): LayerConfigJson {
|
||||
json = { ...json }
|
||||
json.tagRenderings = json.tagRenderings?.filter(trs => {
|
||||
json.tagRenderings = json.tagRenderings?.filter((trs) => {
|
||||
const tr = <QuestionableTagRenderingConfigJson>trs
|
||||
const keep = !(tr.labels ?? [])?.some(l => this._excludedLabels.has(l))
|
||||
const keep = !(tr.labels ?? [])?.some((l) => this._excludedLabels.has(l))
|
||||
if (!keep) {
|
||||
const forbidden = (tr.labels ?? [])?.filter(l => this._excludedLabels.has(l))
|
||||
context.info("Dropping tagRendering " + tr.id + " from layer " + json.id + " due to forbidden label: " + forbidden.join(", "))
|
||||
const forbidden = (tr.labels ?? [])?.filter((l) => this._excludedLabels.has(l))
|
||||
context.info(
|
||||
"Dropping tagRendering " +
|
||||
tr.id +
|
||||
" from layer " +
|
||||
json.id +
|
||||
" due to forbidden label: " +
|
||||
forbidden.join(", ")
|
||||
)
|
||||
}
|
||||
return keep
|
||||
})
|
||||
|
|
@ -378,24 +391,33 @@ class CensorLayer extends DesugaringStep<LayerConfigJson> {
|
|||
}
|
||||
}
|
||||
|
||||
class CensorTheme extends Fuse<ThemeConfigJson & {layers: LayerConfigJson[]}> {
|
||||
class CensorTheme extends Fuse<ThemeConfigJson & { layers: LayerConfigJson[] }> {
|
||||
private readonly _excludedLabels: ReadonlySet<string>
|
||||
|
||||
constructor(excludedLabels: ReadonlySet<string>) {
|
||||
super("Removes unwanted layers for specific builds (mostly play store)",
|
||||
new On("layers", new Each(
|
||||
new CensorLayer(excludedLabels),
|
||||
)),
|
||||
super(
|
||||
"Removes unwanted layers for specific builds (mostly play store)",
|
||||
new On("layers", new Each(new CensorLayer(excludedLabels)))
|
||||
)
|
||||
this._excludedLabels = excludedLabels
|
||||
}
|
||||
|
||||
convert(json: ThemeConfigJson & {layers: LayerConfigJson[]}, context: ConversionContext): ThemeConfigJson & {layers: LayerConfigJson[]} {
|
||||
convert(
|
||||
json: ThemeConfigJson & { layers: LayerConfigJson[] },
|
||||
context: ConversionContext
|
||||
): ThemeConfigJson & { layers: LayerConfigJson[] } {
|
||||
json = { ...json }
|
||||
const newLayers: LayerConfigJson[] = []
|
||||
for (const layer of <LayerConfigJson[]>json.layers) {
|
||||
if (layer.labels?.some(label => this._excludedLabels.has(label))) {
|
||||
context.info("Dropping layer " + layer.id + " from theme " + json.id + " due to forbidden label: " + layer.labels?.filter(l => this._excludedLabels.has(l)).join(", "))
|
||||
if (layer.labels?.some((label) => this._excludedLabels.has(label))) {
|
||||
context.info(
|
||||
"Dropping layer " +
|
||||
layer.id +
|
||||
" from theme " +
|
||||
json.id +
|
||||
" due to forbidden label: " +
|
||||
layer.labels?.filter((l) => this._excludedLabels.has(l)).join(", ")
|
||||
)
|
||||
continue
|
||||
}
|
||||
newLayers.push(layer)
|
||||
|
|
@ -411,7 +433,9 @@ class LayerOverviewUtils extends Script {
|
|||
public static readonly themePath = "./public/assets/generated/themes/"
|
||||
|
||||
constructor() {
|
||||
super("Reviews and generates the compiled themes. Arguments: '[--exclude-labels=label0,label1] --themes=theme0,theme1'")
|
||||
super(
|
||||
"Reviews and generates the compiled themes. Arguments: '[--exclude-labels=label0,label1] --themes=theme0,theme1'"
|
||||
)
|
||||
}
|
||||
|
||||
private static publicLayerIdsFrom(themefiles: ThemeConfigJson[]): Set<string> {
|
||||
|
|
@ -739,14 +763,16 @@ class LayerOverviewUtils extends Script {
|
|||
?.substring("--themes=".length)
|
||||
?.split(",") ?? []
|
||||
)
|
||||
const labelBlacklist = new Set(args.find(a => a.startsWith("--exclude-labels="))
|
||||
?.substring("--exclude-labels=".length)
|
||||
?.split(",") ?? [])
|
||||
|
||||
const labelBlacklist = new Set(
|
||||
args
|
||||
.find((a) => a.startsWith("--exclude-labels="))
|
||||
?.substring("--exclude-labels=".length)
|
||||
?.split(",") ?? []
|
||||
)
|
||||
|
||||
const forceReload = args.some((a) => a == "--force") || labelBlacklist.size > 0
|
||||
|
||||
console.log("Arguments are:",{ labelBlacklist, themeWhitelist, forceReload })
|
||||
console.log("Arguments are:", { labelBlacklist, themeWhitelist, forceReload })
|
||||
const doesImageExist = DoesImageExist.constructWithLicenses(existsSync)
|
||||
const sharedLayers = this.buildLayerIndex(doesImageExist, labelBlacklist)
|
||||
|
||||
|
|
@ -774,7 +800,7 @@ class LayerOverviewUtils extends Script {
|
|||
recompiledThemes,
|
||||
forceReload,
|
||||
themeWhitelist,
|
||||
labelBlacklist,
|
||||
labelBlacklist
|
||||
)
|
||||
|
||||
new ValidateThemeEnsemble().convertStrict(
|
||||
|
|
@ -885,7 +911,10 @@ class LayerOverviewUtils extends Script {
|
|||
return results
|
||||
}
|
||||
|
||||
private buildLayerIndex(doesImageExist: DoesImageExist, labelBlacklist: Set<string>): Map<string, LayerConfigJson> {
|
||||
private buildLayerIndex(
|
||||
doesImageExist: DoesImageExist,
|
||||
labelBlacklist: Set<string>
|
||||
): Map<string, LayerConfigJson> {
|
||||
// First, we expand and validate all builtin layers. These are written to src/assets/generated/layers
|
||||
// At the same time, an index of available layers is built.
|
||||
const sharedQuestions = this.getSharedTagRenderings(doesImageExist)
|
||||
|
|
@ -946,10 +975,13 @@ class LayerOverviewUtils extends Script {
|
|||
levels,
|
||||
layerState,
|
||||
sharedQuestions,
|
||||
labelBlacklist,
|
||||
labelBlacklist
|
||||
)
|
||||
builder.writeLayer(sharedQuestionsDef)
|
||||
const allLayers = builder.convertStrict({}, ConversionContext.construct([], ["Building the layer index"]))
|
||||
const allLayers = builder.convertStrict(
|
||||
{},
|
||||
ConversionContext.construct([], ["Building the layer index"])
|
||||
)
|
||||
if (layerState.get("usersettings") !== "clean") {
|
||||
// We always need the calculated tags of 'usersettings', so we export them separately if dirty
|
||||
|
||||
|
|
@ -1088,7 +1120,7 @@ class LayerOverviewUtils extends Script {
|
|||
recompiledThemes: string[],
|
||||
forceReload: boolean,
|
||||
whitelist: ReadonlySet<string>,
|
||||
labelBlacklist: ReadonlySet<string>,
|
||||
labelBlacklist: ReadonlySet<string>
|
||||
): Map<string, ThemeConfigJson> {
|
||||
console.log(" ---------- VALIDATING BUILTIN THEMES ---------")
|
||||
const themeFiles = ScriptUtils.getThemeFiles()
|
||||
|
|
@ -1134,7 +1166,7 @@ class LayerOverviewUtils extends Script {
|
|||
continue
|
||||
}
|
||||
|
||||
if (themeFile.labels?.some(l => labelBlacklist.has(l))) {
|
||||
if (themeFile.labels?.some((l) => labelBlacklist.has(l))) {
|
||||
console.log("Skipping theme due to label", themeFile.id)
|
||||
continue
|
||||
}
|
||||
|
|
@ -1150,17 +1182,16 @@ class LayerOverviewUtils extends Script {
|
|||
!forceReload &&
|
||||
!LayerOverviewUtils.shouldBeUpdated([themePath, ...usedLayers], targetPath)
|
||||
) {
|
||||
const parsed = <ThemeConfigJson>JSON.parse(
|
||||
readFileSync(LayerOverviewUtils.themePath + themeFile.id + ".json", "utf8"),
|
||||
const parsed = <ThemeConfigJson>(
|
||||
JSON.parse(
|
||||
readFileSync(LayerOverviewUtils.themePath + themeFile.id + ".json", "utf8")
|
||||
)
|
||||
)
|
||||
|
||||
skippedThemes.push(themeFile.id)
|
||||
|
||||
ScriptUtils.erasableLog("Skipping", themeFile.id)
|
||||
fixed.set(
|
||||
themeFile.id,
|
||||
parsed,
|
||||
)
|
||||
fixed.set(themeFile.id, parsed)
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
@ -1186,12 +1217,14 @@ class LayerOverviewUtils extends Script {
|
|||
themeFile,
|
||||
ConversionContext.construct([themePath], ["PrepareLayer"])
|
||||
)
|
||||
if(themeFile.labels?.some(l => labelBlacklist.has(l))){
|
||||
if (themeFile.labels?.some((l) => labelBlacklist.has(l))) {
|
||||
continue
|
||||
}
|
||||
|
||||
themeFile = censorTheme.convertStrict(<any> themeFile,
|
||||
ConversionContext.construct([themePath], ["Censoring"]))
|
||||
themeFile = censorTheme.convertStrict(
|
||||
<any>themeFile,
|
||||
ConversionContext.construct([themePath], ["Censoring"])
|
||||
)
|
||||
|
||||
if (themeFile.icon.endsWith(".svg")) {
|
||||
try {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue