X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Futils%2FFileUtils.ts;h=f38bde6c8ea66218887438eefa23832c7e6aa0e9;hb=c127bd643861f50701371eddbad282edb420798a;hp=b057d7f7e844b4684f823903bc22a60f98e200dd;hpb=3e0905a14af7b7e0a96e859d6c4c615044845d54;p=e-mobility-charging-stations-simulator.git diff --git a/src/utils/FileUtils.ts b/src/utils/FileUtils.ts index b057d7f7..f38bde6c 100644 --- a/src/utils/FileUtils.ts +++ b/src/utils/FileUtils.ts @@ -8,16 +8,16 @@ import fs from 'fs'; import logger from './Logger'; export default class FileUtils { - static watchJsonFile( + public static watchJsonFile( logPrefix: string, fileType: FileType, file: string, - attribute?: T, + refreshedVariable?: T, listener: fs.WatchListener = (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, @@ -25,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, @@ -39,7 +39,7 @@ export default class FileUtils { } } - static handleFileException( + public static handleFileException( logPrefix: string, fileType: FileType, file: string,