Reorder script
This commit is contained in:
parent
e13e9f652c
commit
c274a01965
8 changed files with 628 additions and 570 deletions
|
@ -8,12 +8,22 @@ import Translations from "../src/UI/i18n/Translations"
|
|||
import { Translation } from "../src/UI/i18n/Translation"
|
||||
import { LayerConfigJson } from "../src/Models/ThemeConfig/Json/LayerConfigJson"
|
||||
import { ConversionContext } from "../src/Models/ThemeConfig/Conversion/Conversion"
|
||||
import themeconfig from "../src/assets/schemas/layoutconfigmeta.json"
|
||||
import layerconfig from "../src/assets/schemas/layerconfigmeta.json"
|
||||
|
||||
import { Utils } from "../src/Utils"
|
||||
import { ConfigMeta } from "../src/UI/Studio/configMeta"
|
||||
|
||||
/*
|
||||
* This script reads all theme and layer files and reformats them inplace
|
||||
* Use with caution, make a commit beforehand!
|
||||
*/
|
||||
|
||||
const themeAttributesOrder = Utils.Dedup(
|
||||
(<ConfigMeta[]>themeconfig).filter((c) => c.path.length === 1).map((c) => c.path[0])
|
||||
)
|
||||
const layerAttributesOrder = Utils.Dedup(
|
||||
(<ConfigMeta[]>layerconfig).filter((c) => c.path.length === 1).map((c) => c.path[0])
|
||||
)
|
||||
const t: Translation = Translations.t.general.add.addNew
|
||||
t.OnEveryLanguage((txt, ln) => {
|
||||
console.log(ln, txt)
|
||||
|
@ -31,6 +41,19 @@ const articles = {
|
|||
pt_BR : 'uma',//*/
|
||||
}
|
||||
|
||||
function reorder(object: object, order: string[]) {
|
||||
const allKeys = new Set<string>(Object.keys(object))
|
||||
const copy = {}
|
||||
for (const key of order) {
|
||||
copy[key] = object[key]
|
||||
allKeys.delete(key)
|
||||
}
|
||||
for (const key of allKeys) {
|
||||
copy[key] = object[key]
|
||||
}
|
||||
return copy
|
||||
}
|
||||
|
||||
function addArticleToPresets(layerConfig: { presets?: { title: any }[] }) {
|
||||
/*
|
||||
if(layerConfig.presets === undefined){
|
||||
|
@ -73,7 +96,8 @@ for (const layerFile of layerFiles) {
|
|||
)
|
||||
)
|
||||
addArticleToPresets(fixed)
|
||||
writeFileSync(layerFile.path, JSON.stringify(fixed, null, " ") + "\n")
|
||||
const reordered = reorder(fixed, layerAttributesOrder)
|
||||
writeFileSync(layerFile.path, JSON.stringify(reordered, null, " ") + "\n")
|
||||
} catch (e) {
|
||||
console.error("COULD NOT LINT LAYER" + layerFile.path + ":\n\t" + e)
|
||||
}
|
||||
|
@ -93,9 +117,10 @@ for (const themeFile of themeFiles) {
|
|||
}
|
||||
// extractInlineLayer(fixed)
|
||||
const endsWithNewline = themeFile.raw.at(-1) === "\n"
|
||||
const ordered = reorder(fixed, themeAttributesOrder)
|
||||
writeFileSync(
|
||||
themeFile.path,
|
||||
JSON.stringify(fixed, null, " ") + (endsWithNewline ? "\n" : "")
|
||||
JSON.stringify(ordered, null, " ") + (endsWithNewline ? "\n" : "")
|
||||
)
|
||||
} catch (e) {
|
||||
console.error("COULD NOT LINT THEME" + themeFile.path + ":\n\t" + e)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue