Skip to content

Commit

Permalink
feat(file-io): add deleteDir()
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Apr 22, 2024
1 parent f3c1512 commit 06b4ffc
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion packages/file-io/src/delete.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ILogger } from "@thi.ng/logger";
import { unlinkSync } from "node:fs";
import { rmSync, unlinkSync } from "node:fs";

/**
* Deletes file at given path. If `dryRun` is true (default: false), the file
Expand All @@ -15,3 +15,17 @@ export const deleteFile = (path: string, logger?: ILogger, dryRun = false) => {
if (dryRun) return;
unlinkSync(path);
};

/**
* Like {@link deleteFile}, but attempts to recursively remove an entire
* directory at given path.
*
* @param path
* @param logger
* @param dryRun
*/
export const deleteDir = (path: string, logger?: ILogger, dryRun = false) => {
logger && logger.info(`${dryRun ? "[dryrun] " : ""}deleting file: ${path}`);
if (dryRun) return;
rmSync(path, { recursive: true, force: true });
};

0 comments on commit 06b4ffc

Please sign in to comment.