All files / src/lib/project loadResourceChecksums.ts

52.63% Statements 10/19
100% Branches 0/0
0% Functions 0/4
50% Lines 9/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 371x 1x 1x 1x 1x 1x   1x   1x   1x                                                  
import path from "path";
import glob from "glob";
import { promisify } from "util";
import promiseLimit from "lib/helpers/promiseLimit";
import { checksumMD5File } from "lib/helpers/checksum";
import { pathToPosix } from "shared/lib/helpers/path";
 
const globAsync = promisify(glob);
 
const CONCURRENT_RESOURCE_LOAD_COUNT = 16;
 
export const loadProjectResourceChecksums = async (
  projectPath: string
): Promise<Record<string, string>> => {
  const projectRoot = path.dirname(projectPath);
 
  const projectResources = await globAsync(
    path.join(projectRoot, "**/*.gbsres")
  );
 
  const resources = await promiseLimit(
    CONCURRENT_RESOURCE_LOAD_COUNT,
    projectResources.map((projectResourcePath) => async () => {
      const resourceData = await checksumMD5File(projectResourcePath);
      return {
        path: pathToPosix(path.relative(projectRoot, projectResourcePath)),
        data: resourceData,
      };
    })
  );
 
  return resources.reduce((memo, { path, data }) => {
    memo[path] = data;
    return memo;
  }, {} as Record<string, string>);
};