This commit is contained in:
Pieter Vander Vennet 2025-09-20 18:22:05 +02:00
parent 5c382a7721
commit a394853a51
2 changed files with 23 additions and 1 deletions

View file

@ -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))
}
}

View file

@ -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")
}