forked from MapComplete/MapComplete
Merge branch 'master' into develop
This commit is contained in:
commit
ffdb295019
2 changed files with 23 additions and 1 deletions
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue