Skip to content

Instantly share code, notes, and snippets.

@MaikelVeen
Last active January 10, 2021 00:31
Show Gist options
  • Save MaikelVeen/7c3563968dddb72f0818ce32c59b7109 to your computer and use it in GitHub Desktop.
Save MaikelVeen/7c3563968dddb72f0818ce32c59b7109 to your computer and use it in GitHub Desktop.
GetPathsFromBuildFolder
const GetPathsFromBuildFolder = (dir: string, urlList: Array<Url>, host: string, basePath: string): Array<Url> => {
const files: string[] = fs.readdirSync(dir);
urlList = urlList || [];
files.forEach((file) => {
if (fs.statSync(dir + file).isDirectory()) {
urlList = GetPathsFromBuildFolder(dir + file + '/', urlList, host, basePath);
} else {
if (path.extname(file) == '.json') {
let route = path.join(dir + file.substring(0, file.length - 5));
route = route.replace(basePath, '/');
urlList.push({ host: host, route: route });
}
}
});
return urlList;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment