All files / src/find-duplicate-segments index.ts

0% Statements 0/19
0% Branches 0/7
0% Functions 0/3
0% Lines 0/19

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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75                                                                                                                                                     
import { findDuplicateSegments, DuplicateSegmentsOptions } from "./findDuplicateSegments";
import { Dependencies } from "../dependencies";
import { Plugin } from "../cli";
import { getProjectSetExecutions, printSetHeader } from "../sets";
import {
  CLI_COLOR_CYAN,
  CLI_FORMAT_BOLD,
  CLI_FORMAT_GREEN,
  CLI_FORMAT_YELLOW,
  colorize,
} from "../tester/cliFormat";
 
export async function findDuplicateSegmentsInProject(
  deps: Dependencies,
  options: DuplicateSegmentsOptions = {},
) {
  const duplicates = await findDuplicateSegments(deps, options);
 
  console.log("");
  console.log(CLI_FORMAT_BOLD, "Finding duplicate Featurevisor segments");
 
  if (duplicates.length === 0) {
    console.log(CLI_FORMAT_GREEN, "No duplicate segments found");
    return;
  }
 
  console.log(CLI_FORMAT_YELLOW, `Found ${duplicates.length} duplicate(s):`);
  console.log("");
 
  duplicates.forEach((entry) => {
    if (options.authors) {
      console.log(`  ${colorize("•", CLI_COLOR_CYAN)} Segments: ${entry.segments.join(", ")}`);
      console.log(
        `    ${colorize("Authors", CLI_COLOR_CYAN)}:  ${entry.authors && entry.authors.join(", ")}`,
      );
      console.log("");
    } else {
      console.log(`  ${colorize("•", CLI_COLOR_CYAN)} ${entry.segments.join(", ")}`);
    }
  });
}
 
export const findDuplicateSegmentsPlugin: Plugin = {
  command: "find-duplicate-segments",
  handler: async ({ rootDirectoryPath, projectConfig, datasource, parsed }) => {
    const executions = await getProjectSetExecutions(projectConfig, datasource, parsed.set);
 
    for (const execution of executions) {
      printSetHeader(projectConfig, execution.set);
 
      await findDuplicateSegmentsInProject(
        {
          rootDirectoryPath,
          projectConfig: execution.projectConfig,
          datasource: execution.datasource,
          options: parsed,
        },
        {
          authors: parsed.authors,
        },
      );
    }
  },
  examples: [
    {
      command: "find-duplicate-segments",
      description: "Find duplicate segments in the project",
    },
    {
      command: "find-duplicate-segments --authors",
      description: "Find duplicate segments in the project and list authors",
    },
  ],
};