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:
Pieter Vander Vennet 2023-01-17 01:00:43 +01:00
parent 39cc043f8b
commit e9004a2190
7 changed files with 543 additions and 130 deletions

View file

@ -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> {