module.exports=function(r){require("source-map-support").install();var l=require("./core/modbus-io-core");r.nodes.registerType("modbus-io-config",function(e){var t=require("fs-extra"),a=(r.nodes.createNode(this,e),this.name=e.name,this.path=e.path,this.format=e.format,this.addressOffset=e.addressOffset,this);if(a.setMaxListeners(0),a.lastUpdatedAt=null,a.configData=[],a.path)if(t.existsSync(a.path)){e=!1;try{var n=t.lstatSync(a.path),e=n&&"function"==typeof n.isFile&&n.isFile()}catch(e){l.internalDebug(e.message)}if(e)try{var i=function(){a.lineReader&&"function"==typeof a.lineReader.removeAllListeners&&a.lineReader.removeAllListeners(),a.lineReader.on("error",function(e){l.internalDebug(e.message)}),a.lineReader.on("line",function(e){e&&a.configData.push(e)}),a.lineReader.on("end",function(){a.lastUpdatedAt=Date.now(),l.internalDebug("Read IO Done From File "+a.path),a.warn({payload:l.allValueNamesFromIOFile(a),name:"Modbus Value Names From IO File",path:a.path}),a.emit("updatedConfig",a.configData)}),l.internalDebug("Loading IO File Started For "+a.path)};a.lineReader=new l.LineByLineReader(a.path),l.internalDebug("Read IO File "+a.path),i(),t.watchFile(a.path,function(e,t){if(l.internalDebug("the current mtime is: ".concat(e.mtime)),l.internalDebug("the previous mtime was: ".concat(t.mtime)),e.mtime!==t.mtime){l.internalDebug("Reload IO File "+a.path),a.configData=[],delete a.lastUpdatedAt,a.lineReader&&"function"==typeof a.lineReader.removeAllListeners&&a.lineReader.removeAllListeners();try{a.lineReader=new l.LineByLineReader(a.path),i(),l.internalDebug("Reloading IO File Started For "+a.path)}catch(e){l.internalDebug(e.message)}}})}catch(e){l.internalDebug(e.message),a.warn("Failed to read IO file: "+e.message)}else l.internalDebug("IO path is not a file: "+a.path),a.warn("Modbus IO path is not a file; using empty config: "+a.path)}else l.internalDebug("IO File Not Found "+a.path),a.warn("Modbus IO File Not Found "+a.path);else l.internalDebug("IO File path is empty"),a.warn("Modbus IO File path is empty; using empty config");a.on("close",function(e){try{if(a.path)try{t.unwatchFile(a.path)}catch(e){}if(a.lineReader&&"function"==typeof a.lineReader.removeAllListeners)try{a.lineReader.removeAllListeners()}catch(e){}}finally{a.removeAllListeners(),e()}})})};
//# sourceMappingURL=maps/modbus-io-config.js.map
