- fileType: string,
- filePath: string,
- error: NodeJS.ErrnoException,
- params: HandleErrorParams<EmptyObject> = { throwError: true, consoleOut: false }
- ): void {
- const prefix = logPrefix.length !== 0 ? logPrefix + ' ' : '';
- if (error.code === 'ENOENT') {
- if (params?.consoleOut) {
- console.warn(
- chalk.green(prefix) + chalk.yellow(fileType + ' file ' + filePath + ' not found: '),
- error
- );
- } else {
- logger.warn(prefix + fileType + ' file ' + filePath + ' not found: %j', error);
- }
- } else if (error.code === 'EEXIST') {
- if (params?.consoleOut) {
- console.warn(
- chalk.green(prefix) + chalk.yellow(fileType + ' file ' + filePath + ' already exists: '),
- error
- );
- } else {
- logger.warn(prefix + fileType + ' file ' + filePath + ' already exists: %j', error);
+ refreshedVariable?: T,
+ listener: fs.WatchListener<string> = (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);
+ } catch (error) {
+ ErrorUtils.handleFileException(
+ file,
+ fileType,
+ error as NodeJS.ErrnoException,
+ logPrefix,
+ {
+ throwError: false,
+ }
+ );
+ }