]> git.r.bdr.sh - rbdr/blog/blobdiff - lib/utils.js
Add generator
[rbdr/blog] / lib / utils.js
index 24b9407a46645c869bafb1099474d4eba232dc22..cee3f4708ad110f83fcbc01dadb2c7695c5a83b1 100644 (file)
@@ -1,36 +1,34 @@
-const { access, constants, mkdir, rm } = require('fs/promises');
-const { kFileNotFoundError } = require('./constants');
+import { access, constants, mkdir, rm } from 'fs/promises';
+import { kFileNotFoundError } from './constants.js';
 
 // File system utilities
 
-module.exports = {
-  async rmIfExists(location) {
+export const rmIfExists = async function rmIfExists(location) {
 
-    try {
-      await access(location, constants.F_OK);
-      await rm(location, { recursive: true });
+  try {
+    await access(location, constants.F_OK);
+    await rm(location, { recursive: true });
+  }
+  catch (error) {
+    if (error.code === kFileNotFoundError) {
+      return;
     }
-    catch (error) {
-      if (error.code === kFileNotFoundError) {
-        return;
-      }
 
-      throw error;
-    }
-  },
+    throw error;
+  }
+};
 
-  async ensureDirectoryExists(directory) {
+export const ensureDirectoryExists = async function ensureDirectoryExists(directory) {
 
-    try {
-      await access(directory);
+  try {
+    await access(directory);
+  }
+  catch (error) {
+    if (error.code === kFileNotFoundError) {
+      await mkdir(directory, { recursive: true });
+      return;
     }
-    catch (error) {
-      if (error.code === kFileNotFoundError) {
-        await mkdir(directory, { recursive: true });
-        return;
-      }
 
-      throw error;
-    }
+    throw error;
   }
 };