Scripts: automatically reorder layers and themes on generateLayerOverview.ts

This commit is contained in:
Pieter Vander Vennet 2025-07-06 03:07:26 +02:00
parent 1a7bcdca61
commit 8c5d9d6abc
3 changed files with 36 additions and 4 deletions

View file

@ -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()