All files / generateExportFile/utils createIndexTsFileContent.ts

100% Statements 18/18
100% Branches 6/6
100% Functions 3/3
100% Lines 18/18

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 374x   4x 13x 13x 26x           13x 18x 18x         18x 17x   1x     13x 13x 27x 27x 15x     27x     13x    
import * as path from "path";
 
export const createIndexTsFileContent = ({
  fileNames,
  folderNames,
  stripFileExts = ["js", "ts"]
}: {
  fileNames: string[];
  folderNames: string[];
  stripFileExts?: string[];
}): string => {
  const transformedFileName = fileNames.map(fileName => {
    const parseFileName = path.parse(fileName);
    const transformedFileExt = parseFileName.ext.substr(
      1,
      parseFileName.ext.length - 1
    );
 
    if (stripFileExts.includes(transformedFileExt)) {
      return parseFileName.name;
    }
    return fileName;
  });
 
  const names = [...transformedFileName, ...folderNames];
  const fileContent = names.reduce((fileContent, name, index) => {
    fileContent += `export * from './${name}'`;
    if (index < names.length - 1) {
      fileContent += "\n";
    }
 
    return fileContent;
  }, "");
 
  return fileContent;
};