forked from MapComplete/MapComplete
47 lines
1.6 KiB
TypeScript
47 lines
1.6 KiB
TypeScript
import ScriptUtils from "./ScriptUtils"
|
|
import { writeFileSync } from "fs"
|
|
import {
|
|
FixLegacyTheme,
|
|
UpdateLegacyLayer,
|
|
} from "../src/Models/ThemeConfig/Conversion/LegacyJsonConvert"
|
|
import { LayerConfigJson } from "../src/Models/ThemeConfig/Json/LayerConfigJson"
|
|
import { ConversionContext } from "../src/Models/ThemeConfig/Conversion/ConversionContext"
|
|
|
|
/*
|
|
* This script reads all theme and layer files and reformats them inplace
|
|
* Use with caution, make a commit beforehand!
|
|
*/
|
|
|
|
const layerFiles = ScriptUtils.getLayerFiles()
|
|
for (const layerFile of layerFiles) {
|
|
try {
|
|
const fixed = <LayerConfigJson>(
|
|
new UpdateLegacyLayer().convertStrict(
|
|
layerFile.parsed,
|
|
ConversionContext.construct([layerFile.path.split("/").at(-1)], ["update legacy"])
|
|
)
|
|
)
|
|
writeFileSync(layerFile.path, JSON.stringify(fixed, null, " ") + "\n")
|
|
} catch (e) {
|
|
console.error("COULD NOT LINT LAYER" + layerFile.path + ":\n\t" + e)
|
|
}
|
|
}
|
|
|
|
const themeFiles = ScriptUtils.getThemeFiles()
|
|
for (const themeFile of themeFiles) {
|
|
try {
|
|
const fixed = new FixLegacyTheme().convertStrict(
|
|
themeFile.parsed,
|
|
ConversionContext.construct([themeFile.path.split("/").at(-1)], ["update legacy layer"])
|
|
)
|
|
|
|
// extractInlineLayer(fixed)
|
|
const endsWithNewline = themeFile.raw.at(-1) === "\n"
|
|
writeFileSync(
|
|
themeFile.path,
|
|
JSON.stringify(fixed, null, " ") + (endsWithNewline ? "\n" : "")
|
|
)
|
|
} catch (e) {
|
|
console.error("COULD NOT LINT THEME" + themeFile.path + ":\n\t" + e)
|
|
}
|
|
}
|