I have a directory with subdirectories, and the code checks if these subdirectories are valid by querying the settings.json
of them, if it has (which is required to be valid), however $.getJSON
does not work by returning the contents of the file, and if I pass it as an argument to a function, however I need the getThemes
function to return the list of valid subdirectories when all $.getJSON
are ready, code:
getDirectories = (srcpath) => {
return fs.readdirSync(srcpath).filter(function(file)
{
return !['.', '..'].includes(file) && fs.statSync(path.join(srcpath, file)).isDirectory();
});
}
getThemes = () => {
let directories = getDirectories(path.join(process.cwd(), 'themes'));
let out = [];
for (let dir of directories)
$.getJSON(path.join('themes', dir, 'settings.json')).done((json) => {
if (json.version && json.name)
out.push(json)
})
return out
}