]>
git.r.bdr.sh - rbdr/blog/blob - lib/utils.js
24b9407a46645c869bafb1099474d4eba232dc22
1 const { access
, constants
, mkdir
, rm
} = require('fs/promises');
2 const { kFileNotFoundError
} = require('./constants');
4 // File system utilities
7 async
rmIfExists(location
) {
10 await
access(location
, constants
.F_OK
);
11 await
rm(location
, { recursive: true });
14 if (error
.code
=== kFileNotFoundError
) {
22 async
ensureDirectoryExists(directory
) {
25 await
access(directory
);
28 if (error
.code
=== kFileNotFoundError
) {
29 await
mkdir(directory
, { recursive: true });