forked from MapComplete/MapComplete
		
	First part of a huge refactoring
This commit is contained in:
		
							parent
							
								
									0c22b15c8d
								
							
						
					
					
						commit
						11150a258d
					
				
					 56 changed files with 1425 additions and 1324 deletions
				
			
		|  | @ -1,4 +1,4 @@ | |||
| import {existsSync, mkdirSync, readFileSync, writeFile, writeFileSync} from "fs"; | ||||
| import {appendFileSync, existsSync, mkdirSync, readFileSync, writeFile, writeFileSync} from "fs"; | ||||
| import Locale from "../UI/i18n/Locale"; | ||||
| import Translations from "../UI/i18n/Translations"; | ||||
| import {Translation} from "../UI/i18n/Translation"; | ||||
|  | @ -8,6 +8,8 @@ import {LayoutConfigJson} from "../Models/ThemeConfig/Json/LayoutConfigJson"; | |||
| import LayoutConfig from "../Models/ThemeConfig/LayoutConfig"; | ||||
| 
 | ||||
| const sharp = require('sharp'); | ||||
| const template = readFileSync("theme.html", "utf8"); | ||||
| const codeTemplate = readFileSync("index_theme.ts.template", "utf8"); | ||||
| 
 | ||||
| 
 | ||||
| function enc(str: string): string { | ||||
|  | @ -106,7 +108,6 @@ async function createManifest(layout: LayoutConfig) { | |||
|     }; | ||||
| } | ||||
| 
 | ||||
| const template = readFileSync("index.html", "utf8"); | ||||
| 
 | ||||
| async function createLandingPage(layout: LayoutConfig, manifest) { | ||||
| 
 | ||||
|  | @ -159,7 +160,8 @@ async function createLandingPage(layout: LayoutConfig, manifest) { | |||
| 
 | ||||
|     let output = template | ||||
|         .replace("Loading MapComplete, hang on...", `Loading MapComplete theme <i>${ogTitle}</i>...`) | ||||
|         .replace(/<!-- THEME-SPECIFIC -->.*<!-- THEME-SPECIFIC-END-->/s, themeSpecific); | ||||
|         .replace(/<!-- THEME-SPECIFIC -->.*<!-- THEME-SPECIFIC-END-->/s, themeSpecific) | ||||
|         .replace("<script src=\"./index.ts\"></script>", `<script src='./index_${layout.id}.ts'></script>`); | ||||
| 
 | ||||
|     try { | ||||
|         output = output | ||||
|  | @ -172,12 +174,18 @@ async function createLandingPage(layout: LayoutConfig, manifest) { | |||
|     return output; | ||||
| } | ||||
| 
 | ||||
| async function createIndexFor(theme: LayoutConfig){ | ||||
|     const filename = "index_"+theme.id+".ts" | ||||
|     writeFileSync(filename, `import * as themeConfig from "./assets/generated/themes/${theme.id}.json"\n`) | ||||
|     appendFileSync(filename, codeTemplate) | ||||
| } | ||||
| 
 | ||||
| const generatedDir = "./assets/generated"; | ||||
| if (!existsSync(generatedDir)) { | ||||
|     mkdirSync(generatedDir) | ||||
| } | ||||
| 
 | ||||
| const blacklist = ["", "test", ".", "..", "manifest", "index", "land", "preferences", "account", "openstreetmap", "custom"] | ||||
| const blacklist = ["", "test", ".", "..", "manifest", "index", "land", "preferences", "account", "openstreetmap", "custom","theme"] | ||||
| // @ts-ignore
 | ||||
| const all: LayoutConfigJson[] = all_known_layouts.themes; | ||||
| for (const i in all) { | ||||
|  | @ -202,6 +210,7 @@ for (const i in all) { | |||
|         createLandingPage(layout, manifObj).then(landing => { | ||||
|             writeFile(enc(layout.id) + ".html", landing, err) | ||||
|         }); | ||||
|         createIndexFor(layout) | ||||
|     }).catch(e => console.log("Could not generate the manifest: ", e)) | ||||
| 
 | ||||
| } | ||||
|  | @ -224,6 +233,4 @@ createManifest(new LayoutConfig({ | |||
| }) | ||||
| 
 | ||||
| 
 | ||||
| console.log("Counting all translations") | ||||
| Translations.CountTranslations(); | ||||
| console.log("All done!"); | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue