forked from MapComplete/MapComplete
		
	Scripts: automatically reorder layers and themes on generateLayerOverview.ts
This commit is contained in:
		
							parent
							
								
									1a7bcdca61
								
							
						
					
					
						commit
						8c5d9d6abc
					
				
					 3 changed files with 36 additions and 4 deletions
				
			
		|  | @ -11,8 +11,8 @@ import { | |||
|     ValidateThemeEnsemble, | ||||
| } from "../src/Models/ThemeConfig/Conversion/Validation" | ||||
| import { Translation } from "../src/UI/i18n/Translation" | ||||
| import { PrepareLayer } from "../src/Models/ThemeConfig/Conversion/PrepareLayer" | ||||
| import { PrepareTheme } from "../src/Models/ThemeConfig/Conversion/PrepareTheme" | ||||
| import { OrderLayer, PrepareLayer } from "../src/Models/ThemeConfig/Conversion/PrepareLayer" | ||||
| import { OrderTheme, PrepareTheme } from "../src/Models/ThemeConfig/Conversion/PrepareTheme" | ||||
| import { Conversion, DesugaringContext, DesugaringStep } from "../src/Models/ThemeConfig/Conversion/Conversion" | ||||
| import { Utils } from "../src/Utils" | ||||
| import Script from "./Script" | ||||
|  | @ -309,6 +309,37 @@ class LayerBuilder extends Conversion<object, Map<string, LayerConfigJson>> { | |||
|     } | ||||
| } | ||||
| 
 | ||||
| class ReorderFiles extends Script { | ||||
|     constructor() { | ||||
|         super("Reorders the attributes in the layers and theme files") | ||||
|     } | ||||
| 
 | ||||
|     private lintAll<T>(items: {parsed: T, path: string}[], reorder: DesugaringStep<T>){ | ||||
|         for (const item of items) { | ||||
|             const l = reorder.convertStrict(item.parsed, ConversionContext.construct([item.path], ["reorder"])) | ||||
|             const content = JSON.stringify(l, null, "  ") | ||||
|             const contentOld = JSON.stringify(item.parsed, null, "  ") | ||||
|             if(contentOld === content){ | ||||
|                 continue | ||||
|             } | ||||
|             const orig = readFileSync(item.path, "utf-8") | ||||
|             const ending = orig.endsWith("\n")? "\n" : "" | ||||
|             writeFileSync(item.path, content+ending, "utf-8") | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     async main(){ | ||||
|         console.log("Reordering layers and themes") | ||||
|         const orderL = new OrderLayer() | ||||
|         const layers =ScriptUtils.getLayerFiles() | ||||
|         this.lintAll(layers, orderL) | ||||
| 
 | ||||
|         const orderT = new OrderTheme() | ||||
|         const themes = ScriptUtils.getThemeFiles() | ||||
|         this.lintAll(themes, orderT) | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| class LayerOverviewUtils extends Script { | ||||
|     public static readonly layerPath = "./public/assets/generated/layers/" | ||||
|     public static readonly themePath = "./public/assets/generated/themes/" | ||||
|  | @ -1163,3 +1194,4 @@ class LayerOverviewUtils extends Script { | |||
| 
 | ||||
| new GenerateFavouritesLayer().run() | ||||
| new LayerOverviewUtils().run() | ||||
| new ReorderFiles().run() | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue