X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Futils%2FFileUtils.ts;h=5e40b72435bc461b5ca8a6494ee08541be830a56;hb=a1c394ae6f706a51274c4a2adb1d5d89c0913596;hp=51871884ccc38e7c7b6d09c7d6cd37c1a6ad3192;hpb=d58b442097da31f8b974d51aef63c64470d9ab48;p=e-mobility-charging-stations-simulator.git diff --git a/src/utils/FileUtils.ts b/src/utils/FileUtils.ts index 51871884..5e40b724 100644 --- a/src/utils/FileUtils.ts +++ b/src/utils/FileUtils.ts @@ -1,4 +1,4 @@ -import fs from 'node:fs'; +import { type FSWatcher, type WatchListener, readFileSync, watch } from 'node:fs'; import { handleFileException } from './ErrorUtils'; import { logger } from './Logger'; @@ -10,11 +10,11 @@ export const watchJsonFile = ( fileType: FileType, logPrefix: string, refreshedVariable?: T, - listener: fs.WatchListener = (event, filename) => { + listener: WatchListener = (event, filename) => { if (Utils.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, @@ -22,10 +22,10 @@ export const watchJsonFile = ( } } } -): fs.FSWatcher | undefined => { +): FSWatcher | undefined => { if (Utils.isNotEmptyString(file)) { try { - return fs.watch(file, listener); + return watch(file, listener); } catch (error) { handleFileException(file, fileType, error as NodeJS.ErrnoException, logPrefix, { throwError: false,