index.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.initCheckOptionsEnv = exports.checkCompile = exports.checkSwiftCompile = exports.checkKotlinCompile = exports.storeSourceMap = exports.restoreSourceMap = exports.restoreDex = exports.genManifestFile = void 0;
  4. const fs_extra_1 = require("fs-extra");
  5. const path_1 = require("path");
  6. const shared_1 = require("../shared");
  7. const manifest_1 = require("./manifest");
  8. const utils_1 = require("./utils");
  9. var manifest_2 = require("./manifest");
  10. Object.defineProperty(exports, "genManifestFile", { enumerable: true, get: function () { return manifest_2.genManifestFile; } });
  11. var dex_1 = require("./dex");
  12. Object.defineProperty(exports, "restoreDex", { enumerable: true, get: function () { return dex_1.restoreDex; } });
  13. var sourceMap_1 = require("./sourceMap");
  14. Object.defineProperty(exports, "restoreSourceMap", { enumerable: true, get: function () { return sourceMap_1.restoreSourceMap; } });
  15. Object.defineProperty(exports, "storeSourceMap", { enumerable: true, get: function () { return sourceMap_1.storeSourceMap; } });
  16. const ANDROID_CUSTOM_RES = [
  17. 'app-android/assets/',
  18. 'app-android/libs/',
  19. 'app-android/res/',
  20. 'app-android/AndroidManifest.xml',
  21. ];
  22. const IOS_CUSTOM_RES = [
  23. 'app-ios/Frameworks/',
  24. 'app-ios/Resources/',
  25. 'app-ios/Info.plist',
  26. ];
  27. function checkKotlinCompile(playground, options) {
  28. return checkCompile('app-android', playground, options);
  29. }
  30. exports.checkKotlinCompile = checkKotlinCompile;
  31. function checkSwiftCompile(playground, options) {
  32. return checkCompile('app-ios', playground, options);
  33. }
  34. exports.checkSwiftCompile = checkSwiftCompile;
  35. function checkCompile(platform, playground, options) {
  36. const platformOptions = {
  37. customRes: platform === 'app-android' ? ANDROID_CUSTOM_RES : IOS_CUSTOM_RES,
  38. };
  39. if (playground === 'standard') {
  40. return checkWithPlayground(platform, 'standard', options, platformOptions);
  41. }
  42. return checkWithPlayground(platform, 'custom', options, platformOptions);
  43. }
  44. exports.checkCompile = checkCompile;
  45. async function checkWithPlayground(platform, type, { id, env, cacheDir, pluginDir, pluginRelativeDir, is_uni_modules, }, { customRes }) {
  46. // 第一步:获取所有文件列表
  47. const files = await (0, manifest_1.resolvePluginFiles)(platform, pluginDir, is_uni_modules);
  48. let tips = '';
  49. // 标准基座检查是否包含原生资源/配置
  50. if (type === 'standard') {
  51. if ((0, manifest_1.hasCustomResources)(files, customRes)) {
  52. tips = (0, utils_1.customResourceTips)(id);
  53. }
  54. else {
  55. // 检查 config.json
  56. if (platform === 'app-android') {
  57. if (androidHasCustomConfigJson(pluginDir, is_uni_modules)) {
  58. tips = (0, utils_1.customResourceTips)(id);
  59. }
  60. }
  61. else if (platform === 'app-ios') {
  62. if (iOSHasCustomConfigJson(pluginDir, is_uni_modules)) {
  63. tips = (0, utils_1.customResourceTips)(id);
  64. }
  65. }
  66. }
  67. }
  68. // 第二步:获取当前插件缓存文件信息
  69. const manifest = (0, manifest_1.resolveManifestJson)(platform, pluginRelativeDir, cacheDir);
  70. if (!manifest) {
  71. return { expired: true, tips, files };
  72. }
  73. // 第四步:检查文件变更
  74. const res = await (0, manifest_1.checkManifest)(manifest, { env, files, pluginDir });
  75. // 自定义基座检查原生资源/配置是否发生变化
  76. if (type === 'custom' && typeof res === 'string') {
  77. if ((0, manifest_1.isCustomResources)(res, customRes)) {
  78. tips = (0, utils_1.customResourceChangedTips)(id);
  79. }
  80. }
  81. return {
  82. expired: res !== true,
  83. tips,
  84. files,
  85. };
  86. }
  87. function initCheckOptionsEnv() {
  88. return {
  89. compilerVersion: require('../../package.json').version,
  90. };
  91. }
  92. exports.initCheckOptionsEnv = initCheckOptionsEnv;
  93. function androidHasCustomConfigJson(pluginDir, is_uni_modules) {
  94. return hasCustomConfigJson('app-android', 'minSdkVersion', pluginDir, is_uni_modules);
  95. }
  96. function iOSHasCustomConfigJson(pluginDir, is_uni_modules) {
  97. return hasCustomConfigJson('app-ios', 'deploymentTarget', pluginDir, is_uni_modules);
  98. }
  99. function hasCustomConfigJson(platform, key, pluginDir, is_uni_modules) {
  100. const configJsonFile = (0, path_1.join)(pluginDir, is_uni_modules ? 'utssdk' : '', platform, 'config.json');
  101. if (configJsonFile && (0, fs_extra_1.existsSync)(configJsonFile)) {
  102. try {
  103. const configJson = (0, shared_1.parseJson)((0, fs_extra_1.readFileSync)(configJsonFile, 'utf8'));
  104. const len = Object.keys(configJson).length;
  105. if (len > 1) {
  106. return true;
  107. }
  108. if (len === 1) {
  109. if (!configJson.hasOwnProperty(key)) {
  110. return true;
  111. }
  112. }
  113. }
  114. catch (e) { }
  115. }
  116. return false;
  117. }