Undo some changes to fix the build, move svg-check into generateLayerOverview as to move fs out of the dependency tree for the webpage
This commit is contained in:
parent
39cc043f8b
commit
e9004a2190
7 changed files with 543 additions and 130 deletions
|
@ -1,5 +1,5 @@
|
|||
// import * as fs from "fs"
|
||||
// import { existsSync, lstatSync, readdirSync, readFileSync } from "fs"
|
||||
import * as fs from "fs"
|
||||
import { existsSync, lstatSync, readdirSync, readFileSync } from "fs"
|
||||
import { Utils } from "../Utils"
|
||||
import * as https from "https"
|
||||
import { LayoutConfigJson } from "../Models/ThemeConfig/Json/LayoutConfigJson"
|
||||
|
@ -23,17 +23,17 @@ export default class ScriptUtils {
|
|||
if (maxDepth <= 0) {
|
||||
return []
|
||||
}
|
||||
// for (const entry of readdirSync(path)) {
|
||||
// const fullEntry = path + "/" + entry
|
||||
// const stats = lstatSync(fullEntry)
|
||||
// if (stats.isDirectory()) {
|
||||
// // Subdirectory
|
||||
// // @ts-ignore
|
||||
// result.push(...ScriptUtils.readDirRecSync(fullEntry, maxDepth - 1))
|
||||
// } else {
|
||||
// result.push(fullEntry)
|
||||
// }
|
||||
// }
|
||||
for (const entry of readdirSync(path)) {
|
||||
const fullEntry = path + "/" + entry
|
||||
const stats = lstatSync(fullEntry)
|
||||
if (stats.isDirectory()) {
|
||||
// Subdirectory
|
||||
// @ts-ignore
|
||||
result.push(...ScriptUtils.readDirRecSync(fullEntry, maxDepth - 1))
|
||||
} else {
|
||||
result.push(fullEntry)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
|
@ -78,8 +78,7 @@ export default class ScriptUtils {
|
|||
.filter((path) => path.indexOf("license_info.json") < 0)
|
||||
.map((path) => {
|
||||
try {
|
||||
// const contents = readFileSync(path, { encoding: "utf8" })
|
||||
const contents = ""
|
||||
const contents = readFileSync(path, { encoding: "utf8" })
|
||||
if (contents === "") {
|
||||
throw "The file " + path + " is empty, did you properly save?"
|
||||
}
|
||||
|
@ -102,8 +101,7 @@ export default class ScriptUtils {
|
|||
public static getThemeFiles(): { parsed: LayoutConfigJson; path: string }[] {
|
||||
return this.getThemePaths().map((path) => {
|
||||
try {
|
||||
// const contents = readFileSync(path, { encoding: "utf8" })
|
||||
const contents = ""
|
||||
const contents = readFileSync(path, { encoding: "utf8" })
|
||||
if (contents === "") {
|
||||
throw "The file " + path + " is empty, did you properly save?"
|
||||
}
|
||||
|
@ -124,25 +122,24 @@ export default class ScriptUtils {
|
|||
}
|
||||
|
||||
public static async ReadSvg(path: string): Promise<any> {
|
||||
// if (!existsSync(path)) {
|
||||
// throw "File not found: " + path
|
||||
// }
|
||||
// const root = await xml2js.parseStringPromise(readFileSync(path, { encoding: "utf8" }))
|
||||
// return root.svg
|
||||
return ""
|
||||
if (!existsSync(path)) {
|
||||
throw "File not found: " + path
|
||||
}
|
||||
const root = await xml2js.parseStringPromise(readFileSync(path, { encoding: "utf8" }))
|
||||
return root.svg
|
||||
}
|
||||
|
||||
public static ReadSvgSync(path: string, callback: (svg: any) => void): any {
|
||||
// xml2js.parseString(
|
||||
// readFileSync(path, { encoding: "utf8" }),
|
||||
// { async: false },
|
||||
// (err, root) => {
|
||||
// if (err) {
|
||||
// throw err
|
||||
// }
|
||||
// callback(root["svg"])
|
||||
// }
|
||||
// )
|
||||
xml2js.parseString(
|
||||
readFileSync(path, { encoding: "utf8" }),
|
||||
{ async: false },
|
||||
(err, root) => {
|
||||
if (err) {
|
||||
throw err
|
||||
}
|
||||
callback(root["svg"])
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
private static async DownloadJSON(url: string, headers?: any): Promise<any> {
|
||||
|
|
|
@ -281,10 +281,9 @@ class LayerOverviewUtils {
|
|||
then: th.icon,
|
||||
}))
|
||||
const proto: LayoutConfigJson = JSON.parse(
|
||||
readFileSync(
|
||||
"./assets/themes/mapcomplete-changes/mapcomplete-changes.proto.json",
|
||||
{ encoding: "utf8" }
|
||||
)
|
||||
readFileSync("./assets/themes/mapcomplete-changes/mapcomplete-changes.proto.json", {
|
||||
encoding: "utf8",
|
||||
})
|
||||
)
|
||||
const protolayer = <LayerConfigJson>(
|
||||
proto.layers.filter((l) => l["id"] === "mapcomplete-changes")[0]
|
||||
|
@ -441,6 +440,34 @@ class LayerOverviewUtils {
|
|||
convertState.tagRenderings
|
||||
).convertStrict(themeFile, themePath)
|
||||
|
||||
if (themeFile.icon.endsWith(".svg")) {
|
||||
try {
|
||||
ScriptUtils.ReadSvgSync(json.icon, (svg) => {
|
||||
const width: string = svg.$.width
|
||||
const height: string = svg.$.height
|
||||
if (width !== height) {
|
||||
const e =
|
||||
`the icon for theme ${json.id} is not square. Please square the icon at ${json.icon}` +
|
||||
` Width = ${width} height = ${height}`
|
||||
;(json.hideFromOverview ? warnings : errors).push(e)
|
||||
}
|
||||
|
||||
const w = parseInt(width)
|
||||
const h = parseInt(height)
|
||||
if (w < 370 || h < 370) {
|
||||
const e: string = [
|
||||
`the icon for theme ${json.id} is too small. Please rescale the icon at ${json.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.`,
|
||||
].join("\n")
|
||||
;(json.hideFromOverview ? warnings : errors).push(e)
|
||||
}
|
||||
})
|
||||
} catch (e) {
|
||||
console.error("Could not read " + json.icon + " due to " + e)
|
||||
}
|
||||
}
|
||||
|
||||
this.writeTheme(themeFile)
|
||||
fixed.set(themeFile.id, themeFile)
|
||||
} catch (e) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue