forked from MapComplete/MapComplete
		
	Chore: housekeeping
This commit is contained in:
		
							parent
							
								
									8178c5607b
								
							
						
					
					
						commit
						cd0d275965
					
				
					 73 changed files with 2105 additions and 2219 deletions
				
			
		|  | @ -107,7 +107,7 @@ function genImages(dryrun = false) { | |||
|         "wikimedia-commons-white", | ||||
|         "wikimedia_commons_white", | ||||
|         "wikipedia", | ||||
|         "github" | ||||
|         "github", | ||||
|     ].map((s) => s.toLowerCase()) | ||||
|     const dir = fs.readdirSync("./assets/svg") | ||||
| 
 | ||||
|  |  | |||
|  | @ -10,12 +10,16 @@ import { | |||
|     PrevalidateTheme, | ||||
|     ValidateLayer, | ||||
|     ValidateThemeAndLayers, | ||||
|     ValidateThemeEnsemble | ||||
|     ValidateThemeEnsemble, | ||||
| } from "../src/Models/ThemeConfig/Conversion/Validation" | ||||
| 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" | ||||
|  | @ -158,11 +162,11 @@ class LayerOverviewUtils extends Script { | |||
|                 continue | ||||
|             } | ||||
|             if (publicLayer["builtin"] !== undefined) { | ||||
|                 const bi : string | string[] = publicLayer["builtin"] | ||||
|                 const bi: string | string[] = publicLayer["builtin"] | ||||
|                 if (typeof bi === "string") { | ||||
|                     publicLayerIds.push(bi) | ||||
|                 } else { | ||||
|                     bi.forEach(id => publicLayerIds.push(id)) | ||||
|                     bi.forEach((id) => publicLayerIds.push(id)) | ||||
|                 } | ||||
|                 continue | ||||
|             } | ||||
|  | @ -204,9 +208,9 @@ class LayerOverviewUtils extends Script { | |||
|                 | LayerConfigJson | ||||
|                 | string | ||||
|                 | { | ||||
|                 builtin | ||||
|             } | ||||
|                 )[] | ||||
|                       builtin | ||||
|                   } | ||||
|             )[] | ||||
|         }[] | ||||
|     ) { | ||||
|         const perId = new Map<string, any>() | ||||
|  | @ -226,7 +230,7 @@ class LayerOverviewUtils extends Script { | |||
|                 icon: theme.icon, | ||||
|                 hideFromOverview: theme.hideFromOverview, | ||||
|                 mustHaveLanguage: theme.mustHaveLanguage, | ||||
|                 keywords: Utils.NoNull(keywords) | ||||
|                 keywords: Utils.NoNull(keywords), | ||||
|             } | ||||
|             perId.set(theme.id, data) | ||||
|         } | ||||
|  | @ -275,7 +279,9 @@ class LayerOverviewUtils extends Script { | |||
|         ) | ||||
|     } | ||||
| 
 | ||||
