get-dashboard-paths.ts 964 B

12345678910111213141516171819202122232425262728
  1. import path from 'path';
  2. import { PluginInfo } from '../types.js';
  3. /**
  4. * Returns an array of the paths to plugins, based on the info provided by the ConfigLoaderApi.
  5. */
  6. export function getDashboardPaths(pluginInfo: PluginInfo[]) {
  7. return (
  8. pluginInfo
  9. ?.flatMap(({ dashboardEntryPath, sourcePluginPath, pluginPath }) => {
  10. if (!dashboardEntryPath) {
  11. return [];
  12. }
  13. const sourcePaths = [];
  14. if (sourcePluginPath) {
  15. sourcePaths.push(
  16. path.join(path.dirname(sourcePluginPath), path.dirname(dashboardEntryPath)),
  17. );
  18. }
  19. if (pluginPath) {
  20. sourcePaths.push(path.join(path.dirname(pluginPath), path.dirname(dashboardEntryPath)));
  21. }
  22. return sourcePaths;
  23. })
  24. .filter(x => x != null) ?? []
  25. );
  26. }