123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- const Path = require('path');
- const Fs = require('fs');
- const FsExtra = require('fs-extra');
- const OutPut = Editor.require('packages://hot-update-tools/core/OutPut.js');
- const { shell } = require('electron');
- Vue.component('env-project', {
- template: Fs.readFileSync(Editor.url('packages://hot-update-tools/panel/env-project.html'), 'utf-8'),
- mixins: [Editor.require('packages://hot-update-tools/panel/mixin.js')],
- data () {
- return {
- localGameVersion: '-', // 游戏版本号
- localGamePackageUrl: '',
- localGameProjectManifest: '',
- localGameVersionManifest: '',
- };
- },
- created () {
- this.initLocalGameVersion();
- },
- methods: {
- // 导入生成的manifest到游戏项目中
- importManifestToGame () {
- let manifest = {
- project: 'project.manifest',
- version: 'version.manifest',
- };
- let projectFile = Path.join(OutPut.manifestDir, manifest.project);
- if (!Fs.existsSync(projectFile)) {
- this.log(`[${manifest.project}]文件不存在: ${projectFile}`);
- return;
- }
- let versionFile = Path.join(OutPut.manifestDir, manifest.version);
- if (!Fs.existsSync(versionFile)) {
- this.log(`[${manifest.version}]文件不存在: ${versionFile}`);
- return;
- }
- let projectManifestDir = null;
- if (!Fs.existsSync(this.localGameProjectManifest)) {
- // 默认使用根目录
- projectManifestDir = Editor.url('db://assets');
- } else {
- projectManifestDir = Path.dirname(this.localGameProjectManifest);
- }
- for (let key in manifest) {
- let source = Path.join(OutPut.manifestDir, manifest[key]);
- let dest = Path.join(projectManifestDir, manifest[key]);
- FsExtra.copyFileSync(source, dest);
- let url = Editor.assetdb.remote.fspathToUrl(dest);
- Editor.assetdb.refresh(url);
- }
- this.initLocalGameVersion();
- },
- onClickLocalPackageUrl () {
- let url = `${this.localGamePackageUrl}/version.manifest`;
- shell && shell.openExternal(url);
- },
- initLocalGameVersion () {
- const Globby = require('globby');
- let root = Editor.url('db://assets');
- let manifestUrl = Path.join(root, '**/*.manifest');
- manifestUrl = Path.normalize(manifestUrl).replace(/\\/g, '/');
- let results = Globby.sync([manifestUrl]);
- let versionCfg = '';
- let projectCfg = '';
- results.forEach((result) => {
- if (Path.basename(result) === 'version.manifest') {
- versionCfg = result;
- } else if (Path.basename(result) === 'project.manifest') {
- projectCfg = result;
- }
- });
- if (versionCfg.length === 0) {
- this.log('项目中没有配置文件: version.manifest');
- return;
- }
- if (projectCfg.length === 0) {
- this.log('项目中没有配置文件: project.manifest');
- return;
- }
- this.localGameVersionManifest = versionCfg;
- this.localGameProjectManifest = projectCfg;
- let versionData = null;
- let projectData = null;
- if (Fs.existsSync(versionCfg)) {
- try {
- versionData = JSON.parse(Fs.readFileSync(versionCfg, 'utf-8'));
- } catch (e) {
- this.log(`配置数据异常,不是json格式:${versionCfg}`);
- return;
- }
- } else {
- this.log('读取项目中的配置文件失败: ' + versionCfg);
- }
- if (Fs.existsSync(projectCfg)) {
- try {
- projectData = JSON.parse(Fs.readFileSync(projectCfg, 'utf-8'));
- } catch (e) {
- this.log(`配置数据异常,不是json格式:${projectCfg}`);
- return;
- }
- } else {
- this.log('读取项目中的配置文件失败: ' + projectCfg);
- }
- if (projectData && versionData &&
- projectData.version && versionData.version &&
- projectData.version === versionData.version) {
- this.localGameVersion = projectData.version;
- this.localGamePackageUrl = projectData.packageUrl;
- } else {
- this.log('游戏中的 project.manifest 和 version.manifest 中的数据异常,请检查配置文件');
- }
- },
- },
- });
|