strapi/packages/generators/admin/utils/getPluginList.js

31 lines
782 B
JavaScript
Raw Normal View History

2021-07-21 20:08:17 +02:00
'use strict';
const glob = require('glob');
2021-07-22 14:10:54 +02:00
const fileExistsInPackages = require('./fileExistsInPackages');
const packagesFolder = require('./packagesFolder');
2021-07-21 20:08:17 +02:00
const asyncFilter = async (array, predicate) => {
const results = await Promise.all(array.map(predicate));
return array.filter((_, index) => results[index]);
};
const getPluginList = () => {
return new Promise((resolve, reject) => {
glob(
'{core,plugins}/*',
{ ignore: ['**/node_modules'], cwd: packagesFolder },
async (err, matches) => {
if (err) {
reject(err);
}
2021-07-22 14:10:54 +02:00
const extendsAdmin = match => fileExistsInPackages(`${match}/admin/src`);
2021-07-21 20:08:17 +02:00
resolve(await asyncFilter(matches, extendsAdmin));
}
);
});
};
module.exports = getPluginList;