diff --git a/scripts/ScriptUtils.ts b/scripts/ScriptUtils.ts index f1f2a6547..7e54ce5f0 100644 --- a/scripts/ScriptUtils.ts +++ b/scripts/ScriptUtils.ts @@ -274,4 +274,24 @@ export default class ScriptUtils { }) return Promise.race([requestPromise, timeoutPromise]) } + + /** + * Will inspect the path. If something like `./assets/layer/sport_pitches/{sport}.svg` is entered, + * all files possibly matching this path will be returned. + * + * If not, [path] is returned + * + * ScriptUtils.detectVariablePaths("./assets/layers/sport_pitch/{sport}.svg").indexOf("./assets/layers/sport_pitch/baseball.svg") >= 0 // => true + */ + static detectVariablePaths(path: string) { + const splitPath = path.match(/(.*)\{(.+)\}(.*)/) + if(!splitPath){ + return [path] + } + const [_, head] = splitPath + const headPath = head.slice(0, head.lastIndexOf("/")) + const allPossibleMatchingFiles = ScriptUtils.readDirRecSync(headPath) + const pathAsRegex = path.replaceAll(/\{.+}/g, ".+") + return allPossibleMatchingFiles.filter(pth => pth.match(pathAsRegex)) + } } diff --git a/scripts/generateLayerOverview.ts b/scripts/generateLayerOverview.ts index c567cf678..0b4a718d0 100644 --- a/scripts/generateLayerOverview.ts +++ b/scripts/generateLayerOverview.ts @@ -895,9 +895,11 @@ class LayerOverviewUtils extends Script { ) } if (printAssets) { + console.log("Creating needed_assets-file") const images = Lists.dedup( Array.from(sharedThemes.values()).flatMap((th) => th._usedImages ?? []) - ) + ).flatMap(path => ScriptUtils.detectVariablePaths(path)) + writeFileSync("needed_assets.csv", images.join("\n")) console.log("Written needed_assets.csv") }