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