Add a shared cache per worker for authorized tags
[e-mobility-charging-stations-simulator.git] / src / utils / FileUtils.ts
index 5c15734bfe97cbf7857b3199f53ece7114ff1368..f38bde6c8ea66218887438eefa23832c7e6aa0e9 100644 (file)
@@ -1,24 +1,23 @@
-import { JsonType, JsonValue } from '../types/JsonType';
-
 import { EmptyObject } from '../types/EmptyObject';
 import { FileType } from '../types/FileType';
 import { HandleErrorParams } from '../types/Error';
+import { JsonType } from '../types/JsonType';
 import Utils from './Utils';
 import chalk from 'chalk';
 import fs from 'fs';
 import logger from './Logger';
 
 export default class FileUtils {
-  static watchJsonFile<T extends JsonType | JsonValue>(
+  public static watchJsonFile<T extends JsonType>(
     logPrefix: string,
     fileType: FileType,
     file: string,
-    attribute?: T,
+    refreshedVariable?: T,
     listener: fs.WatchListener<string> = (event, filename) => {
       if (filename && event === 'change') {
         try {
           logger.debug(logPrefix + ' ' + fileType + ' file ' + file + ' have changed, reload');
-          attribute && (attribute = JSON.parse(fs.readFileSync(file, 'utf8')) as T);
+          refreshedVariable && (refreshedVariable = JSON.parse(fs.readFileSync(file, 'utf8')) as T);
         } catch (error) {
           FileUtils.handleFileException(logPrefix, fileType, file, error as NodeJS.ErrnoException, {
             throwError: false,
@@ -26,10 +25,10 @@ export default class FileUtils {
         }
       }
     }
-  ) {
+  ): fs.FSWatcher {
     if (file) {
       try {
-        fs.watch(file, listener);
+        return fs.watch(file, listener);
       } catch (error) {
         FileUtils.handleFileException(logPrefix, fileType, file, error as NodeJS.ErrnoException, {
           throwError: false,
@@ -40,7 +39,7 @@ export default class FileUtils {
     }
   }
 
-  static handleFileException(
+  public static handleFileException(
     logPrefix: string,
     fileType: FileType,
     file: string,