env-project.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. const Path=require("path"),Fs=require("fs"),FsExtra=require("fs-extra"),OutPut=Editor.require("packages://hot-update-tools/core/OutPut.js");
  2. Vue.component("env-project",{
  3. template:Fs.readFileSync(Editor.url("packages://hot-update-tools/panel/env-project.html"),"utf-8"),
  4. mixins:[Editor.require("packages://hot-update-tools/panel/mixin.js")],
  5. data:()=>(
  6. {localGameVersion:"-",localGamePackageUrl:"",localGameProjectManifest:"",localGameVersionManifest:""}
  7. ),
  8. created(){
  9. this.initLocalGameVersion()
  10. },
  11. methods:{
  12. importManifestToGame(){
  13. let e={project:"project.manifest",version:"version.manifest"},t=Path.join(OutPut.manifestDir,e.project);
  14. if(!Fs.existsSync(t))return void
  15. this.log(`[${e.project}]文件不存在: ${t}`);
  16. let s=Path.join(OutPut.manifestDir,e.version);
  17. if(!Fs.existsSync(s))return void
  18. this.log(`[${e.version}]文件不存在: ${s}`);
  19. let i=null;
  20. i=Fs.existsSync(this.localGameProjectManifest)?Path.dirname(this.localGameProjectManifest):Editor.url("db://assets");
  21. for(let t in e){
  22. let s=Path.join(OutPut.manifestDir,e[t]),a=Path.join(i,e[t]);
  23. FsExtra.copyFileSync(s,a);
  24. let o=Editor.assetdb.remote.fspathToUrl(a);
  25. Editor.assetdb.refresh(o)
  26. }
  27. this.initLocalGameVersion()
  28. },
  29. initLocalGameVersion(){
  30. const e=require("globby");
  31. let t=Editor.url("db://assets"),s="",i="";
  32. if(e.sync([Path.join(t,"**/*.manifest")]).forEach(e=>{"version.manifest"===Path.basename(e)?s=e:"project.manifest"===Path.basename(e)&&(i=e)}),0===s.length)return void
  33. this.log("项目中没有配置文件: version.manifest");
  34. if(0===i.length)return void
  35. this.log("项目中没有配置文件: project.manifest");
  36. this.localGameVersionManifest=s,this.localGameProjectManifest=i;
  37. let a=null,o=null;
  38. Fs.existsSync(s)?a=JSON.parse(Fs.readFileSync(s,"utf-8")):this.log("读取项目中的配置文件失败: "+s),Fs.existsSync(i)?o=JSON.parse(Fs.readFileSync(i,"utf-8")):this.log("读取项目中的配置文件失败: "+i),o&&a&&o.version&&a.version&&o.version===a.version?(this.localGameVersion=o.version,this.localGamePackageUrl=o.packageUrl):this.log("游戏中的 project.manifest 和 version.manifest 中的数据异常,请检查配置文件")
  39. }
  40. }
  41. });