forked from MapComplete/MapComplete
Refactoring: split 'Utils' into multiple files; fix some stray uppercase-method names
This commit is contained in:
parent
81be4db044
commit
3ec89826e4
97 changed files with 884 additions and 921 deletions
|
@ -103,13 +103,13 @@ class StatsDownloader {
|
|||
let page = 1
|
||||
let allFeatures: ChangeSetData[] = []
|
||||
const endDay = new Date(year, month - 1 /* Zero-indexed: 0 = january*/, day + 1)
|
||||
const endDate = `${endDay.getFullYear()}-${Utils.TwoDigits(
|
||||
const endDate = `${endDay.getFullYear()}-${Utils.twoDigits(
|
||||
endDay.getMonth() + 1
|
||||
)}-${Utils.TwoDigits(endDay.getDate())}`
|
||||
)}-${Utils.twoDigits(endDay.getDate())}`
|
||||
let url = this.urlTemplate
|
||||
.replace(
|
||||
"{start_date}",
|
||||
year + "-" + Utils.TwoDigits(month) + "-" + Utils.TwoDigits(day)
|
||||
year + "-" + Utils.twoDigits(month) + "-" + Utils.twoDigits(day)
|
||||
)
|
||||
.replace("{end_date}", endDate)
|
||||
.replace("{page}", "" + page)
|
||||
|
@ -142,7 +142,7 @@ class StatsDownloader {
|
|||
}
|
||||
url = result.next
|
||||
}
|
||||
allFeatures = Utils.NoNull(allFeatures)
|
||||
allFeatures = Lists.noNull(allFeatures)
|
||||
allFeatures.forEach((f) => {
|
||||
f.properties = { ...f.properties, ...f.properties.metadata }
|
||||
if (f.properties.editor.toLowerCase().indexOf("android") >= 0) {
|
||||
|
|
|
@ -9,6 +9,7 @@ import { existsSync, readFileSync, writeFileSync } from "fs"
|
|||
import WikidataUtils from "../src/Utils/WikidataUtils"
|
||||
import LanguageUtils from "../src/Utils/LanguageUtils"
|
||||
import Wikidata from "../src/Logic/Web/Wikidata"
|
||||
import { Lists } from "../src/Utils/Lists"
|
||||
|
||||
interface value<T> {
|
||||
value: T
|
||||
|
@ -196,7 +197,7 @@ async function main(wipeCache = false) {
|
|||
})
|
||||
|
||||
translatedForId["_meta"] = {
|
||||
countries: Utils.Dedup(languagesPerCountry[key]),
|
||||
countries: Lists.dedup(languagesPerCountry[key]),
|
||||
dir: value.directionality,
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ import Validators from "../src/UI/InputElement/Validators"
|
|||
import { AllKnownLayouts } from "../src/Customizations/AllKnownLayouts"
|
||||
import { AllSharedLayers } from "../src/Customizations/AllSharedLayers"
|
||||
import Constants from "../src/Models/Constants"
|
||||
import { Lists } from "../src/Utils/Lists"
|
||||
|
||||
const metainfo = {
|
||||
type: "One of the inputValidator types",
|
||||
|
@ -371,7 +372,7 @@ function extractMeta(
|
|||
const fullPath = "./src/assets/schemas/" + path + ".json"
|
||||
writeFileSync(fullPath, JSON.stringify(paths, null, " "))
|
||||
console.log("Written meta to " + fullPath)
|
||||
return Utils.NoNull(paths.map((p) => validateMeta(p)))
|
||||
return Lists.noNull(paths.map((p) => validateMeta(p)))
|
||||
}
|
||||
|
||||
function main() {
|
||||
|
|
|
@ -34,6 +34,7 @@ import { ImmutableStore } from "../src/Logic/UIEventSource"
|
|||
import * as unitUsage from "../Docs/Schemas/UnitConfigJson.schema.json"
|
||||
import { ThemeConfigJson } from "../src/Models/ThemeConfig/Json/ThemeConfigJson"
|
||||
import { ServerSourceInfo, SourceOverview } from "../src/Models/SourceOverview"
|
||||
import { Lists } from "../src/Utils/Lists"
|
||||
|
||||
/**
|
||||
* Converts a markdown-file into a .json file, which a walkthrough/slideshow element can use
|
||||
|
@ -562,7 +563,7 @@ export class GenerateDocs extends Script {
|
|||
)
|
||||
)
|
||||
const serverInfos = Utils.DedupOnId(serverInfosDupl, (item) => item.url)
|
||||
const titles = Utils.Dedup(Utils.NoEmpty(serverInfos.map((s) => s.category)))
|
||||
const titles = Lists.dedup(Lists.noEmpty(serverInfos.map((s) => s.category)))
|
||||
titles.sort()
|
||||
|
||||
function getHost(item: ServerSourceInfo) {
|
||||
|
@ -597,7 +598,7 @@ export class GenerateDocs extends Script {
|
|||
md.push(items.length + " items")
|
||||
md.push(categoryExplanation[title])
|
||||
|
||||
const hosts = Utils.Dedup(items.map(getHost))
|
||||
const hosts = Lists.dedup(items.map(getHost))
|
||||
hosts.sort()
|
||||
if (title === "maplayer") {
|
||||
md.push(MarkdownUtils.list(hosts))
|
||||
|
@ -636,7 +637,7 @@ export class GenerateDocs extends Script {
|
|||
return [
|
||||
item.url,
|
||||
identicalDescription ? "" : item.description,
|
||||
Utils.NoEmpty([
|
||||
Lists.noEmpty([
|
||||
item.openData ? "OpenData" : "",
|
||||
sourceAvailable,
|
||||
selfHostable,
|
||||
|
@ -720,9 +721,7 @@ export class GenerateDocs extends Script {
|
|||
MarkdownUtils.list(
|
||||
Constants.priviliged_layers.map((id) => "[" + id + "](#" + id + ")")
|
||||
),
|
||||
...Utils.NoNull(
|
||||
Constants.priviliged_layers.map((id) => AllSharedLayers.sharedLayers.get(id))
|
||||
).map((l) =>
|
||||
...Lists.noNull(Constants.priviliged_layers.map((id) => AllSharedLayers.sharedLayers.get(id))).map((l) =>
|
||||
l.generateDocumentation({
|
||||
usedInThemes: themesPerLayer.get(l.id),
|
||||
layerIsNeededBy: layerIsNeededBy,
|
||||
|
|
|
@ -13,6 +13,7 @@ import { TagUtils } from "../src/Logic/Tags/TagUtils"
|
|||
import { TagRenderingConfigJson } from "../src/Models/ThemeConfig/Json/TagRenderingConfigJson"
|
||||
import { Translatable } from "../src/Models/ThemeConfig/Json/Translatable"
|
||||
import * as questions from "../assets/layers/questions/questions.json"
|
||||
import { Lists } from "../src/Utils/Lists"
|
||||
|
||||
export class GenerateFavouritesLayer extends Script {
|
||||
private readonly layers: LayerConfigJson[] = []
|
||||
|
@ -155,7 +156,7 @@ export class GenerateFavouritesLayer extends Script {
|
|||
continue
|
||||
}
|
||||
newTr.condition = {
|
||||
and: Utils.NoNull([newTr.condition, layerConfig.source["osmTags"]]),
|
||||
and: Lists.noNull([newTr.condition, layerConfig.source["osmTags"]]),
|
||||
}
|
||||
generatedTagRenderings.push(newTr)
|
||||
blacklistedIds.add(newTr.id)
|
||||
|
|
|
@ -37,10 +37,8 @@ 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"
|
||||
import { Lists } from "../src/Utils/Lists"
|
||||
|
||||
// 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
|
||||
|
@ -126,20 +124,18 @@ class AddIconSummary extends DesugaringStep<{ raw: LayerConfigJson; parsed: Laye
|
|||
pr.location.has("point")
|
||||
)
|
||||
const defaultTags = layerConfig.baseTags
|
||||
fixed["_layerIcon"] = Utils.NoNull(
|
||||
(pointRendering?.marker ?? []).map((i) => {
|
||||
const icon = i.icon?.GetRenderValue(defaultTags)?.txt
|
||||
if (!icon) {
|
||||
return undefined
|
||||
}
|
||||
const result = { icon }
|
||||
const c = i.color?.GetRenderValue(defaultTags)?.txt
|
||||
if (c) {
|
||||
result["color"] = c
|
||||
}
|
||||
return result
|
||||
})
|
||||
)
|
||||
fixed["_layerIcon"] = Lists.noNull((pointRendering?.marker ?? []).map((i) => {
|
||||
const icon = i.icon?.GetRenderValue(defaultTags)?.txt
|
||||
if (!icon) {
|
||||
return undefined
|
||||
}
|
||||
const result = { icon }
|
||||
const c = i.color?.GetRenderValue(defaultTags)?.txt
|
||||
if (c) {
|
||||
result["color"] = c
|
||||
}
|
||||
return result
|
||||
}))
|
||||
return { raw: fixed, parsed: layerConfig }
|
||||
}
|
||||
}
|
||||
|
@ -233,7 +229,7 @@ class LayerBuilder extends Conversion<object, Map<string, LayerConfigJson>> {
|
|||
const origIds: ReadonlyArray<string> = [...ids]
|
||||
|
||||
const deps = this._dependencies
|
||||
const allDeps = Utils.Dedup([].concat(...ids.map((id) => deps.get(id))))
|
||||
const allDeps = Lists.dedup([].concat(...ids.map((id) => deps.get(id))))
|
||||
const depsRecord = Utils.asRecord(Array.from(deps.keys()), (k) =>
|
||||
deps.get(k).filter((dep) => ids.indexOf(dep) >= 0)
|
||||
)
|
||||
|
@ -864,7 +860,7 @@ class LayerOverviewUtils extends Script {
|
|||
)
|
||||
}
|
||||
if(printAssets){
|
||||
const images = Utils.Dedup(Array.from(sharedThemes.values()).flatMap(th => th._usedImages ?? [] ))
|
||||
const images = Lists.dedup(Array.from(sharedThemes.values()).flatMap(th => th._usedImages ?? []))
|
||||
writeFileSync("needed_assets.csv", images.join("\n"))
|
||||
console.log("Written needed_assets.csv")
|
||||
}
|
||||
|
@ -1278,11 +1274,9 @@ class LayerOverviewUtils extends Script {
|
|||
}
|
||||
}
|
||||
|
||||
const usedImages = Utils.Dedup(
|
||||
new ExtractImages(true, knownTagRenderings)
|
||||
.convertStrict(themeFile)
|
||||
.map((x) => x.path)
|
||||
)
|
||||
const usedImages = Lists.dedup(new ExtractImages(true, knownTagRenderings)
|
||||
.convertStrict(themeFile)
|
||||
.map((x) => x.path))
|
||||
usedImages.sort()
|
||||
|
||||
themeFile["_usedImages"] = usedImages
|
||||
|
|
|
@ -3,6 +3,7 @@ import SmallLicense from "../src/Models/smallLicense"
|
|||
import ScriptUtils from "./ScriptUtils"
|
||||
import Script from "./Script"
|
||||
import { Utils } from "../src/Utils"
|
||||
import { Lists } from "../src/Utils/Lists"
|
||||
|
||||
const prompt = require("prompt-sync")()
|
||||
|
||||
|
@ -297,9 +298,7 @@ export class GenerateLicenseInfo extends Script {
|
|||
sources: license.sources,
|
||||
}
|
||||
|
||||
cloned.license = Utils.Dedup(
|
||||
cloned.license.split(";").map((l) => this.toSPDXCompliantLicense(l))
|
||||
).join("; ")
|
||||
cloned.license = Lists.dedup(cloned.license.split(";").map((l) => this.toSPDXCompliantLicense(l))).join("; ")
|
||||
if (cloned.license === "CC0-1.0; TRIVIAL") {
|
||||
cloned.license = "TRIVIAL"
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import Script from "./Script"
|
|||
import NameSuggestionIndex from "../src/Logic/Web/NameSuggestionIndex"
|
||||
import TagInfo from "../src/Logic/Web/TagInfo"
|
||||
import { TagsFilter } from "../src/Logic/Tags/TagsFilter"
|
||||
import { Lists } from "../src/Utils/Lists"
|
||||
|
||||
class GenerateNsiStats extends Script {
|
||||
async createOptimizationFile(includeTags = true) {
|
||||
|
@ -139,9 +140,7 @@ class GenerateNsiStats extends Script {
|
|||
)
|
||||
}
|
||||
const nsi = await NameSuggestionIndex.singleton()
|
||||
const allBrandNames: string[] = Utils.Dedup(
|
||||
nsi.allPossible(<any>type).map((item) => item.tags[type])
|
||||
)
|
||||
const allBrandNames: string[] = Lists.dedup(nsi.allPossible(<any>type).map((item) => item.tags[type]))
|
||||
const batchSize = 50
|
||||
for (let i = 0; i < allBrandNames.length; i += batchSize) {
|
||||
console.warn(
|
||||
|
@ -152,7 +151,7 @@ class GenerateNsiStats extends Script {
|
|||
)
|
||||
let downloaded = 0
|
||||
await Promise.all(
|
||||
Utils.TimesT(batchSize, async (j) => {
|
||||
Utils.timesT(batchSize, async (j) => {
|
||||
const brand = allBrandNames[i + j]
|
||||
if (!allBrands[brand]) {
|
||||
allBrands[brand] = {}
|
||||
|
|
|
@ -5,6 +5,7 @@ import { readFileSync, writeFileSync } from "fs"
|
|||
import ThemeConfig from "../src/Models/ThemeConfig/ThemeConfig"
|
||||
import LayerConfig from "../src/Models/ThemeConfig/LayerConfig"
|
||||
import { Utils } from "../src/Utils"
|
||||
import { Lists } from "../src/Utils/Lists"
|
||||
|
||||
/**
|
||||
* Generates all the files in "Docs/TagInfo". These are picked up by the taginfo project, showing a link to the mapcomplete theme if the key is used
|
||||
|
@ -269,7 +270,7 @@ function main() {
|
|||
}
|
||||
files.push(generateTagInfoEntry(layout))
|
||||
}
|
||||
generateProjectsOverview(Utils.NoNull(files))
|
||||
generateProjectsOverview(Lists.noNull(files))
|
||||
}
|
||||
|
||||
main()
|
||||
|
|
|
@ -4,6 +4,7 @@ import { Utils } from "../src/Utils"
|
|||
import ScriptUtils from "./ScriptUtils"
|
||||
import Script from "./Script"
|
||||
import Constants from "../src/Models/Constants"
|
||||
import { Lists } from "../src/Utils/Lists"
|
||||
|
||||
const knownLanguages = ["en", "nl", "de", "fr", "es", "gl", "ca"]
|
||||
const ignoreTerms = ["searchTerms"]
|
||||
|
@ -172,7 +173,7 @@ class TranslationPart {
|
|||
languages.push(...(value as TranslationPart).knownLanguages())
|
||||
}
|
||||
}
|
||||
return Utils.Dedup(languages)
|
||||
return Lists.dedup(languages)
|
||||
}
|
||||
|
||||
toJson(neededLanguage?: string): string {
|
||||
|
@ -351,7 +352,7 @@ function transformTranslation(
|
|||
}
|
||||
|
||||
const values: string[] = []
|
||||
const spaces = Utils.Times((_) => " ", path.length + 1)
|
||||
const spaces = Utils.times((_) => " ", path.length + 1)
|
||||
|
||||
for (const key in obj) {
|
||||
if (key === "#") {
|
||||
|
@ -381,7 +382,7 @@ function transformTranslation(
|
|||
let expr = `new Translation(${JSON.stringify(value)}, "core:${path.join(".")}.${key}")`
|
||||
if (subParts !== null) {
|
||||
// convert '{to_substitute}' into 'to_substitute'
|
||||
const types = Utils.Dedup(subParts.map((tp) => tp.substring(1, tp.length - 1)))
|
||||
const types = Lists.dedup(subParts.map((tp) => tp.substring(1, tp.length - 1)))
|
||||
const invalid = types.filter(
|
||||
(part) => part.match(/^[a-z0-9A-Z_]+(\(.*\))?$/) == null
|
||||
)
|
||||
|
@ -764,7 +765,7 @@ class GenerateTranslations extends Script {
|
|||
"themes"
|
||||
)
|
||||
|
||||
const usedLanguages: string[] = Utils.Dedup(l1.concat(l2)).filter((v) => v !== "*")
|
||||
const usedLanguages: string[] = Lists.dedup(l1.concat(l2)).filter((v) => v !== "*")
|
||||
usedLanguages.sort()
|
||||
fs.writeFileSync(
|
||||
"./src/assets/used_languages.json",
|
||||
|
|
|
@ -128,7 +128,7 @@ class NsiLogos extends Script {
|
|||
}
|
||||
|
||||
const results = await Promise.all(
|
||||
Utils.TimesT(stepcount, (j) => j).map(async (j) => {
|
||||
Utils.timesT(stepcount, (j) => j).map(async (j) => {
|
||||
return await this.downloadLogo(items[i + j], type, basePath, alreadyDownloaded)
|
||||
})
|
||||
)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import Script from "../Script"
|
||||
import { readFileSync, writeFileSync } from "fs"
|
||||
import { OsmId } from "../../src/Models/OsmFeature"
|
||||
import { Utils } from "../../src/Utils"
|
||||
import { Lists } from "../../src/Utils/Lists"
|
||||
|
||||
interface DiffItem {
|
||||
/**
|
||||
|
@ -34,7 +34,7 @@ export class DiffToCsv extends Script {
|
|||
JSON.parse(readFileSync(file, "utf8"))
|
||||
)
|
||||
const diffs = json.diffs
|
||||
const allKeys = Utils.Dedup(diffs.flatMap((item) => item.diffs.map((d) => d.key)))
|
||||
const allKeys = Lists.dedup(diffs.flatMap((item) => item.diffs.map((d) => d.key)))
|
||||
allKeys.sort()
|
||||
|
||||
const header = [
|
||||
|
|
|
@ -74,7 +74,7 @@ class VeloParkToGeojson extends Script {
|
|||
const batchSize = 50
|
||||
for (let i = 0; i < allVeloparkRaw.length; i += batchSize) {
|
||||
await Promise.all(
|
||||
Utils.TimesT(batchSize, (j) => j).map(async (j) => {
|
||||
Utils.timesT(batchSize, (j) => j).map(async (j) => {
|
||||
const f = allVeloparkRaw[i + j]
|
||||
if (!f) {
|
||||
return
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue