forked from MapComplete/MapComplete
Scripts(docs): partial work on creatign localized docs
This commit is contained in:
parent
76571d9ae5
commit
19701126d6
6 changed files with 3564 additions and 80 deletions
|
@ -140,7 +140,7 @@ export class GenerateDocs extends Script {
|
|||
console.log("Starting documentation generation...")
|
||||
ScriptUtils.fixUtils()
|
||||
|
||||
this.WriteMarkdownFile(
|
||||
this.writeMarkdownFile(
|
||||
"./Docs/SpecialRenderings.md",
|
||||
SpecialVisualizations.HelpMessage(),
|
||||
["src/UI/SpecialVisualizations.ts"],
|
||||
|
@ -153,7 +153,7 @@ export class GenerateDocs extends Script {
|
|||
mkdirSync("./Docs/Themes")
|
||||
}
|
||||
|
||||
this.WriteMarkdownFile("./Docs/Tags_format.md", TagUtils.generateDocs(), [
|
||||
this.writeMarkdownFile("./Docs/Tags_format.md", TagUtils.generateDocs(), [
|
||||
"src/Logic/Tags/TagUtils.ts",
|
||||
])
|
||||
|
||||
|
@ -171,6 +171,8 @@ export class GenerateDocs extends Script {
|
|||
this.generateQueryParameterDocs()
|
||||
this.generateBuiltinQuestions()
|
||||
this.generateOverviewsForAllSingleLayer()
|
||||
// this.generateOverviewsForAllSingleLayer("./Docs/layers_nl", "nl")
|
||||
|
||||
this.generateLayerOverviewText()
|
||||
this.generateBuiltinUnits()
|
||||
await this.generateSourcesOverview()
|
||||
|
@ -180,22 +182,22 @@ export class GenerateDocs extends Script {
|
|||
ScriptUtils.erasableLog("Written docs for theme", theme.id)
|
||||
})
|
||||
|
||||
this.WriteMarkdownFile(
|
||||
this.writeMarkdownFile(
|
||||
"./Docs/CalculatedTags.md",
|
||||
["# Metatags", SimpleMetaTaggers.HelpText(), ExtraFunctions.HelpText()].join("\n"),
|
||||
["src/Logic/SimpleMetaTagger.ts", "src/Logic/ExtraFunctions.ts"],
|
||||
{ noTableOfContents: false }
|
||||
)
|
||||
this.WriteMarkdownFile("./Docs/SpecialInputElements.md", Validators.HelpText(), [
|
||||
this.writeMarkdownFile("./Docs/SpecialInputElements.md", Validators.HelpText(), [
|
||||
"src/UI/InputElement/Validators.ts",
|
||||
])
|
||||
|
||||
this.WriteMarkdownFile("./Docs/ChangesetMeta.md", Changes.getDocs(), [
|
||||
this.writeMarkdownFile("./Docs/ChangesetMeta.md", Changes.getDocs(), [
|
||||
"src/Logic/Osm/Changes.ts",
|
||||
"src/Logic/Osm/ChangesetHandler.ts",
|
||||
])
|
||||
const eli = AvailableRasterLayers.editorLayerIndex()
|
||||
this.WriteMarkdownFile(
|
||||
this.writeMarkdownFile(
|
||||
"./Docs/ELI-overview.md",
|
||||
[
|
||||
"# Layers in the Editor Layer Index",
|
||||
|
@ -219,15 +221,17 @@ export class GenerateDocs extends Script {
|
|||
console.log("Generated docs")
|
||||
}
|
||||
|
||||
private WriteMarkdownFile(
|
||||
private writeMarkdownFile(
|
||||
filename: string,
|
||||
markdown: string,
|
||||
autogenSource: string[],
|
||||
options?: {
|
||||
noTableOfContents?: boolean
|
||||
tocMaxDepth?: number
|
||||
lang?: string
|
||||
}
|
||||
): void {
|
||||
const lang = options?.lang ?? "en"
|
||||
for (const source of autogenSource) {
|
||||
if (source.indexOf("*") > 0) {
|
||||
continue
|
||||
|
@ -244,7 +248,7 @@ export class GenerateDocs extends Script {
|
|||
let md = markdown
|
||||
|
||||
if (options?.noTableOfContents !== false) {
|
||||
md = TableOfContents.insertTocIntoMd(md, options?.tocMaxDepth)
|
||||
md = TableOfContents.insertTocIntoMd(md, lang, options?.tocMaxDepth)
|
||||
}
|
||||
|
||||
md = md.replace(/\n\n\n+/g, "\n\n")
|
||||
|
@ -274,7 +278,7 @@ export class GenerateDocs extends Script {
|
|||
new ThemeConfig(<ThemeConfigJson>(<unknown>bookcases)),
|
||||
new ImmutableStore(new Set())
|
||||
)
|
||||
this.WriteMarkdownFile("./Docs/Hotkeys.md", Hotkeys.generateDocumentation(), [
|
||||
this.writeMarkdownFile("./Docs/Hotkeys.md", Hotkeys.generateDocumentation(), [
|
||||
"src/UI/Base/Hotkeys.ts",
|
||||
])
|
||||
}
|
||||
|
@ -324,7 +328,7 @@ export class GenerateDocs extends Script {
|
|||
}
|
||||
}
|
||||
|
||||
this.WriteMarkdownFile("./Docs/builtin_units.md", els.join("\n\n"), [
|
||||
this.writeMarkdownFile("./Docs/builtin_units.md", els.join("\n\n"), [
|
||||
`assets/layers/unit/unit.json`,
|
||||
`src/Models/ThemeConfig/Json/UnitConfigJson.ts`,
|
||||
])
|
||||
|
@ -334,10 +338,16 @@ export class GenerateDocs extends Script {
|
|||
* Generates documentation for the all the individual layers.
|
||||
* Inline layers are included (if the theme is public)
|
||||
*/
|
||||
private generateOverviewsForAllSingleLayer(): void {
|
||||
private generateOverviewsForAllSingleLayer(targetDirectory: string = "./Docs/Layers", lang: string = "en"): void {
|
||||
const allLayers: LayerConfig[] = Array.from(AllSharedLayers.sharedLayers.values()).filter(
|
||||
(layer) => layer["source"] !== null
|
||||
)
|
||||
const qLayer = new LayerConfig(
|
||||
<LayerConfigJson>(<unknown>questions),
|
||||
"questions.json",
|
||||
true
|
||||
)
|
||||
allLayers.push(qLayer)
|
||||
const builtinLayerIds: Set<string> = new Set<string>()
|
||||
allLayers.forEach((l) => builtinLayerIds.add(l.id))
|
||||
const inlineLayers = new Map<string, string>()
|
||||
|
@ -391,23 +401,23 @@ export class GenerateDocs extends Script {
|
|||
layerIsNeededBy.get(dependency).push(layer.id)
|
||||
}
|
||||
}
|
||||
|
||||
if (!existsSync(targetDirectory)) {
|
||||
mkdirSync(targetDirectory)
|
||||
}
|
||||
allLayers.forEach((layer) => {
|
||||
const element = layer.generateDocumentation({
|
||||
usedInThemes: themesPerLayer.get(layer.id),
|
||||
layerIsNeededBy: layerIsNeededBy,
|
||||
dependencies: DependencyCalculator.getLayerDependencies(layer),
|
||||
})
|
||||
lang
|
||||
}).replaceAll("./Docs/Layers", targetDirectory)
|
||||
const inlineSource = inlineLayers.get(layer.id)
|
||||
ScriptUtils.erasableLog("Exporting layer documentation for", layer.id)
|
||||
if (!existsSync("./Docs/Layers")) {
|
||||
mkdirSync("./Docs/Layers")
|
||||
}
|
||||
let source: string = `assets/layers/${layer.id}/${layer.id}.json`
|
||||
if (inlineSource !== undefined) {
|
||||
source = `assets/themes/${inlineSource}/${inlineSource}.json`
|
||||
}
|
||||
this.WriteMarkdownFile("./Docs/Layers/" + layer.id + ".md", element, [source])
|
||||
this.writeMarkdownFile(targetDirectory+ "/" + layer.id + ".md", element, [source])
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -463,7 +473,7 @@ export class GenerateDocs extends Script {
|
|||
${usedByLayers.map((item) => " - " + item).join("\n")}
|
||||
`
|
||||
}
|
||||
this.WriteMarkdownFile("./Docs/BuiltinIndex.md", docs, ["assets/layers/*.json"])
|
||||
this.writeMarkdownFile("./Docs/BuiltinIndex.md", docs, ["assets/layers/*.json"])
|
||||
}
|
||||
|
||||
private generateQueryParameterDocs() {
|
||||
|
@ -476,7 +486,7 @@ export class GenerateDocs extends Script {
|
|||
"The mode the application starts in, e.g. 'map', 'dashboard' or 'statistics'"
|
||||
)
|
||||
|
||||
this.WriteMarkdownFile(
|
||||
this.writeMarkdownFile(
|
||||
"./Docs/URL_Parameters.md",
|
||||
QueryParameterDocumentation.GenerateQueryParameterDocs(),
|
||||
["src/Logic/Web/QueryParameters.ts", "src/UI/QueryParameterDocumentation.ts"]
|
||||
|
@ -494,7 +504,7 @@ export class GenerateDocs extends Script {
|
|||
Array.from(AllSharedLayers.sharedLayers.values())
|
||||
)
|
||||
const docs = qLayer.generateDocumentation({ reusedTagRenderings })
|
||||
this.WriteMarkdownFile("./Docs/BuiltinQuestions.md", docs, [
|
||||
this.writeMarkdownFile("./Docs/BuiltinQuestions.md", docs, [
|
||||
"assets/layers/questions/questions.json",
|
||||
])
|
||||
}
|
||||
|
@ -533,7 +543,7 @@ export class GenerateDocs extends Script {
|
|||
"These layers can not be reused in different themes.",
|
||||
...layersToInline.map((l) => l.generateDocumentation({ usedInThemes: null })),
|
||||
].join("\n")
|
||||
this.WriteMarkdownFile(
|
||||
this.writeMarkdownFile(
|
||||
"./Docs/Themes/" + theme.id + ".md",
|
||||
el,
|
||||
[`assets/themes/${theme.id}/${theme.id}.json`],
|
||||
|
@ -659,7 +669,7 @@ export class GenerateDocs extends Script {
|
|||
md.push(urls.length + " items")
|
||||
md.push(MarkdownUtils.list(urls))
|
||||
|
||||
this.WriteMarkdownFile(
|
||||
this.writeMarkdownFile(
|
||||
"./Docs/OnlineServicesOverview.md",
|
||||
md.join("\n\n"),
|
||||
["src/Models/SourceOverview.ts"],
|
||||
|
@ -739,7 +749,7 @@ export class GenerateDocs extends Script {
|
|||
)
|
||||
),
|
||||
].join("\n\n")
|
||||
this.WriteMarkdownFile("./Docs/BuiltinLayers.md", el, [
|
||||
this.writeMarkdownFile("./Docs/BuiltinLayers.md", el, [
|
||||
"src/Customizations/AllKnownLayouts.ts",
|
||||
])
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue