chore: automated housekeeping...
This commit is contained in:
parent
6bc8760adf
commit
0ad881316b
359 changed files with 2049 additions and 938 deletions
|
@ -235,7 +235,6 @@ function extractHintsFrom(
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return hints
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ import TableOfContents from "../src/UI/Base/TableOfContents"
|
|||
import MarkdownUtils from "../src/Utils/MarkdownUtils"
|
||||
import { parse as parse_html } from "node-html-parser"
|
||||
import { AvailableRasterLayers } from "../src/Models/RasterLayers"
|
||||
import { ImmutableStore } from "../src/Logic/UIEventSource"
|
||||
|
||||
/**
|
||||
* Converts a markdown-file into a .json file, which a walkthrough/slideshow element can use
|
||||
|
@ -245,7 +246,10 @@ export class GenerateDocs extends Script {
|
|||
const generatedFrom = [
|
||||
"This document is autogenerated from",
|
||||
autogenSource
|
||||
.map((s) => `[${s}](https://source.mapcomplete.org/MapComplete/MapComplete/src/branch/develop/${s})`)
|
||||
.map(
|
||||
(s) =>
|
||||
`[${s}](https://source.mapcomplete.org/MapComplete/MapComplete/src/branch/develop/${s})`
|
||||
)
|
||||
.join(", "),
|
||||
].join(" ")
|
||||
|
||||
|
@ -253,7 +257,7 @@ export class GenerateDocs extends Script {
|
|||
}
|
||||
|
||||
private generateHotkeyDocs() {
|
||||
new ThemeViewState(new ThemeConfig(<any>bookcases), new Set())
|
||||
new ThemeViewState(new ThemeConfig(<any>bookcases), new ImmutableStore(new Set()))
|
||||
this.WriteMarkdownFile("./Docs/Hotkeys.md", Hotkeys.generateDocumentation(), [
|
||||
"src/UI/Base/Hotkeys.ts",
|
||||
])
|
||||
|
|
|
@ -130,9 +130,9 @@ ${changeset}`
|
|||
const changesObj = new Changes(
|
||||
{
|
||||
osmConnection,
|
||||
reportError: (err) => console.error(err)
|
||||
reportError: (err) => console.error(err),
|
||||
},
|
||||
false,
|
||||
false
|
||||
)
|
||||
|
||||
const all: ErrorMessage[] = []
|
||||
|
|
|
@ -15,11 +15,16 @@ class NsiLogos extends Script {
|
|||
super("Contains various subcommands for NSI logo maintainance")
|
||||
}
|
||||
|
||||
private async downloadLogo(nsiItem: NSIItem, type: string, basePath: string, alreadyDownloaded: Map<string, string>) {
|
||||
if(nsiItem === undefined){
|
||||
private async downloadLogo(
|
||||
nsiItem: NSIItem,
|
||||
type: string,
|
||||
basePath: string,
|
||||
alreadyDownloaded: Map<string, string>
|
||||
) {
|
||||
if (nsiItem === undefined) {
|
||||
return false
|
||||
}
|
||||
if(alreadyDownloaded.has(nsiItem.id)){
|
||||
if (alreadyDownloaded.has(nsiItem.id)) {
|
||||
return false
|
||||
}
|
||||
try {
|
||||
|
@ -54,7 +59,7 @@ class NsiLogos extends Script {
|
|||
await ScriptUtils.DownloadFileTo(logos.facebook, path)
|
||||
// Validate
|
||||
const content = readFileSync(path, "utf8")
|
||||
if (content.startsWith("{\"error\"")) {
|
||||
if (content.startsWith('{"error"')) {
|
||||
unlinkSync(path)
|
||||
console.error("Attempted to fetch", logos.facebook, " but this gave an error")
|
||||
} else {
|
||||
|
@ -109,13 +114,16 @@ class NsiLogos extends Script {
|
|||
const stepcount = 50
|
||||
for (let i = 0; i < items.length; i += stepcount) {
|
||||
if (downloadCount > 0 || i % 200 === 0) {
|
||||
console.log(i + "/" + items.length, `downloaded ${downloadCount}; failed ${errored}; skipped ${skipped} for NSI type ${type}`)
|
||||
console.log(
|
||||
i + "/" + items.length,
|
||||
`downloaded ${downloadCount}; failed ${errored}; skipped ${skipped} for NSI type ${type}`
|
||||
)
|
||||
}
|
||||
|
||||
const results = await Promise.all(
|
||||
Utils.TimesT(stepcount, (j) => j).map(async (j) => {
|
||||
return await this.downloadLogo(items[i + j], type, basePath, alreadyDownloaded)
|
||||
}),
|
||||
})
|
||||
)
|
||||
for (let j = 0; j < results.length; j++) {
|
||||
let didDownload = results[j]
|
||||
|
@ -129,7 +137,12 @@ class NsiLogos extends Script {
|
|||
continue
|
||||
}
|
||||
console.log("Retrying", items[i + j].id, type)
|
||||
didDownload = await this.downloadLogo(items[i + j], type, basePath, alreadyDownloaded)
|
||||
didDownload = await this.downloadLogo(
|
||||
items[i + j],
|
||||
type,
|
||||
basePath,
|
||||
alreadyDownloaded
|
||||
)
|
||||
if (didDownload === "error") {
|
||||
errored++
|
||||
console.log("Failed again:", items[i + j].id)
|
||||
|
@ -139,7 +152,8 @@ class NsiLogos extends Script {
|
|||
}
|
||||
}
|
||||
return {
|
||||
downloadCount, errored,
|
||||
downloadCount,
|
||||
errored,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -153,17 +167,26 @@ class NsiLogos extends Script {
|
|||
osmTags: NameSuggestionIndex.asFilterTags(item),
|
||||
}
|
||||
})
|
||||
const mappings = items.map((item) => ({
|
||||
if: NameSuggestionIndex.asFilterTags(item),
|
||||
then: nsi.getIconUrl(item)
|
||||
})).filter(mapping => mapping.then !== undefined)
|
||||
const mappings = items
|
||||
.map((item) => ({
|
||||
if: NameSuggestionIndex.asFilterTags(item),
|
||||
then: nsi.getIconUrl(item),
|
||||
}))
|
||||
.filter((mapping) => mapping.then !== undefined)
|
||||
|
||||
console.log("Checking for shadow-mappings... This will take a while")
|
||||
let deleted = 0
|
||||
for (let i = mappings.length - 1; i >= 0; i--) {
|
||||
const condition = TagUtils.Tag(mappings[i].if)
|
||||
if (i % 100 === 0) {
|
||||
console.log("Checking for shadow-mappings...", i, "/", mappings.length, "deleted", deleted)
|
||||
console.log(
|
||||
"Checking for shadow-mappings...",
|
||||
i,
|
||||
"/",
|
||||
mappings.length,
|
||||
"deleted",
|
||||
deleted
|
||||
)
|
||||
}
|
||||
const shadowsSomething = mappings.some((m, j) => {
|
||||
if (i === j) {
|
||||
|
@ -231,9 +254,12 @@ class NsiLogos extends Script {
|
|||
|
||||
private static readonly path: string = "./public/assets/data/nsi/logos"
|
||||
private static headers: Readonly<Record<string, ReadonlyArray<ReadonlyArray<number>>>> = {
|
||||
"png": [[137, 80, 78, 71, 13, 10, 26, 10]],
|
||||
"jpg": [[255, 216], [255, 232]],
|
||||
"gif": [[71, 73]],
|
||||
png: [[137, 80, 78, 71, 13, 10, 26, 10]],
|
||||
jpg: [
|
||||
[255, 216],
|
||||
[255, 232],
|
||||
],
|
||||
gif: [[71, 73]],
|
||||
}
|
||||
|
||||
private static downloadedFiles(): Map<string, string> {
|
||||
|
@ -273,8 +299,6 @@ class NsiLogos extends Script {
|
|||
}
|
||||
}
|
||||
console.log("Removed ", pruned, "files")
|
||||
|
||||
|
||||
}
|
||||
|
||||
private startsWith(buffer: Buffer, header: ReadonlyArray<number>): boolean {
|
||||
|
@ -285,8 +309,11 @@ class NsiLogos extends Script {
|
|||
return doesMatch
|
||||
}
|
||||
|
||||
private startsWithAnyOf(buffer: Buffer, headers: ReadonlyArray<ReadonlyArray<number>>): boolean {
|
||||
return headers.some(header => this.startsWith(buffer, header))
|
||||
private startsWithAnyOf(
|
||||
buffer: Buffer,
|
||||
headers: ReadonlyArray<ReadonlyArray<number>>
|
||||
): boolean {
|
||||
return headers.some((header) => this.startsWith(buffer, header))
|
||||
}
|
||||
|
||||
private async addExtensions() {
|
||||
|
@ -299,8 +326,7 @@ class NsiLogos extends Script {
|
|||
const fd = openSync(f, "r")
|
||||
const buffer = Buffer.alloc(10)
|
||||
const num = readSync(fd, buffer, 0, 10, null)
|
||||
if (num === 0)
|
||||
throw "INvalid file:" + f
|
||||
if (num === 0) throw "INvalid file:" + f
|
||||
|
||||
let matchFound = false
|
||||
for (const format in NsiLogos.headers) {
|
||||
|
@ -320,12 +346,17 @@ class NsiLogos extends Script {
|
|||
unlinkSync(f)
|
||||
continue
|
||||
}
|
||||
throw "No format found for " + f + buffer.slice(0, 10).join(" ") + " ascii: " + text.slice(0, 40)
|
||||
|
||||
throw (
|
||||
"No format found for " +
|
||||
f +
|
||||
buffer.slice(0, 10).join(" ") +
|
||||
" ascii: " +
|
||||
text.slice(0, 40)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private async patchNsiFile(){
|
||||
private async patchNsiFile() {
|
||||
const files = NsiLogos.downloadedFiles()
|
||||
let path = "./public/assets/data/nsi/nsi.min.json"
|
||||
const otherPath = "./assets/data/nsi/nsi.min.json"
|
||||
|
@ -340,7 +371,7 @@ class NsiLogos extends Script {
|
|||
for (const nsiItem of t) {
|
||||
const file = files.get(nsiItem.id)
|
||||
delete nsiItem.fromTemplate
|
||||
if(!file){
|
||||
if (!file) {
|
||||
continue
|
||||
}
|
||||
const extension = file.match(/.*\.([a-z]{3})/)[1]
|
||||
|
@ -348,25 +379,24 @@ class NsiLogos extends Script {
|
|||
}
|
||||
}
|
||||
writeFileSync(path, JSON.stringify(nsi), "utf8")
|
||||
|
||||
}
|
||||
|
||||
private commands: Record<string, { f: () => Promise<void>, doc?: string }> = {
|
||||
"download": { f: () => this.download(), doc: "Download all icons" },
|
||||
"generateRenderings": {
|
||||
private commands: Record<string, { f: () => Promise<void>; doc?: string }> = {
|
||||
download: { f: () => this.download(), doc: "Download all icons" },
|
||||
generateRenderings: {
|
||||
f: () => this.generateRenderings(),
|
||||
doc: "Generates the layer files 'nsi_brand' and 'nsi_operator' which allows to reuse the icons in renderings",
|
||||
},
|
||||
"prune": { f: () => NsiLogos.prune(), doc: "Remove no longer needed files" },
|
||||
"addExtensions": {
|
||||
prune: { f: () => NsiLogos.prune(), doc: "Remove no longer needed files" },
|
||||
addExtensions: {
|
||||
f: () => this.addExtensions(),
|
||||
doc: "Inspects all files without an extension; might remove invalid files",
|
||||
},
|
||||
"patch": {
|
||||
patch: {
|
||||
f: () => this.patchNsiFile(),
|
||||
doc: "Reads nsi.min.json, adds the 'ext' (extension) field to every relevant entry"
|
||||
doc: "Reads nsi.min.json, adds the 'ext' (extension) field to every relevant entry",
|
||||
},
|
||||
"all": {
|
||||
all: {
|
||||
doc: "Run `download`, `generateRenderings`, `prune` and `addExtensions`",
|
||||
f: async () => {
|
||||
await NsiLogos.prune()
|
||||
|
@ -393,7 +423,6 @@ class NsiLogos extends Script {
|
|||
}
|
||||
|
||||
for (const command of args) {
|
||||
|
||||
const c = this.commands[command]
|
||||
if (!c) {
|
||||
console.log("Unrecognized command:", c)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue