]>
git.r.bdr.sh - rbdr/blog/blob - lib/utils.js
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 });