forked from MapComplete/MapComplete
Use libraries to generate MD, steps to factor out more of the UIElements
This commit is contained in:
parent
015b9aebad
commit
7c71e566e9
5 changed files with 167 additions and 125 deletions
|
@ -2,7 +2,6 @@ import Combine from "../src/UI/Base/Combine"
|
|||
import BaseUIElement from "../src/UI/BaseUIElement"
|
||||
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs"
|
||||
import { AllKnownLayouts } from "../src/Customizations/AllKnownLayouts"
|
||||
import TableOfContents from "../src/UI/Base/TableOfContents"
|
||||
import SimpleMetaTaggers from "../src/Logic/SimpleMetaTagger"
|
||||
import SpecialVisualizations from "../src/UI/SpecialVisualizations"
|
||||
import { ExtraFunctions } from "../src/Logic/ExtraFunctions"
|
||||
|
@ -31,6 +30,7 @@ import { Utils } from "../src/Utils"
|
|||
import { TagUtils } from "../src/Logic/Tags/TagUtils"
|
||||
import Script from "./Script"
|
||||
import { Changes } from "../src/Logic/Osm/Changes"
|
||||
import TableOfContents from "../src/UI/Base/TableOfContents"
|
||||
|
||||
/**
|
||||
* Converts a markdown-file into a .json file, which a walkthrough/slideshow element can use
|
||||
|
@ -56,15 +56,15 @@ class ToSlideshowJson {
|
|||
sections.push(currentSection)
|
||||
currentSection = []
|
||||
}
|
||||
line = line.replace('src="../../public/', 'src="./')
|
||||
line = line.replace('src="../../', 'src="./')
|
||||
line = line.replace("src=\"../../public/", "src=\"./")
|
||||
line = line.replace("src=\"../../", "src=\"./")
|
||||
currentSection.push(line)
|
||||
}
|
||||
sections.push(currentSection)
|
||||
writeFileSync(
|
||||
this._target,
|
||||
JSON.stringify({
|
||||
sections: sections.map((s) => s.join("\n")).filter((s) => s.length > 0),
|
||||
sections: sections.map((s) => s.join("\n")).filter((s) => s.length > 0)
|
||||
})
|
||||
)
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ class WikiPageGenerator {
|
|||
|
||||
generate() {
|
||||
let wikiPage =
|
||||
'{|class="wikitable sortable"\n' +
|
||||
"{|class=\"wikitable sortable\"\n" +
|
||||
"! Name, link !! Genre !! Covered region !! Language !! Description !! Free materials !! Image\n" +
|
||||
"|-"
|
||||
|
||||
|
@ -141,7 +141,7 @@ export class GenerateDocs extends Script {
|
|||
}
|
||||
|
||||
this.WriteFile("./Docs/Tags_format.md", TagUtils.generateDocs(), [
|
||||
"src/Logic/Tags/TagUtils.ts",
|
||||
"src/Logic/Tags/TagUtils.ts"
|
||||
])
|
||||
|
||||
new ToSlideshowJson(
|
||||
|
@ -166,30 +166,33 @@ export class GenerateDocs extends Script {
|
|||
})
|
||||
|
||||
this.WriteFile("./Docs/SpecialRenderings.md", SpecialVisualizations.HelpMessage(), [
|
||||
"src/UI/SpecialVisualizations.ts",
|
||||
"src/UI/SpecialVisualizations.ts"
|
||||
])
|
||||
this.WriteFile(
|
||||
"./Docs/CalculatedTags.md",
|
||||
new Combine([
|
||||
new Title("Metatags", 1),
|
||||
SimpleMetaTaggers.HelpText(),
|
||||
ExtraFunctions.HelpText(),
|
||||
ExtraFunctions.HelpText()
|
||||
]).SetClass("flex-col"),
|
||||
["src/Logic/SimpleMetaTagger.ts", "src/Logic/ExtraFunctions.ts"]
|
||||
)
|
||||
this.WriteFile("./Docs/SpecialInputElements.md", Validators.HelpText(), [
|
||||
"src/UI/InputElement/Validators.ts",
|
||||
"src/UI/InputElement/Validators.ts"
|
||||
])
|
||||
|
||||
this.WriteFile("./Docs/ChangesetMeta.md", Changes.getDocs(), [
|
||||
"src/Logic/Osm/Changes.ts",
|
||||
"src/Logic/Osm/ChangesetHandler.ts",
|
||||
"src/Logic/Osm/ChangesetHandler.ts"
|
||||
])
|
||||
new WikiPageGenerator().generate()
|
||||
|
||||
console.log("Generated docs")
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
private WriteFile(
|
||||
filename,
|
||||
html: string | BaseUIElement,
|
||||
|
@ -201,6 +204,29 @@ export class GenerateDocs extends Script {
|
|||
if (!html) {
|
||||
return
|
||||
}
|
||||
|
||||
let md = new Combine([
|
||||
Translations.W(html),
|
||||
"\n\nThis document is autogenerated from " +
|
||||
autogenSource
|
||||
.map(
|
||||
(file) =>
|
||||
`[${file}](https://github.com/pietervdvn/MapComplete/blob/develop/${file})`
|
||||
)
|
||||
.join(", ")
|
||||
]).AsMarkdown()
|
||||
this.WriteMarkdownFile(filename, md, autogenSource, options)
|
||||
}
|
||||
|
||||
|
||||
private WriteMarkdownFile(
|
||||
filename: string,
|
||||
markdown: string,
|
||||
autogenSource: string[],
|
||||
options?: {
|
||||
noTableOfContents: boolean
|
||||
}
|
||||
): void {
|
||||
for (const source of autogenSource) {
|
||||
if (source.indexOf("*") > 0) {
|
||||
continue
|
||||
|
@ -214,22 +240,12 @@ export class GenerateDocs extends Script {
|
|||
}
|
||||
}
|
||||
|
||||
if (html instanceof Combine && !options?.noTableOfContents) {
|
||||
const toc = new TableOfContents(html)
|
||||
const els = html.getElements()
|
||||
html = new Combine([els.shift(), toc, ...els]).SetClass("flex flex-col")
|
||||
}
|
||||
|
||||
let md = new Combine([
|
||||
Translations.W(html),
|
||||
"\n\nThis document is autogenerated from " +
|
||||
autogenSource
|
||||
.map(
|
||||
(file) =>
|
||||
`[${file}](https://github.com/pietervdvn/MapComplete/blob/develop/${file})`
|
||||
)
|
||||
.join(", "),
|
||||
]).AsMarkdown()
|
||||
let md = markdown
|
||||
|
||||
if (options?.noTableOfContents !== false) {
|
||||
md = TableOfContents.insertTocIntoMd(md)
|
||||
}
|
||||
|
||||
md.replace(/\n\n\n+/g, "\n\n")
|
||||
|
||||
|
@ -238,7 +254,7 @@ export class GenerateDocs extends Script {
|
|||
}
|
||||
|
||||
const warnAutomated =
|
||||
"[//]: # (WARNING: this file is automatically generated. Please find the sources at the bottom and edit those sources)"
|
||||
"[//]: # (WARNING: this file is automatically generated. Please find the sources at the bottom and edit those sources)\n\n"
|
||||
|
||||
writeFileSync(filename, warnAutomated + md)
|
||||
}
|
||||
|
@ -278,7 +294,7 @@ export class GenerateDocs extends Script {
|
|||
}
|
||||
|
||||
this.WriteFile("./Docs/builtin_units.md", new Combine([new Title("Units", 1), ...els]), [
|
||||
`assets/layers/unit/unit.json`,
|
||||
`assets/layers/unit/unit.json`
|
||||
])
|
||||
}
|
||||
|
||||
|
@ -359,9 +375,7 @@ export class GenerateDocs extends Script {
|
|||
if (inlineSource !== undefined) {
|
||||
source = `assets/themes/${inlineSource}/${inlineSource}.json`
|
||||
}
|
||||
this.WriteFile("./Docs/Layers/" + layer.id + ".md", element, [source], {
|
||||
noTableOfContents: true,
|
||||
})
|
||||
this.WriteFile("./Docs/Layers/" + layer.id + ".md", element, [source])
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -405,14 +419,19 @@ export class GenerateDocs extends Script {
|
|||
builtinsPerLayer.set(layer.id, usedBuiltins)
|
||||
}
|
||||
|
||||
const docs = new Combine([
|
||||
new Title("Index of builtin TagRendering", 1),
|
||||
new Title("Existing builtin tagrenderings", 2),
|
||||
...Array.from(layersUsingBuiltin.entries()).map(([builtin, usedByLayers]) =>
|
||||
new Combine([new Title(builtin), new List(usedByLayers)]).SetClass("flex flex-col")
|
||||
),
|
||||
]).SetClass("flex flex-col")
|
||||
this.WriteFile("./Docs/BuiltinIndex.md", docs, ["assets/layers/*.json"])
|
||||
let docs =`
|
||||
# Index of builtin TagRenderings
|
||||
## Existing builtin tagrenderings
|
||||
`
|
||||
|
||||
for (const [builtin, usedByLayers] of Array.from(layersUsingBuiltin.entries())) {
|
||||
docs += `
|
||||
### ${builtin}
|
||||
|
||||
${usedByLayers.map(item => " - "+item).join("\n")}
|
||||
`
|
||||
}
|
||||
this.WriteMarkdownFile("./Docs/BuiltinIndex.md", docs, ["assets/layers/*.json"])
|
||||
}
|
||||
|
||||
private generateQueryParameterDocs() {
|
||||
|
@ -448,7 +467,7 @@ export class GenerateDocs extends Script {
|
|||
theme.title,
|
||||
"(",
|
||||
new Link(theme.id, "https://mapcomplete.org/" + theme.id),
|
||||
")",
|
||||
")"
|
||||
]),
|
||||
2
|
||||
),
|
||||
|
@ -460,7 +479,7 @@ export class GenerateDocs extends Script {
|
|||
.map((l) => new Link(l.id, "../Layers/" + l.id + ".md"))
|
||||
),
|
||||
"Available languages:",
|
||||
new List(theme.language.filter((ln) => ln !== "_context")),
|
||||
new List(theme.language.filter((ln) => ln !== "_context"))
|
||||
]).SetClass("flex flex-col")
|
||||
this.WriteFile(
|
||||
"./Docs/Themes/" + theme.id + ".md",
|
||||
|
@ -538,7 +557,7 @@ export class GenerateDocs extends Script {
|
|||
Array.from(AllSharedLayers.sharedLayers.keys()).map(
|
||||
(id) => new Link(id, "./Layers/" + id + ".md")
|
||||
)
|
||||
),
|
||||
)
|
||||
])
|
||||
this.WriteFile("./Docs/BuiltinLayers.md", el, ["src/Customizations/AllKnownLayouts.ts"])
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue