forked from MapComplete/MapComplete
Refactoring: use theme
instead of layout
in a lot of places
This commit is contained in:
parent
9427083939
commit
bdc9ba52a6
104 changed files with 445 additions and 449 deletions
|
@ -2,7 +2,7 @@ import * as fs from "fs"
|
|||
import { existsSync, lstatSync, readdirSync, readFileSync } from "fs"
|
||||
import { Utils } from "../src/Utils"
|
||||
import { https } from "follow-redirects"
|
||||
import { LayoutConfigJson } from "../src/Models/ThemeConfig/Json/LayoutConfigJson"
|
||||
import { ThemeConfigJson } from "../src/Models/ThemeConfig/Json/ThemeConfigJson"
|
||||
import { LayerConfigJson } from "../src/Models/ThemeConfig/Json/LayerConfigJson"
|
||||
import xml2js from "xml2js"
|
||||
|
||||
|
@ -111,7 +111,7 @@ export default class ScriptUtils {
|
|||
}
|
||||
|
||||
public static getThemeFiles(useTranslationPaths = false): {
|
||||
parsed: LayoutConfigJson;
|
||||
parsed: ThemeConfigJson;
|
||||
path: string;
|
||||
raw: string
|
||||
}[] {
|
||||
|
|
|
@ -8,7 +8,7 @@ import QueryParameterDocumentation from "../src/UI/QueryParameterDocumentation"
|
|||
import ScriptUtils from "./ScriptUtils"
|
||||
import Translations from "../src/UI/i18n/Translations"
|
||||
import themeOverview from "../src/assets/generated/theme_overview.json"
|
||||
import LayoutConfig from "../src/Models/ThemeConfig/LayoutConfig"
|
||||
import ThemeConfig from "../src/Models/ThemeConfig/ThemeConfig"
|
||||
import bookcases from "../src/assets/generated/themes/bookcases.json"
|
||||
import fakedom from "fake-dom"
|
||||
import unit from "../src/assets/generated/layers/unit.json"
|
||||
|
@ -253,7 +253,7 @@ export class GenerateDocs extends Script {
|
|||
}
|
||||
|
||||
private generateHotkeyDocs() {
|
||||
new ThemeViewState(new LayoutConfig(<any>bookcases), new Set())
|
||||
new ThemeViewState(new ThemeConfig(<any>bookcases), new Set())
|
||||
this.WriteMarkdownFile("./Docs/Hotkeys.md", Hotkeys.generateDocumentation(), [
|
||||
"src/UI/Base/Hotkeys.ts",
|
||||
])
|
||||
|
@ -455,7 +455,7 @@ export class GenerateDocs extends Script {
|
|||
)
|
||||
}
|
||||
|
||||
private generateForTheme(theme: LayoutConfig): void {
|
||||
private generateForTheme(theme: ThemeConfig): void {
|
||||
const allLayers = AllSharedLayers.getSharedLayersConfigs()
|
||||
const layersToShow = theme.layers.filter(
|
||||
(l) =>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import ScriptUtils from "./ScriptUtils"
|
||||
import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "fs"
|
||||
import licenses from "../src/assets/generated/license_info.json"
|
||||
import { LayoutConfigJson } from "../src/Models/ThemeConfig/Json/LayoutConfigJson"
|
||||
import { ThemeConfigJson } from "../src/Models/ThemeConfig/Json/ThemeConfigJson"
|
||||
import { LayerConfigJson } from "../src/Models/ThemeConfig/Json/LayerConfigJson"
|
||||
import Constants from "../src/Models/Constants"
|
||||
import {
|
||||
|
@ -29,7 +29,7 @@ import LayerConfig from "../src/Models/ThemeConfig/LayerConfig"
|
|||
import PointRenderingConfig from "../src/Models/ThemeConfig/PointRenderingConfig"
|
||||
import { ConversionContext } from "../src/Models/ThemeConfig/Conversion/ConversionContext"
|
||||
import { GenerateFavouritesLayer } from "./generateFavouritesLayer"
|
||||
import LayoutConfig, { MinimalLayoutInformation } from "../src/Models/ThemeConfig/LayoutConfig"
|
||||
import ThemeConfig, { MinimalThemeInformation } from "../src/Models/ThemeConfig/ThemeConfig"
|
||||
import Translations from "../src/UI/i18n/Translations"
|
||||
import { Translatable } from "../src/Models/ThemeConfig/Json/Translatable"
|
||||
import { ValidateThemeAndLayers } from "../src/Models/ThemeConfig/Conversion/ValidateThemeAndLayers"
|
||||
|
@ -148,14 +148,14 @@ class LayerOverviewUtils extends Script {
|
|||
super("Reviews and generates the compiled themes")
|
||||
}
|
||||
|
||||
private static publicLayerIdsFrom(themefiles: LayoutConfigJson[]): Set<string> {
|
||||
private static publicLayerIdsFrom(themefiles: ThemeConfigJson[]): Set<string> {
|
||||
const publicThemes = [].concat(...themefiles.filter((th) => !th.hideFromOverview))
|
||||
|
||||
return new Set([].concat(...publicThemes.map((th) => this.extractLayerIdsFrom(th))))
|
||||
}
|
||||
|
||||
private static extractLayerIdsFrom(
|
||||
themeFile: LayoutConfigJson,
|
||||
themeFile: ThemeConfigJson,
|
||||
includeInlineLayers = true,
|
||||
): string[] {
|
||||
const publicLayerIds: string[] = []
|
||||
|
@ -295,7 +295,7 @@ class LayerOverviewUtils extends Script {
|
|||
layerKeywords[id] = this.layerKeywords(layer)
|
||||
})
|
||||
|
||||
const perId = new Map<string, MinimalLayoutInformation>()
|
||||
const perId = new Map<string, MinimalThemeInformation>()
|
||||
for (const theme of themes) {
|
||||
|
||||
const keywords: Record<string, string[]> = {}
|
||||
|
@ -308,7 +308,7 @@ class LayerOverviewUtils extends Script {
|
|||
|
||||
}
|
||||
|
||||
const data = <MinimalLayoutInformation> {
|
||||
const data = <MinimalThemeInformation> {
|
||||
id: theme.id,
|
||||
title: theme.title,
|
||||
shortDescription: LayerOverviewUtils.cleanTranslation(theme.shortDescription),
|
||||
|
@ -342,7 +342,7 @@ class LayerOverviewUtils extends Script {
|
|||
)
|
||||
}
|
||||
|
||||
writeTheme(theme: LayoutConfigJson) {
|
||||
writeTheme(theme: ThemeConfigJson) {
|
||||
if (!existsSync(LayerOverviewUtils.themePath)) {
|
||||
mkdirSync(LayerOverviewUtils.themePath)
|
||||
}
|
||||
|
@ -519,7 +519,7 @@ class LayerOverviewUtils extends Script {
|
|||
)
|
||||
|
||||
new ValidateThemeEnsemble().convertStrict(
|
||||
Array.from(sharedThemes.values()).map((th) => new LayoutConfig(th, true)),
|
||||
Array.from(sharedThemes.values()).map((th) => new ThemeConfig(th, true)),
|
||||
)
|
||||
|
||||
if (recompiledThemes.length > 0) {
|
||||
|
@ -545,7 +545,7 @@ class LayerOverviewUtils extends Script {
|
|||
if: "theme=" + th.id,
|
||||
then: th.icon,
|
||||
}))
|
||||
const proto: LayoutConfigJson = JSON.parse(
|
||||
const proto: ThemeConfigJson = JSON.parse(
|
||||
readFileSync("./assets/themes/mapcomplete-changes/mapcomplete-changes.proto.json", {
|
||||
encoding: "utf8",
|
||||
}),
|
||||
|
@ -689,7 +689,7 @@ class LayerOverviewUtils extends Script {
|
|||
* @param themeFile
|
||||
* @private
|
||||
*/
|
||||
private extractJavascriptCode(themeFile: LayoutConfigJson) {
|
||||
private extractJavascriptCode(themeFile: ThemeConfigJson) {
|
||||
const allCode = [
|
||||
"import {Feature} from 'geojson'",
|
||||
"import { ExtraFuncType } from \"../../../Logic/ExtraFunctions\";",
|
||||
|
@ -804,10 +804,10 @@ class LayerOverviewUtils extends Script {
|
|||
recompiledThemes: string[],
|
||||
forceReload: boolean,
|
||||
whitelist: Set<string>,
|
||||
): Map<string, LayoutConfigJson> {
|
||||
): Map<string, ThemeConfigJson> {
|
||||
console.log(" ---------- VALIDATING BUILTIN THEMES ---------")
|
||||
const themeFiles = ScriptUtils.getThemeFiles()
|
||||
const fixed = new Map<string, LayoutConfigJson>()
|
||||
const fixed = new Map<string, ThemeConfigJson>()
|
||||
|
||||
const publicLayers = LayerOverviewUtils.publicLayerIdsFrom(
|
||||
themeFiles.map((th) => th.parsed),
|
||||
|
|
|
@ -3,8 +3,8 @@ import Locale from "../src/UI/i18n/Locale"
|
|||
import Translations from "../src/UI/i18n/Translations"
|
||||
import { Translation } from "../src/UI/i18n/Translation"
|
||||
import all_known_layouts from "../src/assets/generated/known_themes.json"
|
||||
import { LayoutConfigJson } from "../src/Models/ThemeConfig/Json/LayoutConfigJson"
|
||||
import LayoutConfig from "../src/Models/ThemeConfig/LayoutConfig"
|
||||
import { ThemeConfigJson } from "../src/Models/ThemeConfig/Json/ThemeConfigJson"
|
||||
import ThemeConfig from "../src/Models/ThemeConfig/ThemeConfig"
|
||||
import xml2js from "xml2js"
|
||||
import ScriptUtils from "./ScriptUtils"
|
||||
import { Utils } from "../src/Utils"
|
||||
|
@ -100,7 +100,7 @@ class GenerateLayouts extends Script {
|
|||
return newname
|
||||
}
|
||||
|
||||
async createSocialImage(layout: LayoutConfig, template: "" | "Wide"): Promise<string> {
|
||||
async createSocialImage(layout: ThemeConfig, template: "" | "Wide"): Promise<string> {
|
||||
if (!layout.icon.endsWith(".svg")) {
|
||||
console.warn(
|
||||
"Not creating a social image for " +
|
||||
|
@ -160,7 +160,7 @@ class GenerateLayouts extends Script {
|
|||
}
|
||||
|
||||
async createManifest(
|
||||
layout: LayoutConfig,
|
||||
layout: ThemeConfig,
|
||||
alreadyWritten: string[]
|
||||
): Promise<{
|
||||
manifest: any
|
||||
|
@ -319,8 +319,8 @@ class GenerateLayouts extends Script {
|
|||
}
|
||||
|
||||
async generateCsp(
|
||||
layout: LayoutConfig,
|
||||
layoutJson: LayoutConfigJson,
|
||||
layout: ThemeConfig,
|
||||
layoutJson: ThemeConfigJson,
|
||||
options: {
|
||||
scriptSrcs: string[]
|
||||
}
|
||||
|
@ -441,8 +441,8 @@ class GenerateLayouts extends Script {
|
|||
}
|
||||
|
||||
async createLandingPage(
|
||||
layout: LayoutConfig,
|
||||
layoutJson: LayoutConfigJson,
|
||||
layout: ThemeConfig,
|
||||
layoutJson: ThemeConfigJson,
|
||||
whiteIcons,
|
||||
alreadyWritten
|
||||
) {
|
||||
|
@ -456,7 +456,7 @@ class GenerateLayouts extends Script {
|
|||
.replace(/"/g, '\\"')
|
||||
let ogImage = layout.socialImage
|
||||
let twitterImage = ogImage
|
||||
if (ogImage === LayoutConfig.defaultSocialImage && layout.official) {
|
||||
if (ogImage === ThemeConfig.defaultSocialImage && layout.official) {
|
||||
try {
|
||||
ogImage = (await this.createSocialImage(layout, "")) ?? layout.socialImage
|
||||
twitterImage = (await this.createSocialImage(layout, "Wide")) ?? layout.socialImage
|
||||
|
@ -573,7 +573,7 @@ class GenerateLayouts extends Script {
|
|||
)
|
||||
}
|
||||
|
||||
async createIndexFor(theme: LayoutConfig) {
|
||||
async createIndexFor(theme: ThemeConfig) {
|
||||
const filename = "index_" + theme.id + ".ts"
|
||||
|
||||
const imports = [
|
||||
|
@ -628,18 +628,18 @@ class GenerateLayouts extends Script {
|
|||
"theme",
|
||||
]
|
||||
// @ts-ignore
|
||||
const all: LayoutConfigJson[] = all_known_layouts.themes
|
||||
const all: ThemeConfigJson[] = all_known_layouts.themes
|
||||
const args = process.argv
|
||||
const theme = args[2]
|
||||
if (theme !== undefined) {
|
||||
console.warn("Only generating layout " + theme)
|
||||
}
|
||||
for (const i in all) {
|
||||
const layoutConfigJson: LayoutConfigJson = all[i]
|
||||
const layoutConfigJson: ThemeConfigJson = all[i]
|
||||
if (theme !== undefined && layoutConfigJson.id !== theme) {
|
||||
continue
|
||||
}
|
||||
const layout = new LayoutConfig(layoutConfigJson, true)
|
||||
const layout = new ThemeConfig(layoutConfigJson, true)
|
||||
const layoutName = layout.id
|
||||
if (blacklist.indexOf(layoutName.toLowerCase()) >= 0) {
|
||||
console.log(`Skipping a layout with name ${layoutName}, it is on the blacklist`)
|
||||
|
@ -668,7 +668,7 @@ class GenerateLayouts extends Script {
|
|||
}
|
||||
|
||||
const { manifest } = await this.createManifest(
|
||||
new LayoutConfig({
|
||||
new ThemeConfig({
|
||||
icon: "./assets/svg/mapcomplete_logo.svg",
|
||||
id: "index",
|
||||
layers: [],
|
||||
|
|
|
@ -2,7 +2,7 @@ import { AllKnownLayouts } from "../src/Customizations/AllKnownLayouts"
|
|||
import Locale from "../src/UI/i18n/Locale"
|
||||
import { Translation } from "../src/UI/i18n/Translation"
|
||||
import { readFileSync, writeFileSync } from "fs"
|
||||
import LayoutConfig from "../src/Models/ThemeConfig/LayoutConfig"
|
||||
import ThemeConfig from "../src/Models/ThemeConfig/ThemeConfig"
|
||||
import LayerConfig from "../src/Models/ThemeConfig/LayerConfig"
|
||||
import { Utils } from "../src/Utils"
|
||||
|
||||
|
@ -33,7 +33,7 @@ function generateTagOverview(
|
|||
return overview
|
||||
}
|
||||
|
||||
function generateLayerUsage(layer: LayerConfig, layout: LayoutConfig): any[] {
|
||||
function generateLayerUsage(layer: LayerConfig, layout: ThemeConfig): any[] {
|
||||
if (layer.name === undefined) {
|
||||
return [] // Probably a duplicate or irrelevant layer
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ function generateLayerUsage(layer: LayerConfig, layout: LayoutConfig): any[] {
|
|||
* Generates the JSON-object representing the theme for inclusion on taginfo
|
||||
* @param layout
|
||||
*/
|
||||
function generateTagInfoEntry(layout: LayoutConfig): any {
|
||||
function generateTagInfoEntry(layout: ThemeConfig): any {
|
||||
const usedTags = []
|
||||
for (const layer of layout.layers) {
|
||||
if (layer.source === null) {
|
||||
|
|
|
@ -15,7 +15,7 @@ type ErrorMessage = {
|
|||
message: {
|
||||
stacktrace: string
|
||||
message: string
|
||||
layout: string
|
||||
theme: string
|
||||
version: string
|
||||
language: string
|
||||
username: string
|
||||
|
@ -40,7 +40,7 @@ class HandleErrors extends Script {
|
|||
) {
|
||||
console.log(
|
||||
parsed.message.username,
|
||||
parsed.message.layout,
|
||||
parsed.message.theme,
|
||||
parsed.message.message,
|
||||
parsed.date
|
||||
)
|
||||
|
@ -82,7 +82,7 @@ class HandleErrors extends Script {
|
|||
} = changesObj.CreateChangesetObjects(toUpload, objects, true)
|
||||
|
||||
const changeset = Changes.buildChangesetXML("", changes)
|
||||
const path = "error_changeset_" + parsed.index + "_" + e.layout + "_" + e.username + ".osc"
|
||||
const path = "error_changeset_" + parsed.index + "_" + e.theme + "_" + e.username + ".osc"
|
||||
if (
|
||||
changeset ===
|
||||
`<osmChange version='0.6' generator='Mapcomplete ${Constants.vNumber}'></osmChange>`
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue