All files / src/utils directories.ts

100% Statements 15/15
100% Branches 5/5
100% Functions 2/2
100% Lines 15/15

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 221x 1x         7x 7x 7x 7x 7x 7x   7x 7x 7x 7x   1x 2x 2x  
import fs from "node:fs";
import { join, resolve } from "node:path";
import * as core from "@actions/core";
import { glob } from "glob";
import type { ActionInputs } from "./inputs";
 
export async function getDirectories(target: ActionInputs["target"], ignore: ActionInputs["ignore"]) {
	const targetDir = resolve(target);
	const directories = await glob(join(targetDir, "**/"), {
		ignore: ignore.map((i) => join(targetDir, i, "**/")),
		withFileTypes: true,
	});
 
	const paths = directories.map((d) => d.fullpath()).join("\n  ");
	core.debug(`Found ${directories.length} directories: \n  ${paths}`);
	return { root: targetDir, directories };
}
 
export function getDirSize(path: string): number {
	return glob.sync(`${path}/**/*`, { nodir: true }).reduce((acc, path) => acc + fs.statSync(path).size, 0);
}