forked from MapComplete/MapComplete
Scripts(nsi): stabilize and make scripts more log-friendly
This commit is contained in:
parent
53106cc0bf
commit
2b10c715b0
5 changed files with 71 additions and 25 deletions
|
@ -12,10 +12,12 @@ import { FilterConfigOptionJson } from "../src/Models/ThemeConfig/Json/FilterCon
|
|||
import { TagUtils } from "../src/Logic/Tags/TagUtils"
|
||||
import { openSync, readSync } from "node:fs"
|
||||
import { QuestionableTagRenderingConfigJson } from "../src/Models/ThemeConfig/Json/QuestionableTagRenderingConfigJson"
|
||||
import Constants from "../src/Models/Constants"
|
||||
|
||||
class NsiLogos extends Script {
|
||||
constructor() {
|
||||
super("Contains various subcommands for NSI logo maintainance")
|
||||
ScriptUtils.verbose = false
|
||||
}
|
||||
|
||||
private async downloadLogo(
|
||||
|
@ -38,7 +40,7 @@ class NsiLogos extends Script {
|
|||
}
|
||||
}
|
||||
|
||||
private async downloadLogoUnsafe(nsiItem: NSIItem, type: string, basePath: string) {
|
||||
private async downloadLogoUnsafe(nsiItem: NSIItem, type: string, basePath: string) : Promise<true | false | "error">{
|
||||
if (nsiItem === undefined) {
|
||||
return false
|
||||
}
|
||||
|
@ -86,7 +88,7 @@ class NsiLogos extends Script {
|
|||
}
|
||||
if ((<string>logos.wikidata).toLowerCase().endsWith(".svg")) {
|
||||
if (!path.endsWith(".svg")) {
|
||||
throw "Undetected svg path:" + logos.wikidata
|
||||
return false // We don't supports svgs
|
||||
}
|
||||
writeFileSync(path, dloaded["content"], "utf8")
|
||||
return true
|
||||
|
@ -242,6 +244,7 @@ class NsiLogos extends Script {
|
|||
}
|
||||
|
||||
private async download() {
|
||||
ScriptUtils.verbose = false
|
||||
const types = ["brand", "operator"]
|
||||
let dload = 0
|
||||
let failed = 0
|
||||
|
@ -393,7 +396,7 @@ class NsiLogos extends Script {
|
|||
}
|
||||
|
||||
private commands: Record<string, { f: () => Promise<void>; doc?: string }> = {
|
||||
download: { f: () => this.download(), doc: "Download all icons" },
|
||||
download: { f: () => this.download(), doc: "Download all icons. Gets the index from "+Constants.nsiLogosEndpoint+" first, then fetches the corresponding logos" },
|
||||
generateRenderings: {
|
||||
f: () => this.generateRenderings(),
|
||||
doc: "Generates the layer files 'nsi_brand.json' and 'nsi_operator.json' which allows to reuse the icons in renderings",
|
||||
|
@ -405,7 +408,7 @@ class NsiLogos extends Script {
|
|||
},
|
||||
patch: {
|
||||
f: () => this.patchNsiFile(),
|
||||
doc: "Reads nsi.min.json, adds the 'ext' (extension) field to every relevant entry",
|
||||
doc: "Modifies nsi.min.json, adds the 'ext' (extension) field to every relevant entry",
|
||||
},
|
||||
all: {
|
||||
doc: "Run `download`, `generateRenderings`, `prune` and `addExtensions`",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue