mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-30 11:54:33 +03:00
Refactored remaining function in package-json lib to use async-await
- this helps simplify the code and gets rid of Promise chaining - apparently I can't easily use an async function within filter, so I've left it for now
This commit is contained in:
parent
18b87d9734
commit
d4b15141a0
@ -150,10 +150,10 @@ module.exports = class PackageJson {
|
||||
}
|
||||
}
|
||||
|
||||
readPackages(packagePath) {
|
||||
const self = this;
|
||||
async readPackages(packagePath) {
|
||||
const dirContents = await fs.readdir(packagePath);
|
||||
|
||||
return Promise.resolve(fs.readdir(packagePath))
|
||||
const packageNames = dirContents
|
||||
.filter(function (packageName) {
|
||||
// Filter out things which are not packages by regex
|
||||
if (packageName.match(notAPackageRegex)) {
|
||||
@ -163,13 +163,14 @@ module.exports = class PackageJson {
|
||||
return fs.stat(join(packagePath, packageName)).then(function (stat) {
|
||||
return stat.isDirectory();
|
||||
});
|
||||
})
|
||||
.map(function readPackageJson(packageName) {
|
||||
const absolutePath = join(packagePath, packageName);
|
||||
return self.processPackage(absolutePath, packageName);
|
||||
})
|
||||
.then(function (packages) {
|
||||
return _.keyBy(packages, 'name');
|
||||
});
|
||||
|
||||
const packages = await Promise.all(packageNames
|
||||
.map((packageName) => {
|
||||
const absolutePath = join(packagePath, packageName);
|
||||
return this.processPackage(absolutePath, packageName);
|
||||
}));
|
||||
|
||||
return _.keyBy(packages, 'name');
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user