mapcomplete/scripts/lint.ts

47 lines
1.4 KiB
TypeScript
Raw Normal View History

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{
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:58:11 +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-09-26 19:58:11 +02:00
// writeFileSync(themeFile.path, JSON.stringify(themeFile.parsed, null, " "))
}
//*/