| 
									
										
										
										
											2021-09-26 18:21:29 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* | 
					
						
							|  |  |  |  * This script reads all theme and layer files and reformats them inplace | 
					
						
							|  |  |  |  * Use with caution, make a commit beforehand! | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ScriptUtils from "./ScriptUtils"; | 
					
						
							|  |  |  | import {readFileSync, writeFileSync} from "fs"; | 
					
						
							|  |  |  | import {tag} from "@turf/turf"; | 
					
						
							| 
									
										
										
										
											2021-09-26 19:56:40 +02:00
										 |  |  | import {LayerConfigJson} from "../Models/ThemeConfig/Json/LayerConfigJson"; | 
					
						
							| 
									
										
										
										
											2021-09-26 18:21:29 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-26 19:56:40 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * In place fix | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | function fixLayerConfig(config: LayerConfigJson) : void{ | 
					
						
							| 
									
										
										
										
											2021-09-26 19:59:51 +02:00
										 |  |  |     if(config.tagRenderings === undefined){ | 
					
						
							|  |  |  |         return | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2021-09-26 19:56:40 +02:00
										 |  |  |     for (const tagRendering of config.tagRenderings) { | 
					
						
							| 
									
										
										
										
											2021-09-26 18:21:29 +02:00
										 |  |  |         if(tagRendering["#"] !== undefined){ | 
					
						
							|  |  |  |             tagRendering["id"] = tagRendering["#"] | 
					
						
							|  |  |  |             delete tagRendering["#"] | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if(tagRendering["id"] === undefined){ | 
					
						
							|  |  |  |             if(tagRendering["freeform"]?.key !== undefined ) { | 
					
						
							| 
									
										
										
										
											2021-09-26 19:56:40 +02:00
										 |  |  |                 tagRendering["id"] = config.id+"-"+tagRendering["freeform"]["key"] | 
					
						
							| 
									
										
										
										
											2021-09-26 18:21:29 +02:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-09-26 19:56:40 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const layerFiles = ScriptUtils.getLayerFiles(); | 
					
						
							|  |  |  | for (const layerFile of layerFiles) { | 
					
						
							|  |  |  |     fixLayerConfig(layerFile.parsed) | 
					
						
							| 
									
										
										
										
											2021-09-26 18:21:29 +02:00
										 |  |  |     writeFileSync(layerFile.path, JSON.stringify(layerFile.parsed, null, "    ")) | 
					
						
							| 
									
										
										
										
											2021-09-26 19:56:40 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2021-09-26 19:59:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-26 19:56:40 +02:00
										 |  |  | const themeFiles = ScriptUtils.getThemeFiles() | 
					
						
							|  |  |  | for (const themeFile of themeFiles) { | 
					
						
							| 
									
										
										
										
											2021-09-26 19:58:11 +02:00
										 |  |  |     for (const layerConfig of themeFile.parsed.layers ?? []) { | 
					
						
							| 
									
										
										
										
											2021-09-26 19:56:40 +02:00
										 |  |  |         if(typeof layerConfig === "string" || layerConfig["builtin"]!== undefined){ | 
					
						
							|  |  |  |             continue | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         // @ts-ignore
 | 
					
						
							|  |  |  |         fixLayerConfig(layerConfig) | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-10-19 02:03:52 +02:00
										 |  |  |      | 
					
						
							|  |  |  |     if(themeFile.parsed["roamingRenderings"] !== undefined && themeFile.parsed["roamingRenderings"].length == 0){ | 
					
						
							|  |  |  |         delete themeFile.parsed["roamingRenderings"] | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2021-09-26 19:59:51 +02:00
										 |  |  |     writeFileSync(themeFile.path, JSON.stringify(themeFile.parsed, null, "  ")) | 
					
						
							| 
									
										
										
										
											2021-09-26 19:58:11 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2021-10-19 02:03:52 +02:00
										 |  |  | //*/
 |