forked from MapComplete/MapComplete
Fix: fix #2534
This commit is contained in:
parent
5c382a7721
commit
a394853a51
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))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue