const fs = require('fs'); const path = require('path'); const process = require('child_process'); const assetsCompress = require('./assets-compress'); const assetsCrypto = require('./assets-crypto'); const assetsHotUpdate = require('./assets-hot-update'); const assetsObfuscator = require('./assets-obfuscator'); const assetsAndroidPack = require('./assets-android-pack'); module.exports = { handle (options) { Editor.log('--------------- 编译完成 ---------------'); this.rootDir = options.dest; this.actualPlatform = options.actualPlatform; // 处理资源压缩 let isReady = assetsCompress.getInstance().isReady(); if (isReady) { // 需要等待压缩资源完成 this.handleAssetsCompress(this.next.bind(this)); } else { this.next(); } }, next () { // 处理资源加密 let isReady = assetsCrypto.getInstance().isReady(); if (isReady) { this.handleAssetsEncrypt(); } // 处理资源混淆 isReady = assetsObfuscator.getInstance().isReady(); if (isReady) { this.handleAssetsObfuscator(); } // 处理资源热更 isReady = assetsHotUpdate.getInstance().isReady(); if (isReady) { this.handleAssetsHotUpdate(); } // 处理安卓资源打包 isReady = assetsAndroidPack.getInstance().isReady(); if (isReady) { this.handleAssetsAndroidPack(); } }, handleAssetsCompress (next) { Editor.log('||||||||||||||| 开始处理资产压缩 |||||||||||||||'); assetsCompress.getInstance().genFiles(this.rootDir); let total = assetsCompress.getInstance().getFilesCount(); if (total > 0) { let progress = 0; assetsCompress.getInstance().compress((filename)=> { progress++; // Editor.log('压缩完成(' + progress + '/' + total + ')[' + filename + ']'); if (progress == total) { Editor.log('压缩完成(' + progress + '/' + total + ')'); Editor.log('--------------- 结束处理资产压缩 ---------------'); next(); } }); } else { Editor.log('--------------- 结束处理资产压缩 ---------------'); } }, handleAssetsEncrypt () { Editor.log('||||||||||||||| 开始处理资产加密 |||||||||||||||'); assetsCrypto.getInstance().modifyFileUtilsFile(this.rootDir); assetsCrypto.getInstance().genFiles(this.rootDir); let total = assetsCrypto.getInstance().getFilesCount(); if (total > 0) { let progress = 0; assetsCrypto.getInstance().encrypt((filename)=> { progress++; // Editor.log('加密完成(' + progress + '/' + total + ')[' + filename + ']'); if (progress == total) { Editor.log('加密完成(' + progress + '/' + total + ')'); Editor.log('--------------- 结束处理资产加密 ---------------'); } }); } else { Editor.log('--------------- 结束处理资产加密 ---------------'); } }, handleAssetsObfuscator () { Editor.log('||||||||||||||| 开始处理资产混淆 |||||||||||||||'); assetsObfuscator.getInstance().modifyResUuid(this.rootDir); Editor.log('--------------- 结束处理资产混淆 ---------------'); }, handleAssetsHotUpdate () { Editor.log('||||||||||||||| 开始处理资产热更 |||||||||||||||'); assetsHotUpdate.getInstance().addHotUpdateSearchPaths(this.rootDir); assetsHotUpdate.getInstance().generateManifest(this.rootDir, (err) => { if (err) { throw err; } assetsHotUpdate.getInstance().copyAssets(this.rootDir); }); let mjdataPath = path.join(Editor.Project.path, '../mj-data'); if (!fs.existsSync(mjdataPath)) { mjdataPath = '$GIT_ROOT/mj-data'; } let mjprotoPath = path.join(Editor.Project.path, '../mj-proto'); if (!fs.existsSync(mjprotoPath)) { mjprotoPath = '$GIT_ROOT/mj-proto'; } let cmd = 'cd ' + Editor.Project.path + ' && echo GIT最后一次提交的日志' + ' && echo ----------------------------------------- mj-creator 仓库:' + ' && echo $(git show -s --format=分支:%D)' + ' && echo $(git show -s --format=作者:%aN)' + ' && echo $(git show -s --format=标题:%s)' + ' && echo $(git show -s --format=提交:%H)' + ' && echo $(git show -s --format=日期:%aD)' + ' && echo ----------------------------------------- mj-data 仓库: $GIT_ROOT' + ' && cd ' + mjdataPath + ' && echo $(git show -s --format=分支:%D)' + ' && echo $(git show -s --format=作者:%aN)' + ' && echo $(git show -s --format=标题:%s)' + ' && echo $(git show -s --format=提交:%H)' + ' && echo $(git show -s --format=日期:%aD)' + ' && echo ----------------------------------------- mj-proto 仓库:' + ' && cd ' + mjprotoPath + ' && echo $(git show -s --format=分支:%D)' + ' && echo $(git show -s --format=作者:%aN)' + ' && echo $(git show -s --format=标题:%s)' + ' && echo $(git show -s --format=提交:%H)' + ' && echo $(git show -s --format=日期:%aD)'; process.exec(cmd, function (error, stdout, stderr) { if (error) { Editor.log(error); } Editor.warn(stdout); }); Editor.log('--------------- 结束处理资产热更 ---------------'); }, handleAssetsAndroidPack () { Editor.log('||||||||||||||| 开始处理资源安卓打包 |||||||||||||||'); let total = assetsAndroidPack.getInstance().getCopyCount(); if (total > 0) { let progress = 0; assetsAndroidPack.getInstance().copyAssets((filename)=> { progress++; Editor.log('拷贝完成(' + progress + '/' + total + ')[' + filename + ']'); if (progress == total) { Editor.log('--------------- 结束处理资源安卓打包 ---------------'); } }); } else { Editor.log('--------------- 结束处理资源安卓打包 ---------------'); } } };