|     static asDict(trs: QuestionableTagRenderingConfigJson[]): Map<string, QuestionableTagRenderingConfigJson> { | ||||
|     static asDict( | ||||
|         trs: QuestionableTagRenderingConfigJson[] | ||||
|     ): Map<string, QuestionableTagRenderingConfigJson> { | ||||
|         const d = new Map<string, QuestionableTagRenderingConfigJson>() | ||||
|         for (const tr of trs) { | ||||
|             d.set(tr.id, tr) | ||||
|  | @ -283,14 +289,12 @@ class LayerOverviewUtils extends Script { | |||
|         return d | ||||
|     } | ||||
| 
 | ||||
|     getSharedTagRenderings( | ||||
|         doesImageExist: DoesImageExist | ||||
|     ): QuestionableTagRenderingConfigJson[] ; | ||||
|     getSharedTagRenderings(doesImageExist: DoesImageExist): QuestionableTagRenderingConfigJson[] | ||||
|     getSharedTagRenderings( | ||||
|         doesImageExist: DoesImageExist, | ||||
|         bootstrapTagRenderings: Map<string, QuestionableTagRenderingConfigJson>, | ||||
|         bootstrapTagRenderingsOrder: string[] | ||||
|     ): QuestionableTagRenderingConfigJson[] ; | ||||
|     ): QuestionableTagRenderingConfigJson[] | ||||
|     getSharedTagRenderings( | ||||
|         doesImageExist: DoesImageExist, | ||||
|         bootstrapTagRenderings: Map<string, QuestionableTagRenderingConfigJson> = null, | ||||
|  | @ -301,10 +305,10 @@ class LayerOverviewUtils extends Script { | |||
|                 tagRenderings: bootstrapTagRenderings, | ||||
|                 tagRenderingOrder: bootstrapTagRenderingsOrder, | ||||
|                 sharedLayers: null, | ||||
|                 publicLayers: null | ||||
|                 publicLayers: null, | ||||
|             }, | ||||
|             { | ||||
|                 addTagRenderingsToContext: true | ||||
|                 addTagRenderingsToContext: true, | ||||
|             } | ||||
|         ) | ||||
| 
 | ||||
|  | @ -322,7 +326,11 @@ class LayerOverviewUtils extends Script { | |||
|             return <QuestionableTagRenderingConfigJson[]>sharedQuestions.tagRenderings | ||||
|         } | ||||
| 
 | ||||
|         return this.getSharedTagRenderings(doesImageExist, dict, sharedQuestions.tagRenderings.map(tr => tr["id"])) | ||||
|         return this.getSharedTagRenderings( | ||||
|             doesImageExist, | ||||
|             dict, | ||||
|             sharedQuestions.tagRenderings.map((tr) => tr["id"]) | ||||
|         ) | ||||
|     } | ||||
| 
 | ||||
|     checkAllSvgs() { | ||||
|  | @ -336,7 +344,7 @@ class LayerOverviewUtils extends Script { | |||
|             "src/assets/SocialImageBanner.svg", | ||||
|             "src/assets/SocialImageRepo.svg", | ||||
|             "src/assets/svg/osm-logo.svg", | ||||
|             "src/assets/templates/*" | ||||
|             "src/assets/templates/*", | ||||
|         ] | ||||
|         for (const path of allSvgs) { | ||||
|             if ( | ||||
|  | @ -361,8 +369,8 @@ class LayerOverviewUtils extends Script { | |||
|             if (contents.indexOf("<text") > 0) { | ||||
|                 console.warn( | ||||
|                     "The SVG at " + | ||||
|                     path + | ||||
|                     " contains a `text`-tag. This is highly discouraged. Every machine viewing your theme has their own font libary, and the font you choose might not be present, resulting in a different font being rendered. Solution: open your .svg in inkscape (or another program), select the text and convert it to a path" | ||||
|                         path + | ||||
|                         " contains a `text`-tag. This is highly discouraged. Every machine viewing your theme has their own font libary, and the font you choose might not be present, resulting in a different font being rendered. Solution: open your .svg in inkscape (or another program), select the text and convert it to a path" | ||||
|                 ) | ||||
|                 errCount++ | ||||
|             } | ||||
|  | @ -425,7 +433,7 @@ class LayerOverviewUtils extends Script { | |||
|             writeFileSync( | ||||
|                 "./src/assets/generated/known_layers.json", | ||||
|                 JSON.stringify({ | ||||
|                     layers: Array.from(sharedLayers.values()).filter((l) => l.id !== "favourite") | ||||
|                     layers: Array.from(sharedLayers.values()).filter((l) => l.id !== "favourite"), | ||||
|                 }) | ||||
|             ) | ||||
|         } | ||||
|  | @ -442,11 +450,11 @@ class LayerOverviewUtils extends Script { | |||
|             // mapcomplete-changes shows an icon for each corresponding mapcomplete-theme
 | ||||
|             const iconsPerTheme = Array.from(sharedThemes.values()).map((th) => ({ | ||||
|                 if: "theme=" + th.id, | ||||
|                 then: th.icon | ||||
|                 then: th.icon, | ||||
|             })) | ||||
|             const proto: LayoutConfigJson = JSON.parse( | ||||
|                 readFileSync("./assets/themes/mapcomplete-changes/mapcomplete-changes.proto.json", { | ||||
|                     encoding: "utf8" | ||||
|                     encoding: "utf8", | ||||
|                 }) | ||||
|             ) | ||||
|             const protolayer = <LayerConfigJson>( | ||||
|  | @ -462,7 +470,7 @@ class LayerOverviewUtils extends Script { | |||
|         new DetectDuplicateFilters().convertStrict( | ||||
|             { | ||||
|                 layers: ScriptUtils.getLayerFiles().map((f) => f.parsed), | ||||
|                 themes: ScriptUtils.getThemeFiles().map((f) => f.parsed) | ||||
|                 themes: ScriptUtils.getThemeFiles().map((f) => f.parsed), | ||||
|             }, | ||||
|             ConversionContext.construct([], []) | ||||
|         ) | ||||
|  | @ -477,7 +485,7 @@ class LayerOverviewUtils extends Script { | |||
|             writeFileSync( | ||||
|                 "./src/assets/generated/known_themes.json", | ||||
|                 JSON.stringify({ | ||||
|                     themes: Array.from(sharedThemes.values()) | ||||
|                     themes: Array.from(sharedThemes.values()), | ||||
|                 }) | ||||
|             ) | ||||
|         } | ||||
|  | @ -518,8 +526,8 @@ class LayerOverviewUtils extends Script { | |||
|         console.log("   ---------- VALIDATING BUILTIN LAYERS ---------") | ||||
|         const state: DesugaringContext = { | ||||
|             tagRenderings: LayerOverviewUtils.asDict(sharedTagRenderings), | ||||
|             tagRenderingOrder: sharedTagRenderings.map(tr => tr.id), | ||||
|             sharedLayers: AllSharedLayers.getSharedLayersConfigs() | ||||
|             tagRenderingOrder: sharedTagRenderings.map((tr) => tr.id), | ||||
|             sharedLayers: AllSharedLayers.getSharedLayersConfigs(), | ||||
|         } | ||||
|         const sharedLayers = new Map<string, LayerConfigJson>() | ||||
|         const prepLayer = new PrepareLayer(state) | ||||
|  | @ -564,12 +572,12 @@ class LayerOverviewUtils extends Script { | |||
| 
 | ||||
|         console.log( | ||||
|             "Recompiled layers " + | ||||
|             recompiledLayers.join(", ") + | ||||
|             " and skipped " + | ||||
|             skippedLayers.length + | ||||
|             " layers. Detected " + | ||||
|             warningCount + | ||||
|             " warnings" | ||||
|                 recompiledLayers.join(", ") + | ||||
|                 " and skipped " + | ||||
|                 skippedLayers.length + | ||||
|                 " layers. Detected " + | ||||
|                 warningCount + | ||||
|                 " warnings" | ||||
|         ) | ||||
|         // We always need the calculated tags of 'usersettings', so we export them separately
 | ||||
|         this.extractJavascriptCodeForLayer( | ||||
|  | @ -591,11 +599,11 @@ class LayerOverviewUtils extends Script { | |||
|     private extractJavascriptCode(themeFile: LayoutConfigJson) { | ||||
|         const allCode = [ | ||||
|             "import {Feature} from 'geojson'", | ||||
|             "import { ExtraFuncType } from \"../../../Logic/ExtraFunctions\";", | ||||
|             "import { Utils } from \"../../../Utils\"", | ||||
|             'import { ExtraFuncType } from "../../../Logic/ExtraFunctions";', | ||||
|             'import { Utils } from "../../../Utils"', | ||||
|             "export class ThemeMetaTagging {", | ||||
|             "   public static readonly themeName = " + JSON.stringify(themeFile.id), | ||||
|             "" | ||||
|             "", | ||||
|         ] | ||||
|         for (const layer of themeFile.layers) { | ||||
|             const l = <LayerConfigJson>layer | ||||
|  | @ -604,8 +612,8 @@ class LayerOverviewUtils extends Script { | |||
| 
 | ||||
|             allCode.push( | ||||
|                 "   public metaTaggging_for_" + | ||||
|                 id + | ||||
|                 "(feat: Feature, helperFunctions: Record<ExtraFuncType, (feature: Feature) => Function>) {" | ||||
|                     id + | ||||
|                     "(feat: Feature, helperFunctions: Record<ExtraFuncType, (feature: Feature) => Function>) {" | ||||
|             ) | ||||
|             allCode.push("      const {" + ExtraFunctions.types.join(", ") + "} = helperFunctions") | ||||
|             for (const line of code) { | ||||
|  | @ -616,10 +624,10 @@ class LayerOverviewUtils extends Script { | |||
|                 if (!isStrict) { | ||||
|                     allCode.push( | ||||
|                         "      Utils.AddLazyProperty(feat.properties, '" + | ||||
|                         attributeName + | ||||
|                         "', () => " + | ||||
|                         expression + | ||||
|                         " ) " | ||||
|                             attributeName + | ||||
|                             "', () => " + | ||||
|                             expression + | ||||
|                             " ) " | ||||
|                     ) | ||||
|                 } else { | ||||
|                     attributeName = attributeName.substring(0, attributeName.length - 1).trim() | ||||
|  | @ -659,7 +667,7 @@ class LayerOverviewUtils extends Script { | |||
|             `/** This code is autogenerated - do not edit. Edit ./assets/layers/${l?.id}/${l?.id}.json instead */`, | ||||
|             "export class ThemeMetaTagging {", | ||||
|             "   public static readonly themeName = " + JSON.stringify(l.id), | ||||
|             "" | ||||
|             "", | ||||
|         ] | ||||
|         const code = l.calculatedTags ?? [] | ||||
| 
 | ||||
|  | @ -674,10 +682,10 @@ class LayerOverviewUtils extends Script { | |||
|             if (!isStrict) { | ||||
|                 allCode.push( | ||||
|                     "      Utils.AddLazyProperty(feat.properties, '" + | ||||
|                     attributeName + | ||||
|                     "', () => " + | ||||
|                     expression + | ||||
|                     " ) " | ||||
|                         attributeName + | ||||
|                         "', () => " + | ||||
|                         expression + | ||||
|                         " ) " | ||||
|                 ) | ||||
|             } else { | ||||
|                 attributeName = attributeName.substring(0, attributeName.length - 2).trim() | ||||
|  | @ -712,15 +720,13 @@ class LayerOverviewUtils extends Script { | |||
|             themeFiles.map((th) => th.parsed) | ||||
|         ) | ||||
| 
 | ||||
|         const trs = this.getSharedTagRenderings( | ||||
|             new DoesImageExist(licensePaths, existsSync) | ||||
|         ) | ||||
|         const trs = this.getSharedTagRenderings(new DoesImageExist(licensePaths, existsSync)) | ||||
| 
 | ||||
|         const convertState: DesugaringContext = { | ||||
|             sharedLayers, | ||||
|             tagRenderings: LayerOverviewUtils.asDict(trs), | ||||
|             tagRenderingOrder: trs.map(tr => tr.id), | ||||
|             publicLayers | ||||
|             tagRenderingOrder: trs.map((tr) => tr.id), | ||||
|             publicLayers, | ||||
|         } | ||||
|         const knownTagRenderings = new Set<string>() | ||||
|         convertState.tagRenderings.forEach((_, key) => knownTagRenderings.add(key)) | ||||
|  | @ -774,7 +780,7 @@ class LayerOverviewUtils extends Script { | |||
|             ) | ||||
|             try { | ||||
|                 themeFile = new PrepareTheme(convertState, { | ||||
|                     skipDefaultLayers: true | ||||
|                     skipDefaultLayers: true, | ||||
|                 }).convertStrict( | ||||
|                     themeFile, | ||||
|                     ConversionContext.construct([themePath], ["PrepareLayer"]) | ||||
|  | @ -808,7 +814,7 @@ class LayerOverviewUtils extends Script { | |||
|                                 const e: string = [ | ||||
|                                     `the icon for theme ${themeFile.id} is too small. Please rescale the icon at ${themeFile.icon}`, | ||||
|                                     `Even though an SVG is 'infinitely scaleable', the icon should be dimensioned bigger. One of the build steps of the theme does convert the image to a PNG (to serve as PWA-icon) and having a small dimension will cause blurry images.`, | ||||
|                                     ` Width = ${width} height = ${height}; we recommend a size of at least 500px * 500px and to use a square aspect ratio.` | ||||
|                                     ` Width = ${width} height = ${height}; we recommend a size of at least 500px * 500px and to use a square aspect ratio.`, | ||||
|                                 ].join("\n") | ||||
|                                 err(e) | ||||
|                             } | ||||
|  | @ -839,7 +845,7 @@ class LayerOverviewUtils extends Script { | |||
|                             new Translation(t.description) | ||||
|                                 .FirstSentence() | ||||
|                                 .OnEveryLanguage((s) => parse_html(s).textContent).translations, | ||||
|                         mustHaveLanguage: t.mustHaveLanguage?.length > 0 | ||||
|                         mustHaveLanguage: t.mustHaveLanguage?.length > 0, | ||||
|                     } | ||||
|                 }) | ||||
|             ) | ||||
|  | @ -847,10 +853,10 @@ class LayerOverviewUtils extends Script { | |||
| 
 | ||||
|         console.log( | ||||
|             "Recompiled themes " + | ||||
|             recompiledThemes.join(", ") + | ||||
|             " and skipped " + | ||||
|             skippedThemes.length + | ||||
|             " themes" | ||||
|                 recompiledThemes.join(", ") + | ||||
|                 " and skipped " + | ||||
|                 skippedThemes.length + | ||||
|                 " themes" | ||||
|         ) | ||||
| 
 | ||||
|         return fixed | ||||
|  |  | |||
|  | @ -249,7 +249,7 @@ class GenerateLayouts extends Script { | |||
|                 continue | ||||
|             } | ||||
|             let display = ' style="display: none"' | ||||
|             if(!defaultSet){ | ||||
|             if (!defaultSet) { | ||||
|                 display = "" | ||||
|                 defaultSet = true | ||||
|             } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue