chore: switch coding style to JS standard
[e-mobility-charging-stations-simulator.git] / src / utils / FileUtils.ts
index 7235011cb0314509f108ee12115c05c0f84a59f7..bc8dd07c24725d990ae282056fc5ab8d4243b942 100644 (file)
@@ -1,9 +1,9 @@
-import { type FSWatcher, type WatchListener, readFileSync, watch } from 'node:fs';
+import { type FSWatcher, type WatchListener, readFileSync, watch } from 'node:fs'
 
-import { handleFileException } from './ErrorUtils.js';
-import { logger } from './Logger.js';
-import { isNotEmptyString } from './Utils.js';
-import type { FileType, JsonType } from '../types/index.js';
+import { handleFileException } from './ErrorUtils.js'
+import { logger } from './Logger.js'
+import { isNotEmptyString } from './Utils.js'
+import type { FileType, JsonType } from '../types/index.js'
 
 export const watchJsonFile = <T extends JsonType>(
   file: string,
@@ -13,25 +13,26 @@ export const watchJsonFile = <T extends JsonType>(
   listener: WatchListener<string> = (event, filename) => {
     if (isNotEmptyString(filename) && event === 'change') {
       try {
-        logger.debug(`${logPrefix} ${fileType} file ${file} have changed, reload`);
-        refreshedVariable && (refreshedVariable = JSON.parse(readFileSync(file, 'utf8')) as T);
+        logger.debug(`${logPrefix} ${fileType} file ${file} have changed, reload`)
+        refreshedVariable != null &&
+          (refreshedVariable = JSON.parse(readFileSync(file, 'utf8')) as T)
       } catch (error) {
         handleFileException(file, fileType, error as NodeJS.ErrnoException, logPrefix, {
-          throwError: false,
-        });
+          throwError: false
+        })
       }
     }
-  },
+  }
 ): FSWatcher | undefined => {
   if (isNotEmptyString(file)) {
     try {
-      return watch(file, listener);
+      return watch(file, listener)
     } catch (error) {
       handleFileException(file, fileType, error as NodeJS.ErrnoException, logPrefix, {
-        throwError: false,
-      });
+        throwError: false
+      })
     }
   } else {
-    logger.info(`${logPrefix} No ${fileType} file to watch given. Not monitoring its changes`);
+    logger.info(`${logPrefix} No ${fileType} file to watch given. Not monitoring its changes`)
   }
-};
+}