CfgUtil.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. const Fs=require("fire-fs"),FsExtra=require("fs-extra"),Path=require("fire-path"),OutPut=Editor.require("packages://hot-update-tools/core/OutPut.js");
  2. module.exports={
  3. cfgData:{selectDestType:"",isUsedEncrypt:false,version:"",serverRootDir:"",resourceRootDir:"",genManifestDir:"",localServerPath:"",hotAddressArray:[],buildTime:null,genTime:null,genVersion:null},
  4. _save(){
  5. FsExtra.ensureFileSync(this.cfgFile),Fs.writeFileSync(this.cfgFile,JSON.stringify(this.cfgData,null,4))
  6. },
  7. get cfgFile(){
  8. return Path.join(OutPut.rootDir,"cfg.json")
  9. },
  10. initCfg(){
  11. return OutPut.initialization(),Fs.existsSync(this.cfgFile)?this.cfgData=JSON.parse(Fs.readFileSync(this.cfgFile,"utf-8")):this._save(),this.cfgData
  12. },
  13. updateBuildTimeByMain(e){
  14. let i=this.cfgFile;
  15. if(Fs.existsSync(i)){
  16. let t=Fs.readFileSync(i,"utf-8"),s=JSON.parse(t);
  17. s.buildTime=e,s.genTime=e,Fs.writeFileSync(i,JSON.stringify(s,null,4))
  18. }else Editor.log("热更新配置文件不存在: "+i)
  19. },
  20. updateBuildTime(e){
  21. this.cfgData.buildTime=e,this.cfgData.genTime=e,this._save()
  22. },
  23. updateGenTime(e,i){
  24. this.cfgData.genTime=e,this.cfgData.genVersion=i,this._save()
  25. },
  26. getBuildTimeGenTime(){
  27. let e={buildTime:null,genTime:null},i=this.cfgFile;
  28. if(Fs.existsSync(i)){
  29. let t=Fs.readFileSync(i,"utf-8"),s=JSON.parse(t);
  30. e.buildTime=s.buildTime,e.genTime=s.genTime,this.cfgData.buildTime=s.buildTime,this.cfgData.genTime=s.genTime
  31. }
  32. return e
  33. },
  34. saveConfig(e){
  35. this.cfgData.selectDestType=e.selectDestType,this.cfgData.isUsedEncrypt=e.isUsedEncrypt,this.cfgData.version=e.version,this.cfgData.serverRootDir=e.serverRootDir,this.cfgData.resourceRootDir=e.resourceRootDir,this.cfgData.localServerPath=e.localServerPath,this.cfgData.hotAddressArray=e.hotAddressArray,this._save()
  36. }
  37. };