diff --git a/scripts/extractLayer.ts b/scripts/extractLayer.ts new file mode 100644 index 000000000..e8600d6ae --- /dev/null +++ b/scripts/extractLayer.ts @@ -0,0 +1,53 @@ +import {LayoutConfigJson} from "../Models/ThemeConfig/Json/LayoutConfigJson"; +import {LayerConfigJson} from "../Models/ThemeConfig/Json/LayerConfigJson"; +import {existsSync, mkdirSync, readFileSync, writeFileSync} from "fs"; + +function main(args: string[]){ + if(args.length === 0){ + console.log("Extracts an inline layer from a theme and places it in it's own layer directory.") + console.log("USAGE: ts-node scripts/extractLayerFromTheme.ts ") + console.log("(Invoke with only the themename to see which layers can be extracted)") + } + const themeId = args[0] + const layerId = args[1] + + const themePath = "./assets/themes/"+themeId+"/"+themeId+".json" + const contents = JSON.parse(readFileSync(themePath, "UTF-8")) + const layers = contents.layers.filter(l => { + if(typeof l === "string"){ + return false + } + if(l["override"] !== undefined){ + return false + } + return true + }) + + if(layers.length === 0){ + console.log("No layers can be extracted from this theme. The "+contents.layers.length+" layers are already substituted layers") + return + } + + const layerConfig = layers.find(l => l.id === layerId) + if(layerId === undefined || layerConfig === undefined){ + if(layerConfig === undefined){ + console.error( "Layer "+layerId+" not found as inline layer") + } + console.log("Layers available for extraction are:") + console.log(layers.map(l => l.id).join("\n")) + return + } + + + const dir = "./assets/layers/"+layerId + if(!existsSync(dir)){ + mkdirSync(dir) + } + writeFileSync(dir+"/"+layerId+".json", JSON.stringify(layerConfig, null, " ")) + + const index = contents.layers.findIndex(l => l["id"] === layerId) + contents.layers[index] = layerId + writeFileSync(themePath, JSON.stringify(contents, null, " ")) +} + +main(process.argv.slice(2)) \ No newline at end of file diff --git a/scripts/lint.ts b/scripts/lint.ts index 3ac0cc076..220bb3cc2 100644 --- a/scripts/lint.ts +++ b/scripts/lint.ts @@ -57,22 +57,6 @@ function addArticleToPresets(layerConfig: {presets?: {title: any}[]}){ //*/ } -function extractInlineLayer(theme: LayoutConfigJson){ - for (let i = 0; i < theme.layers.length; i++){ - const layer = theme.layers[i]; - if(typeof layer === "string"){ - continue - } - if(layer["override"] !== undefined){ - continue - } - const l = layer - mkdirSync("./assets/layers/"+l.id) - writeFileSync("./assets/layers/"+l.id+"/"+l.id+".json", JSON.stringify(l, null, " ")) - theme.layers[i] = l.id - } -} - const layerFiles = ScriptUtils.getLayerFiles(); for (const layerFile of layerFiles) { try {