]>
git.r.bdr.sh - rbdr/blog/blob - lib/utils.js
cee3f4708ad110f83fcbc01dadb2c7695c5a83b1
1 import { access
, constants
, mkdir
, rm
} from 'fs/promises';
2 import { kFileNotFoundError
} from './constants.js';
4 // File system utilities
6 export const rmIfExists
= async
function rmIfExists(location
) {
9 await
access(location
, constants
.F_OK
);
10 await
rm(location
, { recursive: true });
13 if (error
.code
=== kFileNotFoundError
) {
21 export const ensureDirectoryExists
= async
function ensureDirectoryExists(directory
) {
24 await
access(directory
);
27 if (error
.code
=== kFileNotFoundError
) {
28 await
mkdir(directory
, { recursive: true });