strapi/packages/core/admin/utils/get-plugins-path.js

42 lines
1.5 KiB
JavaScript
Raw Normal View History

'use strict';
2022-12-09 10:12:18 +00:00
const { join, resolve, sep, posix } = require('path');
const fs = require('fs-extra');
2022-08-08 23:33:39 +02:00
// eslint-disable-next-line import/no-extraneous-dependencies
const glob = require('glob');
2022-06-07 18:51:32 +02:00
// Only for dev environement
const getPluginsPath = () => {
const rootPath = resolve(__dirname, '..', join('..', '..', '..', 'packages'));
2022-12-09 10:12:18 +00:00
/**
* So `glob` only supports '/' as a path separator, so we need to replace
* the path separator for the current OS with '/'. e.g. on windows it's `\`.
*
* see https://github.com/isaacs/node-glob/#windows for more information
*
* and see https://github.com/isaacs/node-glob/issues/467#issuecomment-1114240501 for the recommended fix.
*/
let corePath = join(rootPath, 'core', '*');
let pluginsPath = join(rootPath, 'plugins', '*');
if (process.platform === 'win32') {
corePath = corePath.split(sep).join(posix.sep);
pluginsPath = pluginsPath.split(sep).join(posix.sep);
}
const corePackageDirs = glob.sync(corePath);
const pluginsPackageDirs = glob.sync(pluginsPath);
2022-08-08 23:33:39 +02:00
const packageDirs = [...corePackageDirs, ...pluginsPackageDirs].filter((dir) => {
const isCoreAdmin = dir.includes('packages/core/admin');
const pathToEntryPoint = join(dir, 'admin', 'src', 'index.js');
const doesAdminFolderExist = fs.pathExistsSync(pathToEntryPoint);
return !isCoreAdmin && doesAdminFolderExist;
});
2022-08-08 23:33:39 +02:00
return packageDirs.map((dir) => resolve(__dirname, '..', join(dir, 'admin', 'src')));
};
module.exports = getPluginsPath;