Fix the last fake images, fix non-square theme icons, throw an error on fake svgs and non-square icons (if public theme)
This commit is contained in:
parent
d5378c5bd6
commit
db770f2c35
24 changed files with 719 additions and 336 deletions
|
@ -4,7 +4,7 @@ import {Utils} from "../Utils";
|
|||
import * as https from "https";
|
||||
import {LayoutConfigJson} from "../Models/ThemeConfig/Json/LayoutConfigJson";
|
||||
import {LayerConfigJson} from "../Models/ThemeConfig/Json/LayerConfigJson";
|
||||
|
||||
import xml2js from 'xml2js';
|
||||
export default class ScriptUtils {
|
||||
|
||||
|
||||
|
@ -146,4 +146,18 @@ export default class ScriptUtils {
|
|||
return ScriptUtils.DownloadJSON(url)
|
||||
}
|
||||
|
||||
public static async ReadSvg(path: string): Promise<any>{
|
||||
const root = await xml2js.parseStringPromise(readFileSync(path, "UTF8"))
|
||||
return root.svg
|
||||
}
|
||||
|
||||
public static async ReadSvgSync(path: string, callback: ((svg: any) => void)): Promise<any>{
|
||||
xml2js.parseString(readFileSync(path, "UTF8"),{async: false} , (err, root) => {
|
||||
if(err){
|
||||
throw err
|
||||
}
|
||||
callback(root["svg"]);
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -96,7 +96,7 @@ class LayerOverviewUtils {
|
|||
return dict;
|
||||
}
|
||||
|
||||
checkAllSvgs(){
|
||||
checkAllSvgs() {
|
||||
const allSvgs = ScriptUtils.readDirRecSync("./assets")
|
||||
.filter(path => path.endsWith(".svg"))
|
||||
.filter(path => !path.startsWith("./assets/generated"))
|
||||
|
@ -108,11 +108,13 @@ class LayerOverviewUtils {
|
|||
}
|
||||
console.warn("The SVG at " + path + " is a fake SVG: it contains PNG data!")
|
||||
errCount++;
|
||||
if(path.startsWith("./assets/svg")){
|
||||
if (path.startsWith("./assets/svg")) {
|
||||
throw "A core SVG is actually a PNG. Don't do this!"
|
||||
}
|
||||
}
|
||||
console.log("There are "+errCount+" fake svgs")
|
||||
if (errCount > 0) {
|
||||
throw `There are ${errCount} fake svgs`
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -147,7 +149,7 @@ class LayerOverviewUtils {
|
|||
rendering.icon["mappings"] = iconsPerTheme
|
||||
writeFileSync('./assets/themes/mapcomplete-changes/mapcomplete-changes.json', JSON.stringify(proto, null, " "))
|
||||
}
|
||||
|
||||
|
||||
this.checkAllSvgs()
|
||||
}
|
||||
|
||||
|
|
|
@ -64,13 +64,9 @@ async function createManifest(layout: LayoutConfig, alreadyWritten: string[]) {
|
|||
|
||||
const whiteBackgroundPath = "./assets/generated/theme_"+layout.id+"_white_background.svg"
|
||||
{
|
||||
const svgResult = await xml2js.parseStringPromise(readFileSync(icon, "UTF8"))
|
||||
const svg = svgResult.svg
|
||||
const svg = await ScriptUtils.ReadSvg(icon)
|
||||
const width: string = svg.$.width;
|
||||
const height: string = svg.$.height;
|
||||
if(width !== height){
|
||||
console.warn("WARNING: the icon for theme "+layout.id+" is not square. Please square the icon at "+icon+"\n Width = "+width, "height =", height)
|
||||
}
|
||||
|
||||
const builder = new xml2js.Builder();
|
||||
const withRect = {rect: {"$":{width, height, style: "fill:#ffffff;"}}, ...svg}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue