build(deps): apply updates
[e-mobility-charging-stations-simulator.git] / src / utils / FileUtils.ts
index 51871884ccc38e7c7b6d09c7d6cd37c1a6ad3192..ecb945bf40915841809270453428725cddf6b182 100644 (file)
@@ -1,8 +1,8 @@
-import fs from 'node:fs';
+import { type FSWatcher, type WatchListener, readFileSync, watch } from 'node:fs';
 
 import { handleFileException } from './ErrorUtils';
 import { logger } from './Logger';
-import { Utils } from './Utils';
+import { isNotEmptyString } from './Utils';
 import type { FileType, JsonType } from '../types';
 
 export const watchJsonFile = <T extends JsonType>(
@@ -10,22 +10,22 @@ export const watchJsonFile = <T extends JsonType>(
   fileType: FileType,
   logPrefix: string,
   refreshedVariable?: T,
-  listener: fs.WatchListener<string> = (event, filename) => {
-    if (Utils.isNotEmptyString(filename) && event === 'change') {
+  listener: WatchListener<string> = (event, filename) => {
+    if (isNotEmptyString(filename) && event === 'change') {
       try {
         logger.debug(`${logPrefix} ${fileType} file ${file} have changed, reload`);
-        refreshedVariable && (refreshedVariable = JSON.parse(fs.readFileSync(file, 'utf8')) as T);
+        refreshedVariable && (refreshedVariable = JSON.parse(readFileSync(file, 'utf8')) as T);
       } catch (error) {
         handleFileException(file, fileType, error as NodeJS.ErrnoException, logPrefix, {
           throwError: false,
         });
       }
     }
-  }
-): fs.FSWatcher | undefined => {
-  if (Utils.isNotEmptyString(file)) {
+  },
+): FSWatcher | undefined => {
+  if (isNotEmptyString(file)) {
     try {
-      return fs.watch(file, listener);
+      return watch(file, listener);
     } catch (error) {
       handleFileException(file, fileType, error as NodeJS.ErrnoException, logPrefix, {
         throwError: false,