| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | import Combine from "../UI/Base/Combine" | 
					
						
							|  |  |  | import BaseUIElement from "../UI/BaseUIElement" | 
					
						
							|  |  |  | import { existsSync, mkdirSync, writeFileSync } from "fs" | 
					
						
							|  |  |  | import { AllKnownLayouts } from "../Customizations/AllKnownLayouts" | 
					
						
							|  |  |  | import TableOfContents from "../UI/Base/TableOfContents" | 
					
						
							|  |  |  | import SimpleMetaTaggers from "../Logic/SimpleMetaTagger" | 
					
						
							|  |  |  | import ValidatedTextField from "../UI/Input/ValidatedTextField" | 
					
						
							|  |  |  | import SpecialVisualizations from "../UI/SpecialVisualizations" | 
					
						
							|  |  |  | import { ExtraFunctions } from "../Logic/ExtraFunctions" | 
					
						
							|  |  |  | import Title from "../UI/Base/Title" | 
					
						
							|  |  |  | import Minimap from "../UI/Base/Minimap" | 
					
						
							|  |  |  | import QueryParameterDocumentation from "../UI/QueryParameterDocumentation" | 
					
						
							|  |  |  | import ScriptUtils from "./ScriptUtils" | 
					
						
							|  |  |  | import List from "../UI/Base/List" | 
					
						
							|  |  |  | import SharedTagRenderings from "../Customizations/SharedTagRenderings" | 
					
						
							| 
									
										
										
										
											2022-11-02 13:47:34 +01:00
										 |  |  | import { writeFile } from "fs" | 
					
						
							|  |  |  | import Translations from "../UI/i18n/Translations" | 
					
						
							| 
									
										
										
										
											2022-10-27 22:03:41 +02:00
										 |  |  | import * as themeOverview from "../assets/generated/theme_overview.json" | 
					
						
							| 
									
										
										
										
											2022-12-24 03:44:21 +01:00
										 |  |  | import DefaultGUI from "../UI/DefaultGUI" | 
					
						
							|  |  |  | import FeaturePipelineState from "../Logic/State/FeaturePipelineState" | 
					
						
							|  |  |  | import LayoutConfig from "../Models/ThemeConfig/LayoutConfig" | 
					
						
							|  |  |  | import * as bookcases from "../assets/generated/themes/bookcases.json" | 
					
						
							|  |  |  | import { DefaultGuiState } from "../UI/DefaultGuiState" | 
					
						
							|  |  |  | import * as fakedom from "fake-dom" | 
					
						
							|  |  |  | import Hotkeys from "../UI/Base/Hotkeys" | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | function WriteFile( | 
					
						
							|  |  |  |     filename, | 
					
						
							|  |  |  |     html: BaseUIElement, | 
					
						
							|  |  |  |     autogenSource: string[], | 
					
						
							|  |  |  |     options?: { | 
					
						
							|  |  |  |         noTableOfContents: boolean | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | ): void { | 
					
						
							| 
									
										
										
										
											2022-02-15 00:11:11 +01:00
										 |  |  |     for (const source of autogenSource) { | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         if (source.indexOf("*") > 0) { | 
					
						
							| 
									
										
										
										
											2022-02-15 00:11:11 +01:00
										 |  |  |             continue | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         if (!existsSync(source)) { | 
					
						
							|  |  |  |             throw ( | 
					
						
							|  |  |  |                 "While creating a documentation file and checking that the generation sources are properly linked: source file " + | 
					
						
							|  |  |  |                 source + | 
					
						
							|  |  |  |                 " was not found. Typo?" | 
					
						
							|  |  |  |             ) | 
					
						
							| 
									
										
										
										
											2022-02-15 00:11:11 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     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") | 
					
						
							| 
									
										
										
										
											2021-11-30 22:50:48 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |     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(", "), | 
					
						
							| 
									
										
										
										
											2022-01-14 19:34:00 +01:00
										 |  |  |     ]).AsMarkdown() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |     md.replace(/\n\n\n+/g, "\n\n") | 
					
						
							| 
									
										
										
										
											2022-01-26 21:40:38 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |     writeFileSync(filename, md) | 
					
						
							| 
									
										
										
										
											2021-06-15 00:28:59 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2021-03-13 19:07:11 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-27 22:16:28 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * The wikitable is updated as some tools show an overview of apps based on the wiki. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2022-11-02 13:47:34 +01:00
										 |  |  | function generateWikipage() { | 
					
						
							|  |  |  |     function generateWikiEntry(layout: { | 
					
						
							|  |  |  |         hideFromOverview: boolean | 
					
						
							|  |  |  |         id: string | 
					
						
							|  |  |  |         shortDescription: any | 
					
						
							|  |  |  |     }) { | 
					
						
							| 
									
										
										
										
											2022-10-27 22:03:41 +02:00
										 |  |  |         if (layout.hideFromOverview) { | 
					
						
							| 
									
										
										
										
											2022-11-02 13:47:34 +01:00
										 |  |  |             return "" | 
					
						
							| 
									
										
										
										
											2022-10-27 22:03:41 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const languagesInDescr = [] | 
					
						
							|  |  |  |         for (const shortDescriptionKey in layout.shortDescription) { | 
					
						
							|  |  |  |             languagesInDescr.push(shortDescriptionKey) | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-02 13:47:34 +01:00
										 |  |  |         const languages = languagesInDescr.map((ln) => `{{#language:${ln}|en}}`).join(", ") | 
					
						
							|  |  |  |         let auth = "Yes" | 
					
						
							| 
									
										
										
										
											2022-10-27 22:03:41 +02:00
										 |  |  |         return `{{service_item
 | 
					
						
							|  |  |  | |name= [https://mapcomplete.osm.be/${layout.id} ${layout.id}]
 | 
					
						
							|  |  |  | |region= Worldwide | 
					
						
							|  |  |  | |lang= ${languages} | 
					
						
							|  |  |  | |descr= A MapComplete theme: ${Translations.T(layout.shortDescription) | 
					
						
							|  |  |  |             .textFor("en") | 
					
						
							|  |  |  |             .replace("<a href='", "[[") | 
					
						
							| 
									
										
										
										
											2022-11-02 13:47:34 +01:00
										 |  |  |             .replace(/'>.*<\/a>/, "]]")} | 
					
						
							| 
									
										
										
										
											2022-10-27 22:03:41 +02:00
										 |  |  | |material= {{yes|[https://mapcomplete.osm.be/ ${auth}]}}
 | 
					
						
							|  |  |  | |image= MapComplete_Screenshot.png | 
					
						
							|  |  |  | |genre= POI, editor, ${layout.id} | 
					
						
							|  |  |  | }}`
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-02 13:47:34 +01:00
										 |  |  |     let wikiPage = | 
					
						
							|  |  |  |         '{|class="wikitable sortable"\n' + | 
					
						
							| 
									
										
										
										
											2022-10-27 22:03:41 +02:00
										 |  |  |         "! Name, link !! Genre !! Covered region !! Language !! Description !! Free materials !! Image\n" + | 
					
						
							| 
									
										
										
										
											2022-11-02 13:47:34 +01:00
										 |  |  |         "|-" | 
					
						
							| 
									
										
										
										
											2022-10-27 22:03:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-02 13:47:34 +01:00
										 |  |  |     for (const layout of themeOverview["default"] ?? themeOverview) { | 
					
						
							| 
									
										
										
										
											2022-10-27 22:03:41 +02:00
										 |  |  |         if (layout.hideFromOverview) { | 
					
						
							| 
									
										
										
										
											2022-11-02 13:47:34 +01:00
										 |  |  |             continue | 
					
						
							| 
									
										
										
										
											2022-10-27 22:03:41 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-11-02 13:47:34 +01:00
										 |  |  |         wikiPage += "\n" + generateWikiEntry(layout) | 
					
						
							| 
									
										
										
										
											2022-10-27 22:03:41 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     wikiPage += "\n|}" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     writeFile("Docs/wikiIndex.txt", wikiPage, (err) => { | 
					
						
							|  |  |  |         if (err !== null) { | 
					
						
							| 
									
										
										
										
											2022-11-02 13:47:34 +01:00
										 |  |  |             console.log("Could not save wikiindex", err) | 
					
						
							| 
									
										
										
										
											2022-10-27 22:03:41 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-11-02 13:47:34 +01:00
										 |  |  |     }) | 
					
						
							| 
									
										
										
										
											2022-10-27 22:03:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-14 19:34:00 +01:00
										 |  |  | console.log("Starting documentation generation...") | 
					
						
							| 
									
										
										
										
											2022-10-27 22:16:28 +02:00
										 |  |  | generateWikipage() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-06 16:12:01 +02:00
										 |  |  | AllKnownLayouts.GenOverviewsForSingleLayer((layer, element, inlineSource) => { | 
					
						
							| 
									
										
										
										
											2022-01-14 19:34:00 +01:00
										 |  |  |     console.log("Exporting ", layer.id) | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |     if (!existsSync("./Docs/Layers")) { | 
					
						
							| 
									
										
										
										
											2022-04-06 16:12:01 +02:00
										 |  |  |         mkdirSync("./Docs/Layers") | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     let source: string = `assets/layers/${layer.id}/${layer.id}.json` | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |     if (inlineSource !== undefined) { | 
					
						
							| 
									
										
										
										
											2022-04-06 16:12:01 +02:00
										 |  |  |         source = `assets/themes/${inlineSource}/${inlineSource}.json` | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |     WriteFile("./Docs/Layers/" + layer.id + ".md", element, [source], { noTableOfContents: true }) | 
					
						
							| 
									
										
										
										
											2022-01-14 19:34:00 +01:00
										 |  |  | }) | 
					
						
							| 
									
										
										
										
											2022-11-30 21:38:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-16 13:40:25 +01:00
										 |  |  | Array.from(AllKnownLayouts.allKnownLayouts.values()).map((theme) => { | 
					
						
							|  |  |  |     const docs = AllKnownLayouts.GenerateDocumentationForTheme(theme) | 
					
						
							|  |  |  |     WriteFile( | 
					
						
							|  |  |  |         "./Docs/Themes/" + theme.id + ".md", | 
					
						
							|  |  |  |         docs, | 
					
						
							|  |  |  |         [`assets/themes/${theme.id}/${theme.id}.json`], | 
					
						
							|  |  |  |         { noTableOfContents: true } | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2022-11-30 21:38:50 +01:00
										 |  |  | }) | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | WriteFile("./Docs/SpecialRenderings.md", SpecialVisualizations.HelpMessage(), [ | 
					
						
							|  |  |  |     "UI/SpecialVisualizations.ts", | 
					
						
							|  |  |  | ]) | 
					
						
							|  |  |  | WriteFile( | 
					
						
							|  |  |  |     "./Docs/CalculatedTags.md", | 
					
						
							|  |  |  |     new Combine([ | 
					
						
							|  |  |  |         new Title("Metatags", 1), | 
					
						
							|  |  |  |         SimpleMetaTaggers.HelpText(), | 
					
						
							|  |  |  |         ExtraFunctions.HelpText(), | 
					
						
							|  |  |  |     ]).SetClass("flex-col"), | 
					
						
							|  |  |  |     ["Logic/SimpleMetaTagger.ts", "Logic/ExtraFunctions.ts"] | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | WriteFile("./Docs/SpecialInputElements.md", ValidatedTextField.HelpText(), [ | 
					
						
							|  |  |  |     "UI/Input/ValidatedTextField.ts", | 
					
						
							|  |  |  | ]) | 
					
						
							|  |  |  | WriteFile("./Docs/BuiltinLayers.md", AllKnownLayouts.GenLayerOverviewText(), [ | 
					
						
							|  |  |  |     "Customizations/AllKnownLayouts.ts", | 
					
						
							|  |  |  | ]) | 
					
						
							|  |  |  | WriteFile("./Docs/BuiltinQuestions.md", SharedTagRenderings.HelpText(), [ | 
					
						
							|  |  |  |     "Customizations/SharedTagRenderings.ts", | 
					
						
							|  |  |  |     "assets/tagRenderings/questions.json", | 
					
						
							|  |  |  | ]) | 
					
						
							| 
									
										
										
										
											2022-01-14 19:34:00 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-29 02:45:59 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2022-02-04 01:05:35 +01:00
										 |  |  |     // Generate the builtinIndex which shows interlayer dependencies
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |     var layers = ScriptUtils.getLayerFiles().map((f) => f.parsed) | 
					
						
							|  |  |  |     var builtinsPerLayer = new Map<string, string[]>() | 
					
						
							|  |  |  |     var layersUsingBuiltin = new Map<string /* Builtin */, string[]>() | 
					
						
							| 
									
										
										
										
											2022-01-29 02:45:59 +01:00
										 |  |  |     for (const layer of layers) { | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         if (layer.tagRenderings === undefined) { | 
					
						
							| 
									
										
										
										
											2022-01-29 02:45:59 +01:00
										 |  |  |             continue | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         const usedBuiltins: string[] = [] | 
					
						
							| 
									
										
										
										
											2022-01-29 02:45:59 +01:00
										 |  |  |         for (const tagRendering of layer.tagRenderings) { | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             if (typeof tagRendering === "string") { | 
					
						
							| 
									
										
										
										
											2022-01-29 02:45:59 +01:00
										 |  |  |                 usedBuiltins.push(tagRendering) | 
					
						
							|  |  |  |                 continue | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             if (tagRendering["builtin"] !== undefined) { | 
					
						
							| 
									
										
										
										
											2022-01-29 02:45:59 +01:00
										 |  |  |                 const builtins = tagRendering["builtin"] | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                 if (typeof builtins === "string") { | 
					
						
							| 
									
										
										
										
											2022-01-29 02:45:59 +01:00
										 |  |  |                     usedBuiltins.push(builtins) | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                 } else { | 
					
						
							| 
									
										
										
										
											2022-01-29 02:45:59 +01:00
										 |  |  |                     usedBuiltins.push(...builtins) | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         for (const usedBuiltin of usedBuiltins) { | 
					
						
							|  |  |  |             var using = layersUsingBuiltin.get(usedBuiltin) | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             if (using === undefined) { | 
					
						
							| 
									
										
										
										
											2022-01-29 02:45:59 +01:00
										 |  |  |                 layersUsingBuiltin.set(usedBuiltin, [layer.id]) | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             } else { | 
					
						
							| 
									
										
										
										
											2022-01-29 02:45:59 +01:00
										 |  |  |                 using.push(layer.id) | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-29 02:45:59 +01:00
										 |  |  |         builtinsPerLayer.set(layer.id, usedBuiltins) | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-29 02:45:59 +01:00
										 |  |  |     const docs = new Combine([ | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         new Title("Index of builtin TagRendering", 1), | 
					
						
							| 
									
										
										
										
											2022-01-29 02:45:59 +01:00
										 |  |  |         new Title("Existing builtin tagrenderings", 2), | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         ...Array.from(layersUsingBuiltin.entries()).map(([builtin, usedByLayers]) => | 
					
						
							|  |  |  |             new Combine([new Title(builtin), new List(usedByLayers)]).SetClass("flex flex-col") | 
					
						
							|  |  |  |         ), | 
					
						
							| 
									
										
										
										
											2022-01-29 02:45:59 +01:00
										 |  |  |     ]).SetClass("flex flex-col") | 
					
						
							|  |  |  |     WriteFile("./Docs/BuiltinIndex.md", docs, ["assets/layers/*.json"]) | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2022-01-14 19:34:00 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | Minimap.createMiniMap = (_) => { | 
					
						
							|  |  |  |     console.log("Not creating a minimap, it is disabled") | 
					
						
							| 
									
										
										
										
											2021-10-28 03:21:17 +02:00
										 |  |  |     return undefined | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | WriteFile("./Docs/URL_Parameters.md", QueryParameterDocumentation.GenerateQueryParameterDocs(), [ | 
					
						
							|  |  |  |     "Logic/Web/QueryParameters.ts", | 
					
						
							|  |  |  |     "UI/QueryParameterDocumentation.ts", | 
					
						
							|  |  |  | ]) | 
					
						
							| 
									
										
										
										
											2022-12-24 03:44:21 +01:00
										 |  |  | if (fakedom === undefined || window === undefined) { | 
					
						
							|  |  |  |     throw "FakeDom not initialized" | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | new DefaultGUI( | 
					
						
							|  |  |  |     new FeaturePipelineState(new LayoutConfig(<any>bookcases)), | 
					
						
							|  |  |  |     new DefaultGuiState() | 
					
						
							|  |  |  | ).setup() | 
					
						
							| 
									
										
										
										
											2022-10-27 22:16:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-24 03:44:21 +01:00
										 |  |  | WriteFile("./Docs/Hotkeys.md", Hotkeys.generateDocumentation(), []) | 
					
						
							| 
									
										
										
										
											2021-03-22 01:06:24 +01:00
										 |  |  | console.log("Generated docs") |