From 278fce87261ae5520b4f89055312bdd9e4043d47 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Sun, 6 Feb 2022 01:57:33 +0100 Subject: [PATCH] Fix #640: generate an icon with a white background automatically --- .../bike_repair_station.json | 3 - index.manifest | 20 +-- scripts/generateLayouts.ts | 143 ++++++++++-------- test.ts | 20 ++- 4 files changed, 103 insertions(+), 83 deletions(-) diff --git a/assets/layers/bike_repair_station/bike_repair_station.json b/assets/layers/bike_repair_station/bike_repair_station.json index 2083cc9cb..458ef2354 100644 --- a/assets/layers/bike_repair_station/bike_repair_station.json +++ b/assets/layers/bike_repair_station/bike_repair_station.json @@ -277,8 +277,6 @@ ], "id": "bike_repair_station-opening_hours" }, - - { "question": { "en": "Who maintains this cycle pump?", @@ -331,7 +329,6 @@ "render": "{phone}", "id": "bike_repair_station-phone" }, - { "id": "bike_repair_station-bike-chain-tool", "question": { diff --git a/index.manifest b/index.manifest index f6d40e4c5..53b295e9e 100644 --- a/index.manifest +++ b/index.manifest @@ -9,52 +9,52 @@ "orientation": "portrait-primary, landscape-primary", "icons": [ { - "src": "assets/generated/svg_mapcomplete_logo72.png", + "src": "./assets/generated/svg_mapcomplete_logo72.png", "sizes": "72x72", "type": "image/png" }, { - "src": "assets/generated/svg_mapcomplete_logo96.png", + "src": "./assets/generated/svg_mapcomplete_logo96.png", "sizes": "96x96", "type": "image/png" }, { - "src": "assets/generated/svg_mapcomplete_logo120.png", + "src": "./assets/generated/svg_mapcomplete_logo120.png", "sizes": "120x120", "type": "image/png" }, { - "src": "assets/generated/svg_mapcomplete_logo128.png", + "src": "./assets/generated/svg_mapcomplete_logo128.png", "sizes": "128x128", "type": "image/png" }, { - "src": "assets/generated/svg_mapcomplete_logo144.png", + "src": "./assets/generated/svg_mapcomplete_logo144.png", "sizes": "144x144", "type": "image/png" }, { - "src": "assets/generated/svg_mapcomplete_logo152.png", + "src": "./assets/generated/svg_mapcomplete_logo152.png", "sizes": "152x152", "type": "image/png" }, { - "src": "assets/generated/svg_mapcomplete_logo180.png", + "src": "./assets/generated/svg_mapcomplete_logo180.png", "sizes": "180x180", "type": "image/png" }, { - "src": "assets/generated/svg_mapcomplete_logo192.png", + "src": "./assets/generated/svg_mapcomplete_logo192.png", "sizes": "192x192", "type": "image/png" }, { - "src": "assets/generated/svg_mapcomplete_logo384.png", + "src": "./assets/generated/svg_mapcomplete_logo384.png", "sizes": "384x384", "type": "image/png" }, { - "src": "assets/generated/svg_mapcomplete_logo512.png", + "src": "./assets/generated/svg_mapcomplete_logo512.png", "sizes": "512x512", "type": "image/png" }, diff --git a/scripts/generateLayouts.ts b/scripts/generateLayouts.ts index fcffe56a2..b3564d82b 100644 --- a/scripts/generateLayouts.ts +++ b/scripts/generateLayouts.ts @@ -7,7 +7,6 @@ import * as all_known_layouts from "../assets/generated/known_layers_and_themes. import {LayoutConfigJson} from "../Models/ThemeConfig/Json/LayoutConfigJson"; import LayoutConfig from "../Models/ThemeConfig/LayoutConfig"; import xml2js from 'xml2js'; -import {exec} from "child_process"; const sharp = require('sharp'); const template = readFileSync("theme.html", "utf8"); @@ -18,9 +17,7 @@ function enc(str: string): string { return encodeURIComponent(str.toLowerCase()); } -const alreadyWritten = [] - -async function createIcon(iconPath: string, size: number) { +async function createIcon(iconPath: string, size: number, alreadyWritten: string[]) { let name = iconPath.split(".").slice(0, -1).join("."); if (name.startsWith("./")) { name = name.substr(2) @@ -53,7 +50,7 @@ async function createIcon(iconPath: string, size: number) { return newname; } -async function createManifest(layout: LayoutConfig) { +async function createManifest(layout: LayoutConfig, alreadyWritten: string[]) { const name = layout.id; Translation.forcedLanguage = "en" @@ -64,6 +61,7 @@ async function createManifest(layout: LayoutConfig) { if (icon.endsWith(".svg") || icon.startsWith("`) + apple_icons.push(``) } let themeSpecific = [ @@ -211,65 +213,78 @@ async function createIndexFor(theme: LayoutConfig) { appendFileSync(filename, codeTemplate) } -const generatedDir = "./assets/generated"; -if (!existsSync(generatedDir)) { - mkdirSync(generatedDir) +function createDir(path){ + if (!existsSync(path)) { + mkdirSync(path) + } } -const blacklist = ["", "test", ".", "..", "manifest", "index", "land", "preferences", "account", "openstreetmap", "custom", "theme"] -// @ts-ignore -const all: LayoutConfigJson[] = 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] - if(theme !== undefined && layoutConfigJson.id !== theme){ - continue +async function main(): Promise{ + + + const alreadyWritten = [] + createDir("./assets/generated") + createDir("./assets/generated/layers") + createDir("./assets/generated/themes") + createDir("./assets/generated/white_background") + + const blacklist = ["", "test", ".", "..", "manifest", "index", "land", "preferences", "account", "openstreetmap", "custom", "theme"] + // @ts-ignore + const all: LayoutConfigJson[] = all_known_layouts.themes; + const args = process.argv + const theme = args[2] + if(theme !== undefined){ + console.warn("Only generating layout "+theme) } - const layout = new LayoutConfig(layoutConfigJson, true, "generating layouts") - const layoutName = layout.id - if (blacklist.indexOf(layoutName.toLowerCase()) >= 0) { - console.log(`Skipping a layout with name${layoutName}, it is on the blacklist`); - continue; - } - const err = err => { - if (err !== null) { - console.log("Could not write manifest for ", layoutName, " because ", err) + for (const i in all) { + const layoutConfigJson: LayoutConfigJson = all[i] + if(theme !== undefined && layoutConfigJson.id !== theme){ + continue } - }; - createManifest(layout).then(manifObj => { + const layout = new LayoutConfig(layoutConfigJson, true, "generating layouts") + const layoutName = layout.id + if (blacklist.indexOf(layoutName.toLowerCase()) >= 0) { + console.log(`Skipping a layout with name${layoutName}, it is on the blacklist`); + continue; + } + const err = err => { + if (err !== null) { + console.log("Could not write manifest for ", layoutName, " because ", err) + } + }; + await createManifest(layout, alreadyWritten).then(manifObj => { + 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) + }); + createIndexFor(layout) + }).catch(e => console.log("Could not generate the manifest: ", e)) + + } + + await createManifest(new LayoutConfig({ + icon: "assets/svg/mapcomplete_logo.svg", + id: "index", + layers: [], + maintainer: "Pieter Vander Vennet", + socialImage: "assets/SocialImage.png", + startLat: 0, + startLon: 0, + startZoom: 0, + title: {en: "MapComplete"}, + version: Constants.vNumber, + description: {en: "A thematic map viewer and editor based on OpenStreetMap"} + }), alreadyWritten).then(manifObj => { 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) - }); - createIndexFor(layout) - }).catch(e => console.log("Could not generate the manifest: ", e)) + writeFileSync("index.manifest", manif) + }) } -createManifest(new LayoutConfig({ - icon: "assets/svg/mapcomplete_logo.svg", - id: "index", - layers: [], - maintainer: "Pieter Vander Vennet", - socialImage: "assets/SocialImage.png", - startLat: 0, - startLon: 0, - startZoom: 0, - title: {en: "MapComplete"}, - version: Constants.vNumber, - description: {en: "A thematic map viewer and editor based on OpenStreetMap"} -})).then(manifObj => { - const manif = JSON.stringify(manifObj, undefined, 2); - writeFileSync("index.manifest", manif) -}) - - -console.log("All done!"); \ No newline at end of file +main().then(() => { + console.log("All done!") +}) \ No newline at end of file diff --git a/test.ts b/test.ts index 408d16ec5..b7fd7b5f7 100644 --- a/test.ts +++ b/test.ts @@ -1,7 +1,15 @@ -import {AllKnownLayouts} from "./Customizations/AllKnownLayouts"; -import List from "./UI/Base/List"; -import Link from "./UI/Base/Link"; -import {FixedUiElement} from "./UI/Base/FixedUiElement"; +import xml2js from 'xml2js'; +import {readFileSync} from "fs"; -const allHidden = AllKnownLayouts.layoutsList.filter(l => l.hideFromOverview) -new List(allHidden.map(th => new Link(new FixedUiElement(th.id), "theme.html?layout=" + th.id))).AttachTo("maindiv") +const xml = "\n" + + "\n" + + " \n" + + " \n" + + " \n" + + "" + +xml2js.parseStringPromise(xml).then(svgResult => { + const svg = svgResult.svg + const builder = new xml2js.Builder(); + console.log(builder.buildObject(svg)) +})