build-finished.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. const fs = require('fs');
  2. const path = require('path');
  3. const process = require('child_process');
  4. const assetsCompress = require('./assets-compress');
  5. const assetsCrypto = require('./assets-crypto');
  6. const assetsHotUpdate = require('./assets-hot-update');
  7. const assetsObfuscator = require('./assets-obfuscator');
  8. const assetsAndroidPack = require('./assets-android-pack');
  9. module.exports = {
  10. handle (options) {
  11. Editor.log('--------------- 编译完成 ---------------');
  12. this.rootDir = options.dest;
  13. this.actualPlatform = options.actualPlatform;
  14. // 处理资源压缩
  15. let isReady = assetsCompress.getInstance().isReady();
  16. if (isReady) {
  17. // 需要等待压缩资源完成
  18. this.handleAssetsCompress(this.next.bind(this));
  19. } else {
  20. this.next();
  21. }
  22. },
  23. next () {
  24. // 处理资源加密
  25. let isReady = assetsCrypto.getInstance().isReady();
  26. if (isReady) {
  27. this.handleAssetsEncrypt();
  28. }
  29. // 处理资源混淆
  30. isReady = assetsObfuscator.getInstance().isReady();
  31. if (isReady) {
  32. this.handleAssetsObfuscator();
  33. }
  34. // 处理资源热更
  35. isReady = assetsHotUpdate.getInstance().isReady();
  36. if (isReady) {
  37. this.handleAssetsHotUpdate();
  38. }
  39. // 处理安卓资源打包
  40. isReady = assetsAndroidPack.getInstance().isReady();
  41. if (isReady) {
  42. this.handleAssetsAndroidPack();
  43. }
  44. },
  45. handleAssetsCompress (next) {
  46. Editor.log('||||||||||||||| 开始处理资产压缩 |||||||||||||||');
  47. assetsCompress.getInstance().genFiles(this.rootDir);
  48. let total = assetsCompress.getInstance().getFilesCount();
  49. if (total > 0) {
  50. let progress = 0;
  51. assetsCompress.getInstance().compress((filename)=> {
  52. progress++;
  53. // Editor.log('压缩完成(' + progress + '/' + total + ')[' + filename + ']');
  54. if (progress == total) {
  55. Editor.log('压缩完成(' + progress + '/' + total + ')');
  56. Editor.log('--------------- 结束处理资产压缩 ---------------');
  57. next();
  58. }
  59. });
  60. } else {
  61. Editor.log('--------------- 结束处理资产压缩 ---------------');
  62. }
  63. },
  64. handleAssetsEncrypt () {
  65. Editor.log('||||||||||||||| 开始处理资产加密 |||||||||||||||');
  66. assetsCrypto.getInstance().modifyFileUtilsFile(this.rootDir);
  67. assetsCrypto.getInstance().genFiles(this.rootDir);
  68. let total = assetsCrypto.getInstance().getFilesCount();
  69. if (total > 0) {
  70. let progress = 0;
  71. assetsCrypto.getInstance().encrypt((filename)=> {
  72. progress++;
  73. // Editor.log('加密完成(' + progress + '/' + total + ')[' + filename + ']');
  74. if (progress == total) {
  75. Editor.log('加密完成(' + progress + '/' + total + ')');
  76. Editor.log('--------------- 结束处理资产加密 ---------------');
  77. }
  78. });
  79. } else {
  80. Editor.log('--------------- 结束处理资产加密 ---------------');
  81. }
  82. },
  83. handleAssetsObfuscator () {
  84. Editor.log('||||||||||||||| 开始处理资产混淆 |||||||||||||||');
  85. assetsObfuscator.getInstance().modifyResUuid(this.rootDir);
  86. Editor.log('--------------- 结束处理资产混淆 ---------------');
  87. },
  88. handleAssetsHotUpdate () {
  89. Editor.log('||||||||||||||| 开始处理资产热更 |||||||||||||||');
  90. assetsHotUpdate.getInstance().addHotUpdateSearchPaths(this.rootDir);
  91. assetsHotUpdate.getInstance().generateManifest(this.rootDir, (err) => {
  92. if (err) {
  93. throw err;
  94. }
  95. assetsHotUpdate.getInstance().copyAssets(this.rootDir);
  96. });
  97. let mjdataPath = path.join(Editor.Project.path, '../mj-data');
  98. if (!fs.existsSync(mjdataPath)) {
  99. mjdataPath = '$GIT_ROOT/mj-data';
  100. }
  101. let mjprotoPath = path.join(Editor.Project.path, '../mj-proto');
  102. if (!fs.existsSync(mjprotoPath)) {
  103. mjprotoPath = '$GIT_ROOT/mj-proto';
  104. }
  105. let cmd = 'cd ' + Editor.Project.path
  106. + ' && echo GIT最后一次提交的日志'
  107. + ' && echo ----------------------------------------- mj-creator 仓库:'
  108. + ' && echo $(git show -s --format=分支:%D)'
  109. + ' && echo $(git show -s --format=作者:%aN)'
  110. + ' && echo $(git show -s --format=标题:%s)'
  111. + ' && echo $(git show -s --format=提交:%H)'
  112. + ' && echo $(git show -s --format=日期:%aD)'
  113. + ' && echo ----------------------------------------- mj-data 仓库: $GIT_ROOT'
  114. + ' && cd ' + mjdataPath
  115. + ' && echo $(git show -s --format=分支:%D)'
  116. + ' && echo $(git show -s --format=作者:%aN)'
  117. + ' && echo $(git show -s --format=标题:%s)'
  118. + ' && echo $(git show -s --format=提交:%H)'
  119. + ' && echo $(git show -s --format=日期:%aD)'
  120. + ' && echo ----------------------------------------- mj-proto 仓库:'
  121. + ' && cd ' + mjprotoPath
  122. + ' && echo $(git show -s --format=分支:%D)'
  123. + ' && echo $(git show -s --format=作者:%aN)'
  124. + ' && echo $(git show -s --format=标题:%s)'
  125. + ' && echo $(git show -s --format=提交:%H)'
  126. + ' && echo $(git show -s --format=日期:%aD)';
  127. process.exec(cmd, function (error, stdout, stderr) {
  128. if (error) {
  129. Editor.log(error);
  130. }
  131. Editor.warn(stdout);
  132. });
  133. Editor.log('--------------- 结束处理资产热更 ---------------');
  134. },
  135. handleAssetsAndroidPack () {
  136. Editor.log('||||||||||||||| 开始处理资源安卓打包 |||||||||||||||');
  137. let total = assetsAndroidPack.getInstance().getCopyCount();
  138. if (total > 0) {
  139. let progress = 0;
  140. assetsAndroidPack.getInstance().copyAssets((filename)=> {
  141. progress++;
  142. Editor.log('拷贝完成(' + progress + '/' + total + ')[' + filename + ']');
  143. if (progress == total) {
  144. Editor.log('--------------- 结束处理资源安卓打包 ---------------');
  145. }
  146. });
  147. } else {
  148. Editor.log('--------------- 结束处理资源安卓打包 ---------------');
  149. }
  150. }
  151. };