Add binoculars theme, auto reformat everything

This commit is contained in:
Pieter Vander Vennet 2021-09-09 00:05:51 +02:00
parent 38dea806c5
commit 78d6482c88
586 changed files with 115573 additions and 111842 deletions

View file

@ -1,21 +1,22 @@
import ScriptUtils from "./ScriptUtils";
ScriptUtils.fixUtils()
import {appendFileSync, readFileSync, writeFileSync} from "fs";
import {OsmObject} from "../Logic/Osm/OsmObject";
ScriptUtils.fixUtils()
ScriptUtils.erasableLog("Fixing the cycle highways...")
writeFileSync("cycleHighwayFix.osc","<osmChange version=\"0.6\" generator=\"Handmade\" copyright=\"OpenStreetMap and Contributors\"\n" +
writeFileSync("cycleHighwayFix.osc", "<osmChange version=\"0.6\" generator=\"Handmade\" copyright=\"OpenStreetMap and Contributors\"\n" +
" attribution=\"http://www.openstreetmap.org/copyright\" license=\"http://opendatacommons.org/licenses/odbl/1-0/\">\n" +
" <modify>", "utf8")
const ids = JSON.parse(readFileSync("export.geojson","utf-8")).features.map(f => f.properties["@id"])
const ids = JSON.parse(readFileSync("export.geojson", "utf-8")).features.map(f => f.properties["@id"])
console.log(ids)
ids.map(id => OsmObject.DownloadReferencingRelations(id).addCallbackAndRunD(relations => {
console.log(relations)
const changeparts = relations.filter(relation => relation.tags["cycle_highway"] == "yes" && relation.tags["note:state"] == undefined)
.map(relation => {
relation.tags["note:state"]="has_highway_under_construction";
return relation.ChangesetXML(undefined)
relation.tags["note:state"] = "has_highway_under_construction";
return relation.ChangesetXML(undefined)
})
appendFileSync("cycleHighwayFix.osc", changeparts.join("\n"), "utf8")
appendFileSync("cycleHighwayFix.osc", changeparts.join("\n"), "utf8")
return true;
}))

View file

@ -1,13 +1,13 @@
import * as fs from "fs";
import {lstatSync, readdirSync, readFileSync} from "fs";
import {Utils} from "../Utils";
Utils.runningFromConsole = true
import * as https from "https";
import * as fs from "fs";
import {LayoutConfigJson} from "../Models/ThemeConfig/Json/LayoutConfigJson";
import {LayerConfigJson} from "../Models/ThemeConfig/Json/LayerConfigJson";
export default class ScriptUtils {

View file

@ -3,7 +3,6 @@
*/
import {Utils} from "../Utils"
Utils.runningFromConsole = true;
import {readFileSync, writeFileSync} from "fs";
import SmallLicense from "../Models/smallLicense";
import AllKnownLayers from "../Customizations/AllKnownLayers";
@ -13,9 +12,10 @@ import {LayoutConfigJson} from "../Models/ThemeConfig/Json/LayoutConfigJson";
import LayerConfig from "../Models/ThemeConfig/LayerConfig";
ScriptUtils.fixUtils()
if(process.argv.length == 2){
if (process.argv.length == 2) {
console.log("USAGE: ts-node scripts/fixTheme <path to theme>")
throw "No path specified"
}
@ -25,33 +25,33 @@ const dir = path.substring(0, path.lastIndexOf("/"))
console.log("Fixing up ", path)
const themeConfigJson : LayoutConfigJson = JSON.parse(readFileSync(path, "UTF8"))
const themeConfigJson: LayoutConfigJson = JSON.parse(readFileSync(path, "UTF8"))
const licenses : SmallLicense[] = []
const licenses: SmallLicense[] = []
const replacements: {source: string, destination: string}[] = []
const replacements: { source: string, destination: string }[] = []
for (const layerConfigJson of themeConfigJson.layers) {
if(typeof (layerConfigJson) === "string"){
if (typeof (layerConfigJson) === "string") {
continue;
}
if(layerConfigJson["overpassTags"] !== undefined){
if (layerConfigJson["overpassTags"] !== undefined) {
const tags = layerConfigJson["overpassTags"];
layerConfigJson["overpassTags"] = undefined;
layerConfigJson["source"] = { osmTags : tags}
layerConfigJson["source"] = {osmTags: tags}
}
// @ts-ignore
const layerConfig = new LayerConfig(layerConfigJson, AllKnownLayers.sharedUnits, "fix theme",true)
const images : string[] = Array.from(layerConfig.ExtractImages())
const layerConfig = new LayerConfig(layerConfigJson, AllKnownLayers.sharedUnits, "fix theme", true)
const images: string[] = Array.from(layerConfig.ExtractImages())
const remoteImages = images.filter(img => img.startsWith("http"))
for (const remoteImage of remoteImages) {
const filename = remoteImage.substring(remoteImage.lastIndexOf("/"))
ScriptUtils.DownloadFileTo(remoteImage, dir + "/" + filename)
const imgPath = remoteImage.substring(remoteImage.lastIndexOf("/") + 1)
for (const attributionSrc of AllImageProviders.ImageAttributionSource) {
@ -61,26 +61,26 @@ for (const layerConfigJson of themeConfigJson.layers) {
licenses.push({
path: imgPath,
license: license?.license ?? "",
authors:Utils.NoNull([license?.artist]),
authors: Utils.NoNull([license?.artist]),
sources: [remoteImage]
})
})
}catch(e){
} catch (e) {
// Hush hush
}
}
replacements.push({source: remoteImage, destination: `${dir}/${imgPath}`})
}
}
let fixedThemeJson = JSON.stringify(themeConfigJson, null , " ")
let fixedThemeJson = JSON.stringify(themeConfigJson, null, " ")
for (const replacement of replacements) {
fixedThemeJson = fixedThemeJson.replace(new RegExp(replacement.source, "g"), replacement.destination)
}
writeFileSync(dir + "/generated.license_info.json", JSON.stringify(licenses, null, " "))
writeFileSync(path+".autofixed.json", fixedThemeJson)
writeFileSync(path + ".autofixed.json", fixedThemeJson)
console.log(`IMPORTANT:
1) Copy generated.license_info.json over into license_info.json and add the missing attributions and authors

View file

@ -2,9 +2,8 @@
* Generates a collection of geojson files based on an overpass query for a given theme
*/
import {Utils} from "../Utils";
Utils.runningFromConsole = true
import {Overpass} from "../Logic/Osm/Overpass";
import * as fs from "fs";
import {existsSync, readFileSync, writeFileSync} from "fs";
import {TagsFilter} from "../Logic/Tags/TagsFilter";
import {Or} from "../Logic/Tags/Or";
@ -15,11 +14,12 @@ import * as OsmToGeoJson from "osmtogeojson";
import MetaTagging from "../Logic/MetaTagging";
import {GeoOperations} from "../Logic/GeoOperations";
import {UIEventSource} from "../Logic/UIEventSource";
import * as fs from "fs";
import {TileRange} from "../Models/TileRange";
import LayoutConfig from "../Models/ThemeConfig/LayoutConfig";
import LayerConfig from "../Models/ThemeConfig/LayerConfig";
Utils.runningFromConsole = true
function createOverpassObject(theme: LayoutConfig) {
let filters: TagsFilter[] = [];
@ -256,8 +256,8 @@ function splitPerLayer(targetdir: string, r: TileRange, theme: LayoutConfig) {
for (const layer of theme.layers) {
const id = layer.id
const loaded = generated[id]
if(loaded === undefined){
console.log("No features loaded for layer ",id)
if (loaded === undefined) {
console.log("No features loaded for layer ", id)
continue;
}
writeFileSync(targetdir + "_" + id + "_overview.json", JSON.stringify(loaded))
@ -275,9 +275,9 @@ async function createOverview(targetdir: string, r: TileRange, z: number, layern
}
const features = JSON.parse(fs.readFileSync(read_path, "UTF-8")).features
const pointsOnly = features.map(f => {
f.properties["_last_edit:timestamp"] = "1970-01-01"
if (f.geometry.type === "Point") {
return f
} else {
@ -293,13 +293,13 @@ async function createOverview(targetdir: string, r: TileRange, z: number, layern
const seen = new Set<string>()
for (const feature of allFeatures) {
const id = feature.properties.id
if(seen.has(id)){
if (seen.has(id)) {
continue
}
seen.add(id)
featuresDedup.push(feature)
}
const geojson = {
"type": "FeatureCollection",
"features": featuresDedup

View file

@ -1,5 +1,4 @@
import {Utils} from "../Utils";
Utils.runningFromConsole = true;
import SpecialVisualizations from "../UI/SpecialVisualizations";
import SimpleMetaTagger from "../Logic/SimpleMetaTagger";
import Combine from "../UI/Base/Combine";
@ -12,18 +11,19 @@ import State from "../State";
import {QueryParameters} from "../Logic/Web/QueryParameters";
import LayoutConfig from "../Models/ThemeConfig/LayoutConfig";
Utils.runningFromConsole = true;
function WriteFile(filename, html: string | BaseUIElement, autogenSource: string[]): void {
writeFileSync(filename, new Combine([Translations.W(html),
"Generated from "+autogenSource.join(", ")
"Generated from " + autogenSource.join(", ")
]).AsMarkdown());
}
WriteFile("./Docs/SpecialRenderings.md", SpecialVisualizations.HelpMessage, ["UI/SpecialVisualisations.ts"])
WriteFile("./Docs/CalculatedTags.md", new Combine([SimpleMetaTagger.HelpText(), ExtraFunction.HelpText()]).SetClass("flex-col"),
["SimpleMetaTagger","ExtraFunction"])
WriteFile("./Docs/SpecialInputElements.md", ValidatedTextField.HelpText(),["ValidatedTextField.ts"]);
["SimpleMetaTagger", "ExtraFunction"])
WriteFile("./Docs/SpecialInputElements.md", ValidatedTextField.HelpText(), ["ValidatedTextField.ts"]);
new State(new LayoutConfig({

View file

@ -9,17 +9,17 @@ function genImages() {
const allNames: string[] = [];
for (const path of dir) {
if(path.endsWith("license_info.json")){
if (path.endsWith("license_info.json")) {
continue;
}
if (!path.endsWith(".svg")) {
throw "Non-svg file detected in the svg files: " + path;
}
const svg = fs.readFileSync("./assets/svg/" + path, "utf-8")
.replace(/<\?xml.*?>/, "")
.replace(/fill: ?none;/g,"fill: none !important;") // This is such a brittle hack...
.replace(/fill: ?none;/g, "fill: none !important;") // This is such a brittle hack...
.replace(/\n/g, " ")
.replace(/\r/g, "")
.replace(/\\/g, "\\")
@ -37,4 +37,5 @@ function genImages() {
fs.writeFileSync("Svg.ts", module);
console.log("Done")
}
genImages()

View file

@ -1,7 +1,5 @@
// We HAVE to mark this while importing
import {Utils} from "../Utils";
Utils.runningFromConsole = true;
import {existsSync, mkdirSync, readFileSync, writeFile, writeFileSync} from "fs";
import Locale from "../UI/i18n/Locale";
import Translations from "../UI/i18n/Translations";
@ -10,6 +8,9 @@ import Constants from "../Models/Constants";
import * as all_known_layouts from "../assets/generated/known_layers_and_themes.json"
import {LayoutConfigJson} from "../Models/ThemeConfig/Json/LayoutConfigJson";
import LayoutConfig from "../Models/ThemeConfig/LayoutConfig";
Utils.runningFromConsole = true;
const sharp = require('sharp');
@ -57,7 +58,7 @@ async function createManifest(layout: LayoutConfig) {
Translation.forcedLanguage = "en"
const icons = [];
let icon = layout.icon;
if (icon.endsWith(".svg") || icon.startsWith("<svg") || icon.startsWith("<?xml")) {
@ -84,14 +85,13 @@ async function createManifest(layout: LayoutConfig) {
sizes: "513x513",
type: "image/svg"
})
} else if (icon.endsWith(".png")){
} else if (icon.endsWith(".png")) {
icons.push({
src: icon,
sizes: "513x513",
type: "image/png"
})
}
else {
} else {
console.log(icon)
throw "Icon is not an svg for " + layout.id
}
@ -142,15 +142,15 @@ async function createLandingPage(layout: LayoutConfig, manifest) {
icon = `./assets/generated/${layout.id}_icon.svg`
writeFileSync(icon, layout.icon);
}
const apple_icons = []
for (const icon of manifest.icons) {
if(icon.type !== "image/png"){
if (icon.type !== "image/png") {
continue;
}
apple_icons.push(`<link rel="apple-touch-icon" sizes="${icon.sizes}" href="${icon.src}">`)
}
let themeSpecific = [
`<title>${ogTitle}</title>`,
`<link rel="manifest" href="${enc(layout.id)}.webmanifest">`,
@ -183,9 +183,9 @@ if (!existsSync(generatedDir)) {
const blacklist = ["", "test", ".", "..", "manifest", "index", "land", "preferences", "account", "openstreetmap", "custom"]
// @ts-ignore
const all : LayoutConfigJson[] = all_known_layouts.themes;
const all: LayoutConfigJson[] = all_known_layouts.themes;
for (const i in all) {
const layoutConfigJson : LayoutConfigJson = all[i]
const layoutConfigJson: LayoutConfigJson = all[i]
const layout = new LayoutConfig(layoutConfigJson, true, "generating layouts")
const layoutName = layout.id
if (blacklist.indexOf(layoutName.toLowerCase()) >= 0) {
@ -201,13 +201,13 @@ for (const i in all) {
const manif = JSON.stringify(manifObj, undefined, 2);
const manifestLocation = encodeURIComponent(layout.id.toLowerCase()) + ".webmanifest";
writeFile(manifestLocation, manif, err);
// Create a landing page for the given theme
createLandingPage(layout, manifObj).then(landing => {
writeFile(enc(layout.id) + ".html", landing, err)
});
}).catch(e => console.log("Could not generate the manifest: ", e))
}
createManifest(new LayoutConfig({
@ -219,9 +219,9 @@ createManifest(new LayoutConfig({
startLat: 0,
startLon: 0,
startZoom: 0,
title: {en:"MapComplete"},
title: {en: "MapComplete"},
version: Constants.vNumber,
description: {en:"A thematic map viewer and editor based on OpenStreetMap"}
description: {en: "A thematic map viewer and editor based on OpenStreetMap"}
})).then(manifObj => {
const manif = JSON.stringify(manifObj, undefined, 2);
writeFileSync("index.manifest", manif)

View file

@ -1,5 +1,5 @@
import {Utils} from "../Utils";
import {lstatSync, readdirSync, readFileSync, writeFileSync, unlinkSync, existsSync, mkdir, mkdirSync} from "fs";
import {existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync} from "fs";
import SmallLicense from "../Models/smallLicense";
import ScriptUtils from "./ScriptUtils";
@ -143,7 +143,7 @@ function cleanLicenseInfo(allPaths: string[], allLicenseInfos: SmallLicense[]) {
if (!perDirectory.has(dir)) {
perDirectory.set(dir, [])
}
const cloned : SmallLicense = {
const cloned: SmallLicense = {
// We make a clone to force the order of the keys
path: license.path,
license: license.license,

View file

@ -1,6 +1,4 @@
import {Utils} from "../Utils";
Utils.runningFromConsole = true;
import {AllKnownLayouts} from "../Customizations/AllKnownLayouts";
import Locale from "../UI/i18n/Locale";
import {Translation} from "../UI/i18n/Translation";
@ -8,13 +6,15 @@ import {readFileSync, writeFileSync} from "fs";
import LayoutConfig from "../Models/ThemeConfig/LayoutConfig";
import LayerConfig from "../Models/ThemeConfig/LayerConfig";
Utils.runningFromConsole = true;
/**
* 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
*/
const outputDirectory = "Docs/TagInfo"
function generateTagOverview(kv: { k: string, v: string }, description: string) : {
function generateTagOverview(kv: { k: string, v: string }, description: string): {
key: string,
description: string,
value?: string
@ -23,7 +23,7 @@ function generateTagOverview(kv: { k: string, v: string }, description: string)
// OSM tag key (required)
key: kv.k,
description: description,
value : undefined
value: undefined
};
if (kv.v !== undefined) {
// OSM tag value (optional, if not supplied it means "all values")
@ -34,12 +34,12 @@ function generateTagOverview(kv: { k: string, v: string }, description: string)
function generateLayerUsage(layer: LayerConfig, layout: LayoutConfig): any [] {
if(layer.name === undefined){
if (layer.name === undefined) {
return [] // Probably a duplicate or irrelevant layer
}
const usedTags = layer.source.osmTags.asChange({})
const result : {
const result: {
key: string,
description: string,
value?: string
@ -101,7 +101,7 @@ function generateLayerUsage(layer: LayerConfig, layout: LayoutConfig): any [] {
}
}
return result.filter(result => !result.key.startsWith("_"))
}
@ -173,7 +173,6 @@ function generateProjectsOverview() {
}
console.log("Creating taginfo project files")
Locale.language.setData("en")

View file

@ -2,7 +2,6 @@ import * as fs from "fs";
import {readFileSync, writeFileSync} from "fs";
import {Utils} from "../Utils";
import ScriptUtils from "./ScriptUtils";
import {Layer} from "leaflet";
const knownLanguages = ["en", "nl", "de", "fr", "es", "gl", "ca"];
@ -213,7 +212,7 @@ function generateTranslationsObjectFrom(objects: { path: string, parsed: { id: s
}
function MergeTranslation(source: any, target: any, language: string, context: string = "") {
for (const key in source) {
if (!source.hasOwnProperty(key)) {
continue
@ -221,14 +220,14 @@ function MergeTranslation(source: any, target: any, language: string, context: s
const sourceV = source[key];
const targetV = target[key]
if (typeof sourceV === "string") {
if(targetV === undefined){
if(typeof target === "string"){
throw "Trying to merge a translation into a fixed string at "+context+" for key "+key;
if (targetV === undefined) {
if (typeof target === "string") {
throw "Trying to merge a translation into a fixed string at " + context + " for key " + key;
}
target[key] = source[key];
continue;
}
if (targetV[language] === sourceV) {
// Already the same
continue;
@ -264,7 +263,7 @@ function mergeLayerTranslation(layerConfig: { id: string }, path: string, transl
const id = layerConfig.id;
translationFiles.forEach((translations, lang) => {
const translationsForLayer = translations[id]
MergeTranslation(translationsForLayer, layerConfig, lang, path+":"+id)
MergeTranslation(translationsForLayer, layerConfig, lang, path + ":" + id)
})
}

View file

@ -1,10 +1,11 @@
import {Utils} from "../Utils";
Utils.runningFromConsole = true;
import {writeFile} from "fs";
import Translations from "../UI/i18n/Translations";
import {AllKnownLayouts} from "../Customizations/AllKnownLayouts";
import LayoutConfig from "../Models/ThemeConfig/LayoutConfig";
Utils.runningFromConsole = true;
function generateWikiEntry(layout: LayoutConfig) {
if (layout.hideFromOverview) {
@ -29,12 +30,13 @@ function generateWikiEntry(layout: LayoutConfig) {
|genre= POI, editor, ${layout.id}
}}`
}
let wikiPage = "{|class=\"wikitable sortable\"\n" +
"! Name, link !! Genre !! Covered region !! Language !! Description !! Free materials !! Image\n" +
"|-";
for (const layout of AllKnownLayouts.layoutsList) {
if(layout.hideFromOverview){
if (layout.hideFromOverview) {
continue;
}
wikiPage += "\n" + generateWikiEntry(layout);

View file

@ -1,5 +1,6 @@
import {Utils} from "../Utils";
Utils.runningFromConsole = true;
import Constants from "../Models/Constants";
console.log("git tag -a", Constants.vNumber,`-m "Deployed on ${new Date()}"`)
Utils.runningFromConsole = true;
console.log("git tag -a", Constants.vNumber, `-m "Deployed on ${new Date()}"`)