All files / src/lib/pluginManager project.ts

44.44% Statements 8/18
0% Branches 0/3
0% Functions 0/1
41.18% Lines 7/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 291x 1x 1x 1x   1x   1x   1x                                      
import { readJSON } from "fs-extra";
import glob from "glob";
import { join, dirname, relative } from "path";
import { promisify } from "util";
import { InstalledPluginData } from "./types";
import { pathToPosix } from "shared/lib/helpers/path";
 
const globAsync = promisify(glob);
 
export const getPluginsInProject = async (projectPath: string) => {
  const projectRoot = dirname(projectPath);
  const pluginPaths = await globAsync(join(projectRoot, "**/plugin.json"));
  const plugins: InstalledPluginData[] = [];
  for (const pluginPath of pluginPaths) {
    try {
      const pluginJSON = await readJSON(pluginPath);
      Iif ("version" in pluginJSON && typeof pluginJSON.version === "string") {
        plugins.push({
          path: pathToPosix(relative(join(projectRoot, "plugins"), pluginPath)),
          version: pluginJSON.version,
        });
      }
    } catch (e) {
      console.error("Error: Unable to parse " + pluginPath);
    }
  }
  return plugins;
};