miniprogram-ci 2.0.9 → 2.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/README.md +5 -0
  3. package/dist/@types/ci/upload.d.ts +0 -1
  4. package/dist/@types/ci/utils/progressupdate.d.ts +2 -0
  5. package/dist/@types/common/code-analyse/index.d.ts +1 -0
  6. package/dist/@types/config/config.d.ts +1 -1
  7. package/dist/@types/modules/corecompiler/baseCompiler.d.ts +5 -0
  8. package/dist/@types/modules/corecompiler/original/validate/schemaValidate.d.ts +1 -1
  9. package/dist/@types/modules/corecompiler/original/workerThread/task/minifywxml.d.ts +21 -25
  10. package/dist/@types/modules/corecompiler/originalCompiler.d.ts +1 -0
  11. package/dist/@types/modules/corecompiler/processHandler.d.ts +2 -21
  12. package/dist/@types/modules/corecompiler/summer/graph/basegraph.d.ts +1 -0
  13. package/dist/@types/modules/corecompiler/summer/module.d.ts +20 -14
  14. package/dist/@types/modules/corecompiler/summerCompiler.d.ts +5 -4
  15. package/dist/@types/modules/index.d.ts +2 -0
  16. package/dist/@types/modules/nativecompiler/index.d.ts +1 -0
  17. package/dist/@types/modules/nativecompiler/ios/buildCloud.d.ts +9 -2
  18. package/dist/@types/modules/nativecompiler/ios/index.d.ts +2 -0
  19. package/dist/@types/modules/nativecompiler/nativeCompiler.d.ts +3 -0
  20. package/dist/@types/modules/precompiler/conditioncompile/index.d.ts +3 -2
  21. package/dist/@types/modules/precompiler/index.d.ts +3 -2
  22. package/dist/@types/schema/@types/appjson.d.ts +215 -0
  23. package/dist/@types/schema/@types/extjson.d.ts +82 -0
  24. package/dist/@types/schema/@types/gamejson.d.ts +55 -0
  25. package/dist/@types/schema/@types/pagejson.d.ts +47 -0
  26. package/dist/@types/schema/@types/pluginjson.d.ts +17 -0
  27. package/dist/@types/schema/@types/pluginpagejson.d.ts +5 -0
  28. package/dist/@types/schema/@types/projectconfigjson.d.ts +194 -0
  29. package/dist/@types/schema/@types/projectprivateconfigjson.d.ts +114 -0
  30. package/dist/@types/schema/@types/sitemapjson.d.ts +10 -0
  31. package/dist/@types/schema/@types/themejson.d.ts +8 -0
  32. package/dist/@types/schema/src/index.d.ts +60 -0
  33. package/dist/@types/types/ci.d.ts +1 -1
  34. package/dist/@types/types/core.d.ts +3 -3
  35. package/dist/@types/types/devtools.d.ts +22 -3
  36. package/dist/@types/types/miniapp/index.d.ts +5 -0
  37. package/dist/@types/types/summer.d.ts +2 -0
  38. package/dist/@types/utils/messageHub.d.ts +2 -2
  39. package/dist/@types/utils/miniapp-builder.d.ts +13 -3
  40. package/dist/@types/utils/progressRecorder.d.ts +3 -1
  41. package/dist/@types/utils/subprocess/processManager.d.ts +4 -1
  42. package/dist/@types/utils/taskstatus.d.ts +3 -3
  43. package/dist/@types/utils/tools.d.ts +1 -0
  44. package/dist/@types/utils/usbProcess.d.ts +3 -0
  45. package/dist/ci/getCompiledResult.js +1 -1
  46. package/dist/ci/getcompiler.js +1 -1
  47. package/dist/ci/upload.js +1 -1
  48. package/dist/ci/utils/progressupdate.js +1 -0
  49. package/dist/common/code-analyse/index.js +1 -1
  50. package/dist/config/config.js +1 -1
  51. package/dist/modules/corecompiler/baseCompiler.js +1 -1
  52. package/dist/modules/corecompiler/original/workerThread/task/index.js +1 -1
  53. package/dist/modules/corecompiler/original/workerThread/task/minifywxml.js +1 -1
  54. package/dist/modules/corecompiler/originalCompiler.js +1 -1
  55. package/dist/modules/corecompiler/processHandler.js +1 -1
  56. package/dist/modules/corecompiler/summer/graph/appgraph.js +1 -1
  57. package/dist/modules/corecompiler/summer/graph/basegraph.js +1 -1
  58. package/dist/modules/corecompiler/summer/module.js +1 -1
  59. package/dist/modules/corecompiler/summer/plugins/base/es6module.js +1 -1
  60. package/dist/modules/corecompiler/summer/plugins/base/javascript.js +1 -1
  61. package/dist/modules/corecompiler/summer/plugins/base/swc.js +1 -1
  62. package/dist/modules/corecompiler/summer/plugins/base/wxss.js +1 -1
  63. package/dist/modules/corecompiler/summer/plugins/enhance.js +1 -1
  64. package/dist/modules/corecompiler/summer/plugins/less.js +1 -1
  65. package/dist/modules/corecompiler/summer/plugins/minifywxml.js +1 -1
  66. package/dist/modules/corecompiler/summer/plugins/sass.js +1 -1
  67. package/dist/modules/corecompiler/summer/plugins/terser.js +1 -1
  68. package/dist/modules/corecompiler/summer/plugins/typescript.js +1 -1
  69. package/dist/modules/corecompiler/summer/plugins/worklet.js +1 -1
  70. package/dist/modules/corecompiler/summer/summer.js +1 -1
  71. package/dist/modules/corecompiler/summer/worker.js +1 -1
  72. package/dist/modules/corecompiler/summerCompiler.js +1 -1
  73. package/dist/modules/createSummer.js +1 -1
  74. package/dist/modules/index.js +1 -1
  75. package/dist/modules/nativecompiler/index.js +1 -1
  76. package/dist/modules/nativecompiler/ios/buildCloud.js +1 -1
  77. package/dist/modules/nativecompiler/ios/index.js +1 -1
  78. package/dist/modules/nativecompiler/nativeCompiler.js +1 -1
  79. package/dist/modules/nativecompiler/nativeEntryProcess.js +1 -1
  80. package/dist/modules/precompiler/conditioncompile/index.js +1 -1
  81. package/dist/modules/precompiler/index.js +1 -1
  82. package/dist/project/advance/precompileProject.js +1 -1
  83. package/dist/project/baseProject.js +1 -1
  84. package/dist/schema/@types/appjson.js +1 -0
  85. package/dist/schema/@types/extjson.js +1 -0
  86. package/dist/schema/@types/gamejson.js +1 -0
  87. package/dist/schema/@types/pagejson.js +1 -0
  88. package/dist/schema/@types/pluginjson.js +1 -0
  89. package/dist/schema/@types/pluginpagejson.js +1 -0
  90. package/dist/schema/@types/projectconfigjson.js +1 -0
  91. package/dist/schema/@types/projectprivateconfigjson.js +1 -0
  92. package/dist/schema/@types/sitemapjson.js +1 -0
  93. package/dist/schema/@types/themejson.js +1 -0
  94. package/dist/schema/dist/app.js +1 -1
  95. package/dist/schema/dist/ext.js +1 -1
  96. package/dist/schema/dist/game.js +1 -1
  97. package/dist/schema/dist/page.js +1 -1
  98. package/dist/schema/dist/plugin.js +1 -1
  99. package/dist/schema/dist/pluginpage.js +1 -1
  100. package/dist/schema/dist/projectconfig.js +37 -1
  101. package/dist/schema/dist/projectprivateconfig.js +1 -1
  102. package/dist/schema/dist/sitemap.js +1 -1
  103. package/dist/schema/dist/theme.js +1 -1
  104. package/dist/schema/src/index.js +1 -0
  105. package/dist/utils/codesign.js +1 -1
  106. package/dist/utils/cp.js +1 -1
  107. package/dist/utils/miniapp-builder.js +1 -1
  108. package/dist/utils/miniappJson.js +1 -1
  109. package/dist/utils/progressRecorder.js +1 -1
  110. package/dist/utils/subprocess/processManager.js +1 -1
  111. package/dist/utils/taskstatus.js +1 -1
  112. package/dist/utils/tools.js +1 -1
  113. package/dist/utils/usbProcess.js +1 -0
  114. package/package.json +1 -1
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.runSummerPluginHook=void 0;const customError_1=require("../../../utils/customError"),summerCPProject_1=require("../../../project/summerCPProject"),index_1=require("../../precompiler/index"),initPlugin_1=require("./initPlugin");class PluginContainer{constructor(){this.initedPlugins=new Map}getPluginInstance(r,e,t){let n=this.initedPlugins.get(r);return n||(n=(0,initPlugin_1.initPlugin)(r,e,t),this.initedPlugins.set(r,n)),n}clear(){this.initedPlugins.clear()}}const pluginContainer=new PluginContainer;async function runSummerPluginHook(r){var e;if("clear"===r.command)return pluginContainer.clear(),{};const{plugin:t,projectInfo:n,pluginOption:i,method:o,args:u}=r,l=new summerCPProject_1.SummerCPProject(n);await l.ready();const{targetPlatform:s,targetPlatformDefines:a}=n,c=new index_1.PreCompiler(l),m=await c.getPreCompileProject({targetPlatform:s,targetPlatformDefines:a,runEnv:"worker cp"}),P=pluginContainer.getPluginInstance(t,m,i);if("runMethod"===r.command){const r=null===(e=P.workerMethods)||void 0===e?void 0:e[o];if(!r||"function"!=typeof r)throw new Error(`the ${r} is not a workerMethod of plugin(${t})`);try{return{result:await r(...u)}}catch(r){return{error:r instanceof customError_1.CustomError?r.toJSON():r}}}return{}}exports.runSummerPluginHook=runSummerPluginHook;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.runSummerPluginHook=void 0;const customError_1=require("../../../utils/customError"),summerCPProject_1=require("../../../project/summerCPProject"),index_1=require("../../precompiler/index"),initPlugin_1=require("./initPlugin");class PluginContainer{constructor(){this.initedPlugins=new Map}getPluginInstance(r,e,t){let n=this.initedPlugins.get(r);return n||(n=(0,initPlugin_1.initPlugin)(r,e,t),this.initedPlugins.set(r,n)),n}clear(){this.initedPlugins.clear()}}const pluginContainer=new PluginContainer;async function runSummerPluginHook(r){var e;if("clear"===r.command)return pluginContainer.clear(),{};const{plugin:t,projectInfo:n,pluginOption:i,method:o,args:u}=r,l=new summerCPProject_1.SummerCPProject(n);await l.ready();const{targetPlatform:s,targetPlatformDefines:a}=n,c=new index_1.PreCompiler(l,void 0,void 0),m=await c.getPreCompileProject({targetPlatform:s,targetPlatformDefines:a,runEnv:"worker cp"}),P=pluginContainer.getPluginInstance(t,m,i);if("runMethod"===r.command){const r=null===(e=P.workerMethods)||void 0===e?void 0:e[o];if(!r||"function"!=typeof r)throw new Error(`the ${r} is not a workerMethod of plugin(${t})`);try{return{result:await r(...u)}}catch(r){return{error:r instanceof customError_1.CustomError?r.toJSON():r}}}return{}}exports.runSummerPluginHook=runSummerPluginHook;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.SummerCompiler=void 0;const tslib_1=require("tslib"),path_1=tslib_1.__importDefault(require("path")),lodash_1=tslib_1.__importDefault(require("lodash")),locales_1=tslib_1.__importDefault(require("../../utils/locales/locales")),request_1=require("../../utils/request"),progressRecorder_1=require("../../utils/progressRecorder"),common_1=require("./original/compile/common"),tools_1=require("../../utils/tools"),white_ext_list_1=require("../../utils/white_ext_list"),config_1=require("../../config/config"),processManager_1=require("../../utils/subprocess/processManager"),messageHub_1=require("../../utils/messageHub"),singletontask_1=require("../../utils/singletontask"),uglifyfilenames_1=require("./original/protect/uglifyfilenames"),index_1=require("./original/index"),baseCompiler_1=require("./baseCompiler"),packOptionsHelper_1=tslib_1.__importDefault(require("../../utils/packOptionsHelper")),miniProgram=config_1.COMPILE_TYPE.miniProgram,miniGame=config_1.COMPILE_TYPE.miniGame,miniProgramPlugin=config_1.COMPILE_TYPE.miniProgramPlugin,miniGamePlugin=config_1.COMPILE_TYPE.miniGamePlugin;function performanceMark(e,t){}class SummerCompiler extends baseCompiler_1.BaseCoreCompiler{constructor(e,t,i,s,o,r){super(e),this.project=e,this.cachePath=t,this.projectInfo=i,this.devtoolMessagehub=s,this.analyzer=o,this._filterFactory=r,this.isSummer=!0,this.codeCache=new Map,this.promiseCache=new Map,this._taskCache=new Map,this._status=void 0,this._eventAdded=!1,this._locale="",this.codeCacheByPath=new Map,this.onFileChange=(e,t)=>{if("change"!==e||t.endsWith(".json"))for(const e of this.promiseCache.keys())e.startsWith("getConf-")&&this.promiseCache.delete(e);if("change"!==e){for(const e of this.promiseCache.keys())e.startsWith("getPackageFiles-")&&this.promiseCache.delete(e);for(const e of this._taskCache.keys())e.startsWith("getPackageFiles-")&&this._taskCache.delete(e)}this.invalidCodeCache(t),this.subProcessManager.sendEvent("fileChange",{type:e,targetPath:t})},this.onPreCompileOptionsChange=async e=>{await this.clearCache(),this.subProcessManager.sendEvent("precompileOptionsChange",e)},this.onProgressUpdate=(e,t,i)=>{const s="warn"===t?"warn":"doing"===t?"doing":"done"===t?"success":"error";this.messageHub.showBuildLog(""+e,s,i)},this._getPackageFiles=async(e,t,i="dev")=>{performanceMark("request get getPackageFiles");const s=await this.subProcessManager.runTask("getPackageFiles",{graphId:e,root:t},this.onProgressUpdate);performanceMark("request get getPackageFiles",!0);const o=this.isPluginType(e)?this.project.pluginRoot:this.project.miniprogramRoot,r=await this.filterFactory(i),a={},n=s.filter(t=>{const i=path_1.default.posix.join(o,t.path),s=r(e,i);return s!==config_1.EFilterCode.Include&&(a[s]||(a[s]=[]),a[s].push(i)),s===config_1.EFilterCode.Include}),c={[config_1.EFilterCode.AnalyseNoUse]:locales_1.default.config.UNUSE_FILE_LIST,[config_1.EFilterCode.PackOptionsIgnore]:locales_1.default.config.PACK_OPTIONS_IGNORE_LIST,[config_1.EFilterCode.PartialCompileNoUse]:locales_1.default.config.PARTIAL_COMPILE_IGNORE_LIST};for(const e in a)c[e]?this.onProgressUpdate(e,"warn",c[e].format(a[e].join(","))):this.onProgressUpdate(e,"warn",locales_1.default.config.UNKNOWN_REASON_INGORE_LIST.format(e,a[e].join(",")));return n},performanceMark("create summer compiler"),this.messageHub=new messageHub_1.MessageHub(s),this.ready()}get status(){return this._status}async init(){performanceMark("init summer compiler");const e=path_1.default.posix.join(__dirname,"./summerEntryProcess.js");this.subProcessManager=new processManager_1.SubProcessProxy(this.project,e,{cachePath:this.cachePath},this.projectInfo,8891),this.addProjectListener(),this.loadStatus(),performanceMark("init summer compiler",!0)}async loadStatus(){this._status=await this.subProcessManager.runTask("loadStatus")}destroy(){var e;null===(e=this.subProcessManager)||void 0===e||e.destroy(),this.removeProjectListener(),this._checkReadyTask=void 0}async clearCache(){var e;await(null===(e=this.subProcessManager)||void 0===e?void 0:e.runTask("clearCache")),this.codeCache.clear(),this.promiseCache.clear(),this.codeCacheByPath.clear(),this._taskCache.clear()}updateOptions(e){var t;lodash_1.default.isEqual(e,this.projectInfo)||(this.projectInfo=e,this.promiseCache.clear(),this.codeCache.clear(),this.codeCacheByPath.clear(),null===(t=this.subProcessManager)||void 0===t||t.sendEvent("updateOptions",e),this.loadStatus(),this.project.updateOptions(e))}addProjectListener(){var e,t;this._eventAdded&&this.removeProjectListener(),null===(e=this.project.event)||void 0===e||e.on("fileChange",this.onFileChange),null===(t=this.project.event)||void 0===t||t.on("precompileOptionsChange",this.onPreCompileOptionsChange),this._eventAdded=!0}removeProjectListener(){var e,t;null===(e=this.project.event)||void 0===e||e.off("fileChange",this.onFileChange),null===(t=this.project.event)||void 0===t||t.off("precompileOptionsChange",this.onPreCompileOptionsChange),this._eventAdded=!1}invalidCodeCache(e){for(const e of this.codeCache.values())e.isValid=!1;this.codeCacheByPath.delete((0,tools_1.sourcePathToTargetPath)(e))}async getConf(e){var t,i;const s="getConf-"+e;if(this.promiseCache.has(s))return(null===(t=process.env)||void 0===t?void 0:t.isDevtools)&&console.log(s,"hit cache"),this.promiseCache.get(s);(null===(i=process.env)||void 0===i?void 0:i.isDevtools)&&console.log(s,"do request"),performanceMark("request get conf");const o={graphId:e},r=this.subProcessManager.runTask("getConf",o,this.onProgressUpdate);return this.promiseCache.set(s,r),performanceMark("request get conf",!0),r}async getPackageFiles(e,t,i="dev",s=!0){const o=`getPackageFiles-${e}-${t}-${i}`;if(this._taskCache.has(o)&&s){const e=this._taskCache.get(o);return null==e?void 0:e.getResult(!0)}const r=new singletontask_1.SingletonTask(this._getPackageFiles.bind(this,e,t,i),o);return this._taskCache.set(o,r),null==r?void 0:r.getResult(!0)}async filterFactory(e){packOptionsHelper_1.default.updateState(this.project),this.onProgressUpdate("initUnusedFiles","doing","analyzing codes..."),await packOptionsHelper_1.default.initUnusedFiles(this.project,this.analyzer,"prod"===e),this.onProgressUpdate("initUnusedFiles","done","analyzing codes success");const t=this._filterFactory?await this._filterFactory(e):()=>0;return(i,s)=>"mini-android"!==this.project.targetPlatform&&"mini-ios"!==this.project.targetPlatform||path_1.default.posix.join(this.project.miniprogramRoot,"app.miniapp.json")!==s?i===miniProgram&&packOptionsHelper_1.default.isIgnoreByUnusedFiles(s,"prod"===e)?config_1.EFilterCode.AnalyseNoUse:packOptionsHelper_1.default.isIgnoredByRules(s)?config_1.EFilterCode.PackOptionsIgnore:t(i,s):config_1.EFilterCode.Include}async getCodeByFileList(e,t){const i={},s={},o=this.isPluginType(e)?this.project.pluginRoot:this.project.miniprogramRoot;for(const e of t){const t=this.codeCacheByPath.get(path_1.default.posix.join(o,e));t&&("error"in t||(i[e]=t.md5,s[e]=t))}const r=await this.subProcessManager.runTask("getDevCodeByFileList",{graphId:e,fileList:t,cacheMd5:i},this.onProgressUpdate);console.error(r);for(const e in r){const t=r[e],i=path_1.default.posix.join(o,e);"error"in t||""!==t.md5?this.codeCacheByPath.set(i,t):this.codeCacheByPath.delete(i),s[e]=t}return s}async getCode(e,t){var i,s,o;const r=`getCode-${e}${t?"-"+t.package:""}`;if(this.promiseCache.has(r))return(null===(i=process.env)||void 0===i?void 0:i.isDevtools)&&console.log(r,"hit promise cache"),this.promiseCache.get(r);const a=this.codeCache.get(r);if(null==a?void 0:a.isValid)return a.codeFiles;(null===(s=process.env)||void 0===s?void 0:s.isDevtools)&&console.log(r,"do request");const n={};if(a){const{codeFiles:e}=a;for(const t of Object.keys(e)){const i=e[t];"error"in i||(n[t]=i.md5)}}const c={graphId:e,cacheMd5:n,package:null==t?void 0:t.package};performanceMark("request get code");const l=Date.now();(null===(o=process.env)||void 0===o?void 0:o.isDevtools)&&(console.time("[summer-compiler] runTask "+r),console.log(`[summer-compiler] [${(0,progressRecorder_1.getPrintTime)()}] runTask ${r}`));const g=this.subProcessManager.runTask("getCode",c,this.onProgressUpdate).then(e=>{var t,i;(null===(t=process.env)||void 0===t?void 0:t.isDevtools)&&console.timeEnd("[summer-compiler] runTask "+r);const s=(null===(i=this.codeCache.get(r))||void 0===i?void 0:i.codeFiles)||{};for(const t of Object.keys(e)){const i=e[t];"error"in i||""!==i.md5?s[t]=i:delete s[t]}return this.codeCache.set(r,{isValid:!0,codeFiles:s}),s},e=>{throw e.code?console.error(e):console.error("Unexpected error when getCode",e),e});return g.finally(()=>{var e;performanceMark("request get code",!0),(null===(e=process.env)||void 0===e?void 0:e.isDevtools)&&console.log(`[summer-compiler] [${(0,progressRecorder_1.getPrintTime)()}] [cost ${Date.now()-l}ms] runTask ${r}`),this.promiseCache.delete(r)}),this.promiseCache.set(r,g),g}async getExtJSON(){return await(0,index_1.getExtJSON)(this.project)}async getAppJSON(){return(await this.getConf(miniProgram)).app}async getGameJSON(){return(await this.getConf(miniGame)).app}async getSiteMapJSON(){return(await this.getConf(miniProgram)).sitemap}async getPageJSON(e){const t=await this.getConf(miniProgram),i=t.pages[e]||t.comps[e];if(!i)throw new Error("summer-compiler 收集json配置有遗漏, "+e);return i}async getAllPageAndComponent(){const e=await this.getConf(miniProgram),t=(await this.getPackageFiles(miniProgram,config_1.FullPkg)).map(e=>e.path).filter(e=>e.endsWith(".json"));return Object.keys(e.pages).concat(Object.keys(e.comps)).filter(e=>t.includes(e+".json"))}async getAllSortedJSFiles(){const e=await this.getConf(miniProgram),t=Object.keys(e.pages),i=Object.keys(e.comps),s=(await this.getPackageFiles(miniProgram,config_1.FullPkg)).map(e=>e.path).filter(e=>e.endsWith(".js")),o=t.filter(e=>!i.includes(e)).map(e=>e+".js").filter(e=>s.includes(e)),r=i.map(e=>e+".js").filter(e=>s.includes(e)),a=s.filter(e=>e.endsWith(".js")&&"app.js"!==e&&!o.includes(e)&&!r.includes(e));return{jsPagesFiles:o,components:r,otherJsFiles:a}}async getAllWxmlAndWxsFiles(){const e=await this.getCode(miniProgram,{package:config_1.FullPkg}),t=Object.keys(e).filter(e=>e.endsWith(".wxml")),i=Object.keys(e).filter(e=>e.endsWith(".wxs"));return{wxmlFiles:t,wxsFiles:i,content:t.concat(i).reduce((t,i)=>{const s=e[i];if("error"in s)throw s.error;return t[i]=s.code,t["./"+i]=s.code,t},{})}}async getPackageWxmlAndWxsFiles(e){let t=(await this.getPackageFiles(miniProgram,e)).map(e=>e.path);if(e!==config_1.MainPkg&&e!==config_1.FullPkg){const e=(await this.getPackageFiles(miniProgram,config_1.MainPkg)).map(e=>e.path);t=t.concat(e)}const i=t.filter(e=>e.endsWith(".wxml")),s=t.filter(e=>e.endsWith(".wxs")),o=await this.getCodeByFileList(miniProgram,i.concat(s));return{wxmlFiles:i,wxsFiles:s,content:i.concat(s).reduce((e,t)=>{const i=o[t];if(!i)throw`lack of ${t} code`;if("error"in i)throw i.error;return e[t]=i.code,e["./"+t]=i.code,e},{})}}async getPackageWxssFileList(e){let t=(await this.getPackageFiles(miniProgram,e)).map(e=>e.path);if(e!==config_1.MainPkg&&e!==config_1.FullPkg){const e=(await this.getPackageFiles(miniProgram,config_1.MainPkg)).map(e=>e.path);t=t.concat(e)}return t.filter(e=>e.endsWith(".wxss"))}async getPackageWxssFiles(e){const t=await this.getPackageWxssFileList(e),i=await this.getCodeByFileList(miniProgram,t);return{wxssFiles:t,content:t.reduce((e,t)=>{const s=i[t];if(!s)throw`lack of ${t} code`;if("error"in s)throw s.error;return e[t]=s.code,e["./"+t]=s.code,e},{})}}getWxssMap(e,t){t=(0,tools_1.normalizePath)(t);for(const[i,s]of this.codeCache.entries())if(i.startsWith("getCode-"+e)){const e=s.codeFiles[t];if(e&&!("error"in e))return e.map}}async getMainPkgSortedJSFiles(){const e=await this.getConf(miniProgram),t=(await this.getPackageFiles(miniProgram,config_1.MainPkg)).map(e=>e.path).filter(e=>e.endsWith(".js")),i=[],s=[],o=[],r=[],a=[];let n=!1;const c={},l=t=>Object.keys(e.packages).find(e=>t.startsWith(e))||config_1.MainPkg;e.app.functionalPages&&t.forEach(e=>{if(e.startsWith("functional-pages/")){const t=e.replace(/\.js$/,"");if(c[t])return;c[t]=!0,a.push(encodeURI(t))}}),e.app.workers&&t.forEach(t=>{if(t.startsWith((0,tools_1.getWorkersPath)(e.app.workers))){const e=t.replace(/\.js$/,"");if(c[e])return;c[e]=!0,r.push(e)}});Object.keys(e.comps).filter(e=>l(e)===config_1.MainPkg).forEach(t=>{if((t.startsWith("miniprogram_npm/weui-miniprogram")||t.startsWith("weui-miniprogram"))&&e.app.useExtendedLib&&e.app.useExtendedLib.weui)return;if(c[t])return;c[t]=!0;const i=encodeURI(t);o.push(""+i)});Object.keys(e.pages).filter(e=>l(e)===config_1.MainPkg).forEach(e=>{if(c[e])return;c[e]=!0;const t=encodeURI(e);i.push(""+t)}),t.forEach(e=>{const t=e.replace(/\.js$/,"");c[t]||(c[t]=!0,"app.js"!==e?s.push(""+encodeURI(t)):n=!0)});const g=[...s,...o,...i];return n&&g.push("app"),{hasAppJS:n,allFiles:g,pageFiles:i,componentFiles:o,workerFiles:r,functionalPageFiles:a,otherFiles:s}}async getSubPkgSortedJSFiles(e){const t=await this.getConf(miniProgram),i=(await this.getPackageFiles(miniProgram,e)).map(e=>e.path).filter(e=>e.endsWith(".js")),s=[],o=[],r=[],a={},n=e=>Object.keys(t.packages).find(t=>e.startsWith(t))||config_1.MainPkg;Object.keys(t.comps).filter(t=>n(t)===e).forEach(e=>{if((e.startsWith("miniprogram_npm/weui-miniprogram")||e.startsWith("weui-miniprogram"))&&t.app.useExtendedLib&&t.app.useExtendedLib.weui)return;if(a[e])return;a[e]=!0;const i=encodeURI(e);r.push(""+i)});Object.keys(t.pages).filter(t=>n(t)===e).forEach(e=>{if(a[e])return;a[e]=!0;const t=encodeURI(e);s.push(""+t)});let c=t.packages[e].entry||"";c&&(c=path_1.default.join(e,c),c=c.replace(/\.js$/,"")),i.forEach(e=>{const t=e.replace(/\.js$/,"");a[t]||(a[t]=!0,t!==c&&o.push(""+encodeURI(t)))});const l=i.map(e=>""+encodeURI(e.replace(/\.js$/,"")));return{entryJS:c,allFiles:l,pageFiles:s,componentFiles:r,otherFiles:o}}async compileJSList(e){const t=this.project.type;let i=config_1.COMPILE_TYPE.miniProgram;i=e.root===this.project.miniprogramRoot?this.isGameType(t)?config_1.COMPILE_TYPE.miniGame:config_1.COMPILE_TYPE.miniProgram:this.isGameType(t)?config_1.COMPILE_TYPE.miniGamePlugin:miniProgramPlugin;const s=await this.getCodeByFileList(i,e.fileList),o=[];for(const e in s){const t=s[e];if("error"in t)throw t.error;o.push(Object.assign({filePath:e,code:t.code,map:t.map},t.jsTag))}return o}async compileJS(e){const t=this.project.type;let i;if(e.root===this.project.miniprogramRoot){i=(await this.getCodeByFileList(this.isGameType(t)?config_1.COMPILE_TYPE.miniGame:config_1.COMPILE_TYPE.miniProgram,[e.filePath]))[e.filePath]}else{i=(await this.getCodeByFileList(this.isGameType(t)?config_1.COMPILE_TYPE.miniGamePlugin:miniProgramPlugin,[e.filePath]))[e.filePath]}if(!i){const t=new Error(`summer-compiler miss ${e.root} js file, ${e.filePath}`);throw t.code="ENOENT",t}if("error"in i)throw i.error;return Object.assign({filePath:e.filePath,code:i.code,map:i.map},i.jsTag)}async compile(e){Date.now();const t=(await this.getPackageFiles(this.isGameType(this.project.type)?miniGame:miniProgram,config_1.FullPkg,e.resultType,e.useCache)).map(e=>e.path),i=await this.subProcessManager.runTask("compileNewLogic",Object.assign(Object.assign({},e),{fileList:t}),this.onProgressUpdate),s=i.app,o=Object.keys(s).filter(e=>e.endsWith(".json"));this.onProgressUpdate(111,"doing","打包资源文件");const r=await this.compileOther(this.isGameType(this.project.type)?miniGame:miniProgram,e.resultType||"prod",o);let a={};if(this.isPluginType(this.project.type)){const t=i.plugin,o=Object.keys(t).filter(e=>e.endsWith(".json")),n=await this.compileOther(this.isGameType(this.project.type)?miniGamePlugin:miniProgramPlugin,e.resultType||"prod",o);Object.keys(r).forEach(e=>{a[path_1.default.posix.join("miniprogram",e)]=r[e]}),Object.keys(n).forEach(e=>{a[path_1.default.posix.join("plugin",e)]=n[e]}),Object.keys(s).forEach(e=>{a[path_1.default.posix.join("miniprogram",e)]=s[e]}),Object.keys(t).forEach(e=>{a[path_1.default.posix.join("plugin",e)]=t[e]}),a["project.config.json"]=JSON.stringify({miniprogramRoot:"miniprogram",pluginRoot:"plugin",__compileDebugInfo__:{useSummer:!0}})}else a=Object.assign(Object.assign({},r),s),a["project.config.json"]=JSON.stringify({miniprogramRoot:"",__compileDebugInfo__:{useSummer:!0}});this.onProgressUpdate(111,"done","打包资源文件完成");for(const e of Object.keys(a))"object"==typeof a[e]&&"Buffer"===a[e].type&&(a[e]=Buffer.from(a[e].data));return a}async compileOther(e,t,i){const s=(0,tools_1.getSupportCodeFileExtSet)(this.project);s.delete(".json");const o=await(0,white_ext_list_1.getWhiteExtList)();let r=o.MiniProgramWhiteList;this.isGameType(this.project.type)&&(r=o.GameWhiteList);const a=this.isPluginType(e)?this.project.pluginRoot:this.project.miniprogramRoot,n=await this.filterFactory(t),c=this.project.getFileList(a,"").filter(t=>{const o=path_1.default.posix.extname(t),c=path_1.default.posix.relative(a,t);return!(!r.has(o)||s.has(o)||i.includes(c))&&n(e,t)===config_1.EFilterCode.Include}),l=await(0,common_1.compileOther)(this.project,c,{onProgressUpdate:()=>{}}),g={};for(const e in l){g[path_1.default.posix.relative(a,e)]=l[e]}return g}async compile2(e){const t=await this.subProcessManager.runTask("compile",e,(t,i,s)=>{var o;null===(o=e.onProgressUpdate)||void 0===o||o.call(e,{id:t.toString(),status:i,message:s})});for(const e of Object.keys(t))"object"==typeof t[e]&&"Buffer"===t[e].type&&(t[e]=Buffer.from(t[e].data));return t}async getPluginJSON(e=""){return(await this.getConf(this.isGameType(this.project.type)?miniGamePlugin:miniProgramPlugin)).plugin}async getPluginPageJSON(e){const t=await this.getConf(miniProgramPlugin),i=t.pages[e]||t.comps[e];if(!i)throw new Error("summer-compiler 收集plugin json配置有遗漏, "+e);return i}async getPluginComponents(){const e=await this.getConf(miniProgramPlugin),t=new Set(Object.keys(e.pages).concat(Object.keys(e.comps)));return Array.from(t)}async getPluginJSFiles(){const e=this.isGameType(this.project.type)?miniGamePlugin:miniProgramPlugin,t=(await this.getPackageFiles(e,config_1.FullPkg)).map(e=>e.path).filter(e=>e.endsWith(".js")),i=await this.getCodeByFileList(e,t);return{jsFiles:t,content:t.reduce((e,t)=>{const s=i[t];if(!s)throw`lack of ${t} code`;if("error"in s)throw s.error;return e[t]=s.code,e["./"+t]=s.code,e},{})}}async getPluginWxssFiles(){const e=(await this.getPackageFiles(miniProgramPlugin,config_1.FullPkg)).map(e=>e.path).filter(e=>e.endsWith(".wxss")),t=await this.getCodeByFileList(miniProgramPlugin,e);return{wxssFiles:e,content:e.reduce((e,i)=>{const s=t[i];if(!s)throw`lack of ${i} code`;if("error"in s)throw s.error;return e[i]=s.code,e["./"+i]=s.code,e},{})}}async getPluginWxmlAndWxsFiles(){const e=(await this.getPackageFiles(miniProgramPlugin,config_1.FullPkg)).map(e=>e.path),t=e.filter(e=>e.endsWith(".wxml")),i=e.filter(e=>e.endsWith(".wxs")),s=await this.getCodeByFileList(miniProgramPlugin,t.concat(i));return{wxmlFiles:t,wxsFiles:i,content:t.concat(i).reduce((e,t)=>{const i=s[t];if(!i)throw`lack of ${t} code`;if("error"in i)throw i.error;return e[t]=i.code,e["./"+t]=i.code,e},{})}}async checkThemeJSON(e){return(await this.getConf(miniProgram)).theme}setProxy(e){(0,request_1.setCiProxy)(e)}setLocale(e){this._locale!==e&&(this._locale=e,this.subProcessManager.runTask("setLocale",e))}async uglifyFileNames(e,t,i){return await(0,uglifyfilenames_1.uglifyFileNames)(e,t,i)}async getMPFileInfo(){return this.subProcessManager.runTask("getLocalFileList",miniProgram)}async getPluginFileInfo(){return this.subProcessManager.runTask("getLocalFileList",miniProgramPlugin)}async getCompAndPagesOfConf(){const e=await this.getConf(miniProgram);return{pages:e.pages,comps:e.comps}}async getFiltedFileListReason(e){const t=this.project.getFileList(this.project.miniprogramRoot),i=[],s=await this.filterFactory(e),o=this.isGameType(this.project.type)?miniGame:miniProgram;for(const e of t){const t=s(o,e);t!==config_1.EFilterCode.Include&&i.push({file:e,code:t})}if(this.isPluginType(this.project.type)){const e=this.project.getFileList(this.project.pluginRoot),t=this.isGameType(this.project.type)?miniGamePlugin:miniProgramPlugin;for(const o of e){const e=s(t,o);e!==config_1.EFilterCode.Include&&i.push({file:o,code:e})}}return i}}exports.SummerCompiler=SummerCompiler;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.SummerCompiler=void 0;const tslib_1=require("tslib"),path_1=tslib_1.__importDefault(require("path")),lodash_1=tslib_1.__importDefault(require("lodash")),locales_1=tslib_1.__importDefault(require("../../utils/locales/locales")),request_1=require("../../utils/request"),common_1=require("./original/compile/common"),tools_1=require("../../utils/tools"),white_ext_list_1=require("../../utils/white_ext_list"),config_1=require("../../config/config"),processManager_1=require("../../utils/subprocess/processManager"),messageHub_1=require("../../utils/messageHub"),singletontask_1=require("../../utils/singletontask"),uglifyfilenames_1=require("./original/protect/uglifyfilenames"),index_1=require("./original/index"),baseCompiler_1=require("./baseCompiler"),packOptionsHelper_1=tslib_1.__importDefault(require("../../utils/packOptionsHelper")),miniProgram=config_1.COMPILE_TYPE.miniProgram,miniGame=config_1.COMPILE_TYPE.miniGame,miniProgramPlugin=config_1.COMPILE_TYPE.miniProgramPlugin,miniGamePlugin=config_1.COMPILE_TYPE.miniGamePlugin;function performanceMark(e,t){}class SummerCompiler extends baseCompiler_1.BaseCoreCompiler{constructor(e,t,i,s,o,r){super(e),this.project=e,this.cachePath=t,this.projectInfo=i,this.devtoolMessagehub=s,this.analyzer=o,this._filterFactory=r,this.isSummer=!0,this.promiseCache=new Map,this._taskCache=new Map,this._status=void 0,this._eventAdded=!1,this._locale="",this.devCodeCacheByPath=new Map,this.onFileChange=(e,t)=>{if("change"!==e||t.endsWith(".json"))for(const e of this.promiseCache.keys())e.startsWith("getConf-")&&this.promiseCache.delete(e);if("change"!==e){for(const e of this.promiseCache.keys())e.startsWith("getPackageFiles-")&&this.promiseCache.delete(e);for(const e of this._taskCache.keys())e.startsWith("getPackageFiles-")&&this._taskCache.delete(e)}this.invalidCodeCache(t),this.subProcessManager.sendEvent("fileChange",{type:e,targetPath:t})},this.onPreCompileOptionsChange=async e=>{await this.clearCache(),this.subProcessManager.sendEvent("precompileOptionsChange",e)},this.onProgressUpdate=(e,t,i)=>{var s;this.messageHub.showBuildLog(""+e,t,i),null===(s=this.progressUpdateFromCompileOptions)||void 0===s||s.call(this,{id:e.toString(),message:i,status:t})},this._getPackageFiles=async(e,t,i="dev")=>{performanceMark("request get getPackageFiles");const s=await this.subProcessManager.runTask("getPackageFiles",{graphId:e,root:t},this.onProgressUpdate);performanceMark("request get getPackageFiles",!0);const o=this.isPluginType(e)?this.project.pluginRoot:this.project.miniprogramRoot,r=await this.filterFactory(i),a={},n=s.filter(t=>{const i=path_1.default.posix.join(o,t.path),s=r(e,i);return s!==config_1.EFilterCode.Include&&(a[s]||(a[s]=[]),a[s].push(i)),s===config_1.EFilterCode.Include}),c={[config_1.EFilterCode.AnalyseNoUse]:locales_1.default.config.UNUSE_FILE_LIST,[config_1.EFilterCode.PackOptionsIgnore]:locales_1.default.config.PACK_OPTIONS_IGNORE_LIST,[config_1.EFilterCode.PartialCompileNoUse]:locales_1.default.config.PARTIAL_COMPILE_IGNORE_LIST};for(const e in a)c[e]?this.onProgressUpdate(e,"warn",c[e].format(a[e].join(","))):this.onProgressUpdate(e,"warn",locales_1.default.config.UNKNOWN_REASON_INGORE_LIST.format(e,a[e].join(",")));return n},performanceMark("create summer compiler"),this.messageHub=new messageHub_1.MessageHub(s),this.ready()}get status(){return this._status}async init(){performanceMark("init summer compiler");const e=path_1.default.posix.join(__dirname,"./summerEntryProcess.js");this.subProcessManager=new processManager_1.SubProcessProxy(this.project,e,{cachePath:this.cachePath},this.projectInfo,8891,this.onProgressUpdate),this.addProjectListener(),this.loadStatus(),performanceMark("init summer compiler",!0)}async loadStatus(){this._status=await this.subProcessManager.runTask("loadStatus")}destroy(){var e;null===(e=this.subProcessManager)||void 0===e||e.destroy(),this.removeProjectListener(),this._checkReadyTask=void 0}async clearCache(){var e;await(null===(e=this.subProcessManager)||void 0===e?void 0:e.runTask("clearCache")),this.promiseCache.clear(),this.devCodeCacheByPath.clear(),this._taskCache.clear()}updateOptions(e){var t;lodash_1.default.isEqual(e,this.projectInfo)||(this.projectInfo=e,this.promiseCache.clear(),this.devCodeCacheByPath.clear(),null===(t=this.subProcessManager)||void 0===t||t.sendEvent("updateOptions",e),this.loadStatus(),this.project.updateOptions(e))}addProjectListener(){var e,t;this._eventAdded&&this.removeProjectListener(),null===(e=this.project.event)||void 0===e||e.on("fileChange",this.onFileChange),null===(t=this.project.event)||void 0===t||t.on("precompileOptionsChange",this.onPreCompileOptionsChange),this._eventAdded=!0}removeProjectListener(){var e,t;null===(e=this.project.event)||void 0===e||e.off("fileChange",this.onFileChange),null===(t=this.project.event)||void 0===t||t.off("precompileOptionsChange",this.onPreCompileOptionsChange),this._eventAdded=!1}invalidCodeCache(e){const t=this.devCodeCacheByPath.get((0,tools_1.sourcePathToTargetPath)(e));t&&(t.isValid=!1)}async getConf(e){var t,i;const s="getConf-"+e;if(this.promiseCache.has(s))return(null===(t=process.env)||void 0===t?void 0:t.isDevtools)&&console.log(s,"hit cache"),this.promiseCache.get(s);(null===(i=process.env)||void 0===i?void 0:i.isDevtools)&&console.log(s,"do request"),performanceMark("request get conf");const o={graphId:e},r=this.subProcessManager.runTask("getConf",o,this.onProgressUpdate);return this.promiseCache.set(s,r),performanceMark("request get conf",!0),r}async getPackageFiles(e,t,i="dev",s=!0){const o=`getPackageFiles-${e}-${t}-${i}`;if(this._taskCache.has(o)&&s){const e=this._taskCache.get(o);return null==e?void 0:e.getResult(!0)}const r=new singletontask_1.SingletonTask(this._getPackageFiles.bind(this,e,t,i),o);return this._taskCache.set(o,r),null==r?void 0:r.getResult(!0)}async filterFactory(e){packOptionsHelper_1.default.updateState(this.project),this.onProgressUpdate("initUnusedFiles","doing","analyzing codes..."),await packOptionsHelper_1.default.initUnusedFiles(this.project,this.analyzer,"prod"===e),0!==packOptionsHelper_1.default.getUnusedFiles().size&&this.onProgressUpdate("initUnusedFiles","doing","ignoring files: "+Array.from(packOptionsHelper_1.default.getUnusedFiles()).join(",")),this.onProgressUpdate("initUnusedFiles","success","analyzing codes success");const t=this._filterFactory?await this._filterFactory(e):()=>0;return(i,s)=>"mini-android"!==this.project.targetPlatform&&"mini-ios"!==this.project.targetPlatform||path_1.default.posix.join(this.project.miniprogramRoot,"app.miniapp.json")!==s?i===miniProgram&&packOptionsHelper_1.default.isIgnoreByUnusedFiles(s,"prod"===e)?config_1.EFilterCode.AnalyseNoUse:packOptionsHelper_1.default.isIgnoredByRules(s)?config_1.EFilterCode.PackOptionsIgnore:t(i,s):config_1.EFilterCode.Include}async getCodeByFileList(e,t){const i={},s={},o=this.isPluginType(e)?this.project.pluginRoot:this.project.miniprogramRoot,r=[];for(const e of t){const t=this.devCodeCacheByPath.get(path_1.default.posix.join(o,e)),a=null==t?void 0:t.codeFile;let n=!1;t&&t.isValid&&a&&!("error"in a)||(n=!0,r.push(e)),a&&!("error"in a)&&(n&&(i[e]=a.md5),s[e]=a)}if(r.length>0){const t=await this.subProcessManager.runTask("getDevCodeByFileList",{graphId:e,fileList:r,cacheMd5:i},this.onProgressUpdate);for(const e in t){const i=t[e],r=path_1.default.posix.join(o,e);"error"in i||""!==i.md5?this.devCodeCacheByPath.set(r,{isValid:!0,codeFile:i}):this.devCodeCacheByPath.delete(r),s[e]=i}}return s}async getExtJSON(){return await(0,index_1.getExtJSON)(this.project)}async getAppJSON(){return(await this.getConf(miniProgram)).app}async getGameJSON(){return(await this.getConf(miniGame)).app}async getSiteMapJSON(){return(await this.getConf(miniProgram)).sitemap}async getPageJSON(e){const t=await this.getConf(miniProgram),i=t.pages[e]||t.comps[e];if(!i)throw new Error("summer-compiler 收集json配置有遗漏, "+e);return i}async getAllPageAndComponent(){const e=await this.getConf(miniProgram),t=(await this.getPackageFiles(miniProgram,config_1.FullPkg)).map(e=>e.path).filter(e=>e.endsWith(".json"));return Object.keys(e.pages).concat(Object.keys(e.comps)).filter(e=>t.includes(e+".json"))}async getAllSortedJSFiles(){const e=await this.getConf(miniProgram),t=Object.keys(e.pages),i=Object.keys(e.comps),s=(await this.getPackageFiles(miniProgram,config_1.FullPkg)).map(e=>e.path).filter(e=>e.endsWith(".js")),o=t.filter(e=>!i.includes(e)).map(e=>e+".js").filter(e=>s.includes(e)),r=i.map(e=>e+".js").filter(e=>s.includes(e)),a=s.filter(e=>e.endsWith(".js")&&"app.js"!==e&&!o.includes(e)&&!r.includes(e));return{jsPagesFiles:o,components:r,otherJsFiles:a}}async getAllWxmlAndWxsFiles(){const e=(await this.getPackageFiles(miniProgram,config_1.FullPkg)).map(e=>e.path),t=e.filter(e=>e.endsWith(".wxml")),i=e.filter(e=>e.endsWith(".wxs")),s=await this.getCodeByFileList(miniProgram,t.concat(i));return{wxmlFiles:t,wxsFiles:i,content:t.concat(i).reduce((e,t)=>{const i=s[t];if("error"in i)throw i.error;return e[t]=i.code,e["./"+t]=i.code,e},{})}}async getPackageWxmlAndWxsFiles(e){let t=(await this.getPackageFiles(miniProgram,e)).map(e=>e.path);if(e!==config_1.MainPkg&&e!==config_1.FullPkg){const e=(await this.getPackageFiles(miniProgram,config_1.MainPkg)).map(e=>e.path);t=t.concat(e)}const i=t.filter(e=>e.endsWith(".wxml")),s=t.filter(e=>e.endsWith(".wxs")),o=await this.getCodeByFileList(miniProgram,i.concat(s));return{wxmlFiles:i,wxsFiles:s,content:i.concat(s).reduce((e,t)=>{const i=o[t];if(!i)throw`lack of ${t} code`;if("error"in i)throw i.error;return e[t]=i.code,e["./"+t]=i.code,e},{})}}async getPackageWxssFileList(e){let t=(await this.getPackageFiles(miniProgram,e)).map(e=>e.path);if(e!==config_1.MainPkg&&e!==config_1.FullPkg){const e=(await this.getPackageFiles(miniProgram,config_1.MainPkg)).map(e=>e.path);t=t.concat(e)}return t.filter(e=>e.endsWith(".wxss"))}async getPackageWxssFiles(e){const t=await this.getPackageWxssFileList(e),i=await this.getCodeByFileList(miniProgram,t);return{wxssFiles:t,content:t.reduce((e,t)=>{const s=i[t];if(!s)throw`lack of ${t} code`;if("error"in s)throw s.error;return e[t]=s.code,e["./"+t]=s.code,e},{})}}getWxssMap(e,t){t=(0,tools_1.normalizePath)(t),e===miniProgram?t=path_1.default.posix.join(this.project.miniprogramRoot,t):e===miniProgramPlugin&&(t=path_1.default.posix.join(this.project.pluginRoot,t));const i=this.devCodeCacheByPath.get(t),s=null==i?void 0:i.codeFile;if(s&&!("error"in s))return s.map}async getMainPkgSortedJSFiles(){const e=await this.getConf(miniProgram),t=(await this.getPackageFiles(miniProgram,config_1.MainPkg)).map(e=>e.path).filter(e=>e.endsWith(".js")),i=[],s=[],o=[],r=[],a=[];let n=!1;const c={},l=t=>Object.keys(e.packages).find(e=>t.startsWith(e))||config_1.MainPkg;e.app.functionalPages&&t.forEach(e=>{if(e.startsWith("functional-pages/")){const t=e.replace(/\.js$/,"");if(c[t])return;c[t]=!0,a.push(encodeURI(t))}}),e.app.workers&&t.forEach(t=>{if(t.startsWith((0,tools_1.getWorkersPath)(e.app.workers))){const e=t.replace(/\.js$/,"");if(c[e])return;c[e]=!0,r.push(e)}});Object.keys(e.comps).filter(e=>l(e)===config_1.MainPkg).forEach(t=>{if((t.startsWith("miniprogram_npm/weui-miniprogram")||t.startsWith("weui-miniprogram"))&&e.app.useExtendedLib&&e.app.useExtendedLib.weui)return;if(c[t])return;c[t]=!0;const i=encodeURI(t);o.push(""+i)});Object.keys(e.pages).filter(e=>l(e)===config_1.MainPkg).forEach(e=>{if(c[e])return;c[e]=!0;const t=encodeURI(e);i.push(""+t)}),t.forEach(e=>{const t=e.replace(/\.js$/,"");c[t]||(c[t]=!0,"app.js"!==e?s.push(""+encodeURI(t)):n=!0)});const g=[...s,...o,...i];return n&&g.push("app"),{hasAppJS:n,allFiles:g,pageFiles:i,componentFiles:o,workerFiles:r,functionalPageFiles:a,otherFiles:s}}async getSubPkgSortedJSFiles(e){const t=await this.getConf(miniProgram),i=(await this.getPackageFiles(miniProgram,e)).map(e=>e.path).filter(e=>e.endsWith(".js")),s=[],o=[],r=[],a={},n=e=>Object.keys(t.packages).find(t=>e.startsWith(t))||config_1.MainPkg;Object.keys(t.comps).filter(t=>n(t)===e).forEach(e=>{if((e.startsWith("miniprogram_npm/weui-miniprogram")||e.startsWith("weui-miniprogram"))&&t.app.useExtendedLib&&t.app.useExtendedLib.weui)return;if(a[e])return;a[e]=!0;const i=encodeURI(e);r.push(""+i)});Object.keys(t.pages).filter(t=>n(t)===e).forEach(e=>{if(a[e])return;a[e]=!0;const t=encodeURI(e);s.push(""+t)});let c=t.packages[e].entry||"";c&&(c=path_1.default.join(e,c),c=c.replace(/\.js$/,"")),i.forEach(e=>{const t=e.replace(/\.js$/,"");a[t]||(a[t]=!0,t!==c&&o.push(""+encodeURI(t)))});const l=i.map(e=>""+encodeURI(e.replace(/\.js$/,"")));return{entryJS:c,allFiles:l,pageFiles:s,componentFiles:r,otherFiles:o}}async compileJSList(e){const t=this.project.type;let i=config_1.COMPILE_TYPE.miniProgram;i=e.root===this.project.miniprogramRoot?this.isGameType(t)?config_1.COMPILE_TYPE.miniGame:config_1.COMPILE_TYPE.miniProgram:this.isGameType(t)?config_1.COMPILE_TYPE.miniGamePlugin:miniProgramPlugin;const s=await this.getCodeByFileList(i,e.fileList),o=[];for(const e in s){const t=s[e];if("error"in t)throw t.error;o.push(Object.assign({filePath:e,code:t.code,map:t.map,mtime:t.mtime},t.jsTag))}return o}async compileJS(e){const t=this.project.type;let i;if(e.root===this.project.miniprogramRoot){i=(await this.getCodeByFileList(this.isGameType(t)?config_1.COMPILE_TYPE.miniGame:config_1.COMPILE_TYPE.miniProgram,[e.filePath]))[e.filePath]}else{i=(await this.getCodeByFileList(this.isGameType(t)?config_1.COMPILE_TYPE.miniGamePlugin:miniProgramPlugin,[e.filePath]))[e.filePath]}if(!i){const t=new Error(`summer-compiler miss ${e.root} js file, ${e.filePath}`);throw t.code="ENOENT",t}if("error"in i)throw i.error;return Object.assign({filePath:e.filePath,code:i.code,map:i.map,mtime:i.mtime},i.jsTag)}async compile(e){Date.now();this.progressUpdateFromCompileOptions=e.onProgressUpdate;const t=(await this.getPackageFiles(this.isGameType(this.project.type)?miniGame:miniProgram,config_1.FullPkg,e.resultType,e.useCache)).map(e=>e.path),i=await this.subProcessManager.runTask("compileNewLogic",Object.assign(Object.assign({},e),{fileList:t,analyzer:void 0}),this.onProgressUpdate),s=i.app,o=Object.keys(s).filter(e=>e.endsWith(".json"));this.onProgressUpdate(111,"doing","打包资源文件");const r=await this.compileOther(this.isGameType(this.project.type)?miniGame:miniProgram,e.resultType||"prod",o);let a={};if(this.isPluginType(this.project.type)){const t=i.plugin,o=Object.keys(t).filter(e=>e.endsWith(".json")),n=await this.compileOther(this.isGameType(this.project.type)?miniGamePlugin:miniProgramPlugin,e.resultType||"prod",o);Object.keys(r).forEach(e=>{a[path_1.default.posix.join("miniprogram",e)]=r[e]}),Object.keys(n).forEach(e=>{a[path_1.default.posix.join("plugin",e)]=n[e]}),Object.keys(s).forEach(e=>{a[path_1.default.posix.join("miniprogram",e)]=s[e]}),Object.keys(t).forEach(e=>{a[path_1.default.posix.join("plugin",e)]=t[e]}),a["project.config.json"]=JSON.stringify({miniprogramRoot:"miniprogram",pluginRoot:"plugin",__compileDebugInfo__:{useSummer:!0}})}else a=Object.assign(Object.assign({},r),s),a["project.config.json"]=JSON.stringify({miniprogramRoot:"",__compileDebugInfo__:{useSummer:!0}});this.onProgressUpdate(111,"success","打包资源文件完成");for(const e of Object.keys(a))"object"==typeof a[e]&&"Buffer"===a[e].type&&(a[e]=Buffer.from(a[e].data));return a}async compileOther(e,t,i){const s=(0,tools_1.getSupportCodeFileExtSet)(this.project);s.delete(".json");const o=await(0,white_ext_list_1.getWhiteExtList)();let r=o.MiniProgramWhiteList;this.isGameType(this.project.type)&&(r=o.GameWhiteList);const a=this.isPluginType(e)?this.project.pluginRoot:this.project.miniprogramRoot,n=await this.filterFactory(t),c=this.project.getFileList(a,"").filter(t=>{const o=path_1.default.posix.extname(t),c=path_1.default.posix.relative(a,t);return!(!r.has(o)||s.has(o)||i.includes(c))&&n(e,t)===config_1.EFilterCode.Include}),l=await(0,common_1.compileOther)(this.project,c,{onProgressUpdate:()=>{}}),g={};for(const e in l){g[path_1.default.posix.relative(a,e)]=l[e]}return g}async compile2(e){const t=await this.subProcessManager.runTask("compile",e,(t,i,s)=>{var o;null===(o=e.onProgressUpdate)||void 0===o||o.call(e,{id:t.toString(),status:i,message:s})});for(const e of Object.keys(t))"object"==typeof t[e]&&"Buffer"===t[e].type&&(t[e]=Buffer.from(t[e].data));return t}async getPluginJSON(e=""){return(await this.getConf(this.isGameType(this.project.type)?miniGamePlugin:miniProgramPlugin)).plugin}async getPluginPageJSON(e){const t=await this.getConf(miniProgramPlugin),i=t.pages[e]||t.comps[e];if(!i)throw new Error("summer-compiler 收集plugin json配置有遗漏, "+e);return i}async getPluginComponents(){const e=await this.getConf(miniProgramPlugin),t=new Set(Object.keys(e.pages).concat(Object.keys(e.comps)));return Array.from(t)}async getPluginJSFiles(){const e=this.isGameType(this.project.type)?miniGamePlugin:miniProgramPlugin,t=(await this.getPackageFiles(e,config_1.FullPkg)).map(e=>e.path).filter(e=>e.endsWith(".js")),i=await this.getCodeByFileList(e,t);return{jsFiles:t,content:t.reduce((e,t)=>{const s=i[t];if(!s)throw`lack of ${t} code`;if("error"in s)throw s.error;return e[t]=s.code,e["./"+t]=s.code,e},{})}}async getPluginWxssFiles(){const e=(await this.getPackageFiles(miniProgramPlugin,config_1.FullPkg)).map(e=>e.path).filter(e=>e.endsWith(".wxss")),t=await this.getCodeByFileList(miniProgramPlugin,e);return{wxssFiles:e,content:e.reduce((e,i)=>{const s=t[i];if(!s)throw`lack of ${i} code`;if("error"in s)throw s.error;return e[i]=s.code,e["./"+i]=s.code,e},{})}}async getPluginWxmlAndWxsFiles(){const e=(await this.getPackageFiles(miniProgramPlugin,config_1.FullPkg)).map(e=>e.path),t=e.filter(e=>e.endsWith(".wxml")),i=e.filter(e=>e.endsWith(".wxs")),s=await this.getCodeByFileList(miniProgramPlugin,t.concat(i));return{wxmlFiles:t,wxsFiles:i,content:t.concat(i).reduce((e,t)=>{const i=s[t];if(!i)throw`lack of ${t} code`;if("error"in i)throw i.error;return e[t]=i.code,e["./"+t]=i.code,e},{})}}async checkThemeJSON(e){return(await this.getConf(miniProgram)).theme}setProxy(e){(0,request_1.setCiProxy)(e)}setLocale(e){this._locale!==e&&(this._locale=e,this.subProcessManager.runTask("setLocale",e))}async uglifyFileNames(e,t,i){return await(0,uglifyfilenames_1.uglifyFileNames)(e,t,i)}async getMPFileInfo(){return this.subProcessManager.runTask("getLocalFileList",miniProgram)}async getPluginFileInfo(){return this.subProcessManager.runTask("getLocalFileList",miniProgramPlugin)}async getCompAndPagesOfConf(){const e=await this.getConf(miniProgram);return{pages:e.pages,comps:e.comps}}async getFiltedFileListReason(e){const t=this.project.getFileList(this.project.miniprogramRoot),i=[],s=await this.filterFactory(e),o=this.isGameType(this.project.type)?miniGame:miniProgram;for(const e of t){const t=s(o,e);t!==config_1.EFilterCode.Include&&i.push({file:e,code:t})}if(this.isPluginType(this.project.type)){const e=this.project.getFileList(this.project.pluginRoot),t=this.isGameType(this.project.type)?miniGamePlugin:miniProgramPlugin;for(const o of e){const e=s(t,o);e!==config_1.EFilterCode.Include&&i.push({file:o,code:e})}}return i}}exports.SummerCompiler=SummerCompiler;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getSummerCompiler=exports.summerCompilerFactory=exports.SummerCompilerFactory=void 0;const tslib_1=require("tslib"),path_1=tslib_1.__importDefault(require("path")),lodash_1=tslib_1.__importDefault(require("lodash")),config_1=require("../config/config"),ciProject_1=require("../project/ciProject"),tools_1=require("../utils/tools"),locales_1=tslib_1.__importDefault(require("../utils/locales/locales")),packOptionsHelper_1=tslib_1.__importDefault(require("../utils/packOptionsHelper")),summerCompiler_1=require("./corecompiler/summerCompiler"),pluginconfig_1=require("./corecompiler/summer/pluginconfig"),WeappCompileCache="";class SummerCompilerFactory{constructor(){this.summerCompiler=null,this.project=null,this.createPromise=null,this.releaseCbs=[]}async getSummerCompiler(e,r){return this.shouldCreate(e)?(this.releaseLastCompiler(),this.project=e,this.summerCompiler=null,this.createPromise=this.createSummerCompiler(e,r),this.summerCompiler=await this.createPromise,this.summerCompiler.setLocale(locales_1.default.getLocale())):(this.summerCompiler||(this.summerCompiler=await this.createPromise),this.summerCompiler.updateOptions(this.getSummerOptions(e))),this.summerCompiler}shouldCreate(e){var r,t,i,o,s;if(!this.project)return!0;if(this.project.projectPath!==e.projectPath)return!0;if(!lodash_1.default.isEqual(this.project.packOptions,e.packOptions))return!0;const l=["es6","minified","postcss","uglifyFileName","compileWorklet","enhance","minifyWXML","minifyWXSS","disableUseStrict","swc","useCompilerPlugins","babelSetting","swcSetting","condition"],m=null!==(t=null===(r=this.project)||void 0===r?void 0:r.setting)&&void 0!==t?t:{},p=null!==(i=e.setting)&&void 0!==i?i:{};for(const e of l){const r=m[e],t=p[e];if(!lodash_1.default.isEqual(r,t))return console.info(`shouldCreate return true, project.setting.${e}, before: ${JSON.stringify(r)}, after: ${JSON.stringify(t)}`),!0}return(null===(o=this.project)||void 0===o?void 0:o.miniprogramRoot)!==e.miniprogramRoot||(null===(s=this.project)||void 0===s?void 0:s.pluginRoot)!==e.pluginRoot}async releaseLastCompiler(){const{releaseCbs:e}=this;if(this.releaseCbs=[],this.createPromise)try{(await this.createPromise).destroy(),e.forEach(e=>{try{e()}catch(e){console.error("[SummerCompilerFactory] releaseLastCompiler release cb execute error: "+e)}})}catch(e){console.error("[SummerCompilerFactory] releaseLastCompiler error: "+e)}}ensureCacheDir(){const e=path_1.default.join("",(0,tools_1.generateMD5)(this.project.projectPath+"|summer"));return(0,tools_1.mkdirSync)(e),e}async createSummerCompiler(e,r){const t=new ciProject_1.CIProject(e);await t.ready();const i=this.ensureCacheDir(),o=this.getSummerOptions(e),s=new summerCompiler_1.SummerCompiler(t,i,o,{showBuildLog:()=>{}},r);return await s.ready(),s}getFileFilter(e){packOptionsHelper_1.default.updateState(e);return r=>{const t=r.startsWith(e.miniprogramRoot)&&packOptionsHelper_1.default.isIgnoredByRules(r.slice(e.miniprogramRoot.length)),i=e.pluginRoot&&r.startsWith(e.pluginRoot)&&packOptionsHelper_1.default.isIgnoredByRules(r.slice(e.pluginRoot.length));return!t&&!i}}getSummerOptions(e){const r=(0,pluginconfig_1.getSummerPluginConfig)(e.setting),t={[config_1.compileTypeConfig.weapp]:"miniProgram",[config_1.compileTypeConfig.plugin]:"miniProgramPlugin",[config_1.compileTypeConfig.game]:"miniGame",[config_1.compileTypeConfig.gamePlugin]:"miniGamePlugin"}[e.compileType];return{appid:e.appid,attr:e.attr,projectArchitecture:e.projectArchitecture,miniprogramRoot:e.miniprogramRoot,pluginRoot:e.pluginRoot,compileType:t,summerPlugins:r,setting:Object.assign({},e.setting)}}}exports.SummerCompilerFactory=SummerCompilerFactory,exports.summerCompilerFactory=new SummerCompilerFactory,exports.getSummerCompiler=exports.summerCompilerFactory.getSummerCompiler.bind(exports.summerCompilerFactory);
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getSummerCompiler=exports.summerCompilerFactory=exports.SummerCompilerFactory=void 0;const tslib_1=require("tslib"),path_1=tslib_1.__importDefault(require("path")),lodash_1=tslib_1.__importDefault(require("lodash")),config_1=require("../config/config"),ciProject_1=require("../project/ciProject"),tools_1=require("../utils/tools"),locales_1=tslib_1.__importDefault(require("../utils/locales/locales")),packOptionsHelper_1=tslib_1.__importDefault(require("../utils/packOptionsHelper")),summerCompiler_1=require("./corecompiler/summerCompiler"),pluginconfig_1=require("./corecompiler/summer/pluginconfig"),WeappCompileCache="";class SummerCompilerFactory{constructor(){this.summerCompiler=null,this.project=null,this.createPromise=null,this.releaseCbs=[]}async getSummerCompiler(e,r){return this.shouldCreate(e)?(this.releaseLastCompiler(),this.project=e,this.summerCompiler=null,this.createPromise=this.createSummerCompiler(e,r),this.summerCompiler=await this.createPromise,this.summerCompiler.setLocale(locales_1.default.getLocale())):(this.summerCompiler||(this.summerCompiler=await this.createPromise),this.summerCompiler.updateOptions(this.getSummerOptions(e))),this.summerCompiler}shouldCreate(e){var r,t,i,o,s;if(!this.project)return!0;if(this.project.projectPath!==e.projectPath)return!0;if(!lodash_1.default.isEqual(this.project.packOptions,e.packOptions))return!0;const l=["es6","minified","postcss","uglifyFileName","compileWorklet","enhance","minifyWXML","minifyWXSS","disableUseStrict","swc","useCompilerPlugins","babelSetting","swcSetting","minifyWXMLSetting","condition"],m=null!==(t=null===(r=this.project)||void 0===r?void 0:r.setting)&&void 0!==t?t:{},p=null!==(i=e.setting)&&void 0!==i?i:{};for(const e of l){const r=m[e],t=p[e];if(!lodash_1.default.isEqual(r,t))return console.info(`shouldCreate return true, project.setting.${e}, before: ${JSON.stringify(r)}, after: ${JSON.stringify(t)}`),!0}return(null===(o=this.project)||void 0===o?void 0:o.miniprogramRoot)!==e.miniprogramRoot||(null===(s=this.project)||void 0===s?void 0:s.pluginRoot)!==e.pluginRoot}async releaseLastCompiler(){const{releaseCbs:e}=this;if(this.releaseCbs=[],this.createPromise)try{(await this.createPromise).destroy(),e.forEach(e=>{try{e()}catch(e){console.error("[SummerCompilerFactory] releaseLastCompiler release cb execute error: "+e)}})}catch(e){console.error("[SummerCompilerFactory] releaseLastCompiler error: "+e)}}ensureCacheDir(){const e=path_1.default.join("",(0,tools_1.generateMD5)(this.project.projectPath+"|summer"));return(0,tools_1.mkdirSync)(e),e}async createSummerCompiler(e,r){const t=new ciProject_1.CIProject(e);await t.ready();const i=this.ensureCacheDir(),o=this.getSummerOptions(e),s=new summerCompiler_1.SummerCompiler(t,i,o,{showBuildLog:()=>{}},r);return await s.ready(),s}getFileFilter(e){packOptionsHelper_1.default.updateState(e);return r=>{const t=r.startsWith(e.miniprogramRoot)&&packOptionsHelper_1.default.isIgnoredByRules(r.slice(e.miniprogramRoot.length)),i=e.pluginRoot&&r.startsWith(e.pluginRoot)&&packOptionsHelper_1.default.isIgnoredByRules(r.slice(e.pluginRoot.length));return!t&&!i}}getSummerOptions(e){const r=(0,pluginconfig_1.getSummerPluginConfig)(e.setting),t={[config_1.compileTypeConfig.weapp]:"miniProgram",[config_1.compileTypeConfig.plugin]:"miniProgramPlugin",[config_1.compileTypeConfig.game]:"miniGame",[config_1.compileTypeConfig.gamePlugin]:"miniGamePlugin"}[e.compileType];return{appid:e.appid,attr:e.attr,projectArchitecture:e.projectArchitecture,miniprogramRoot:e.miniprogramRoot,pluginRoot:e.pluginRoot,compileType:t,summerPlugins:r,setting:Object.assign({},e.setting)}}}exports.SummerCompilerFactory=SummerCompilerFactory,exports.summerCompilerFactory=new SummerCompilerFactory,exports.getSummerCompiler=exports.summerCompilerFactory.getSummerCompiler.bind(exports.summerCompilerFactory);
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Builder=void 0;const tslib_1=require("tslib"),nodePath=tslib_1.__importStar(require("path")),index_1=require("./precompiler/index"),nativecompiler_1=require("./nativecompiler"),createSummer_1=require("./createSummer"),singletontask_1=require("../utils/singletontask"),code_analyse_1=require("../common/code-analyse"),tools_1=require("../utils/tools");class CodeDataFileHelper{constructor(e){var t;this.project=e,this._listeners=[],this.onFileChange=()=>{this._listeners.forEach(e=>{e()})},null===(t=e.event)||void 0===t||t.on("fileChange",this.onFileChange)}destroy(){var e;null===(e=this.project.event)||void 0===e||e.off("fileChange",this.onFileChange)}get prefix(){return"miniProgram"===this.project.type?this.project.miniprogramRoot:"miniProgramPlugin"===this.project.type?this.project.pluginRoot:""}stat(e){const t=this.project.stat(this.prefix,e),i=!!(null==t?void 0:t.isFile),r=!!(null==t?void 0:t.isDirectory);if(!i&&!r)return;return{isFile:i,isDirectory:r,size:null==t?void 0:t.size,mtime:(null==t?void 0:t.mtimeMs)||0}}mtime(e){const t=this.stat(e);return t?t.mtime:0}exist(e){return this.project.exists(this.prefix,e)}existDir(e){if(this.exist(e)){const t=this.stat(e);return!!(null==t?void 0:t.isDirectory)}return!1}existFile(e){if(this.exist(e)){const t=this.stat(e);return!!(null==t?void 0:t.isFile)}return!1}getFileList(e="",t=""){const i=this.project.getFileList(this.prefix,t);return this.excludeRoot(i,this.prefix)}excludeRoot(e=[],t=""){return t?e.map(e=>nodePath.posix.relative(t,e)):e}async getString(e){return this.project.getFile(this.prefix,e).toString()}async getLocalFileString(e){return this.project.getFile(this.prefix,e).toString("utf-8")}async getJSON(e){const t=await this.getString(e);try{return JSON.parse(t)}catch(e){return null}}async readdir(e){const{files:t,dirs:i}=this.project.getFilesAndDirs();e.endsWith("/")||(e+="/");const r=t.filter(t=>t.startsWith(e));return i.filter(t=>t.startsWith(e)).concat(r).filter(t=>t.slice(e.length).indexOf("/")<0).map(t=>t.slice(e.length))}watchFileChange(e){this._listeners.push(e)}}class Builder{constructor(e,t){this._getSummerCompiler=async()=>{if(!this._summerCompiler){const{summerCompilerClass:e,projectInfo:t,cachePath:i="",devtoolMessagehub:r}=this._options,s=await this.getPreCompileProject(),o=await this.getAnalyzer();e?(this._summerCompiler=new e(s,i,t,r,o,this._options.filterFactory),await this._summerCompiler.ready()):this._summerCompiler=await(0,createSummer_1.getSummerCompiler)(s,o)}return this._summerCompiler},this.originProject=e,this._options=t}async getCompiler(){return this.getSummerCompiler()}async getAnalyzer(){if(this._analyzer)return this._analyzer;const e=await this.getPreCompileProject();return this._analyzer=new code_analyse_1.Analyzer({root:nodePath.join(e.projectPath,e.miniprogramRoot),type:"miniprogram",fileHelper:new CodeDataFileHelper(e),compilerPlugins:(0,tools_1.getCompilerPlugins)(e)}),this._analyzer}async getPreCompileProject(){if(!this._precompileProject){const{targetPlatform:e,targetPlatformDefines:t}=this._options,i=await this.getPreCompiler();this._precompileProject=await i.getPreCompileProject({targetPlatform:e,targetPlatformDefines:t,runEnv:"main process"}),await this._precompileProject.ready()}return this._precompileProject}async getPreCompiler(){if(!this._preCompiler){const{devtoolMessagehub:e}=this._options;this._preCompiler=new index_1.PreCompiler(this.originProject,e)}return this._preCompiler}async getSummerCompiler(){var e;return this._getSummerCompilerTask||(this._getSummerCompilerTask=new singletontask_1.SingletonTask(this._getSummerCompiler)),null===(e=this._getSummerCompilerTask)||void 0===e?void 0:e.getResult(!0)}async ready(){return this._checkReadyTask||(this._checkReadyTask=new singletontask_1.SingletonTask(this.init.bind(this,this._options))),await this._checkReadyTask.getResult()}async init(){}async getNativeCompiler(){return this._nativeCompiler||await this.initNativeCompiler(this._options),this._nativeCompiler}async initNativeCompiler(e){if("multiPlatform"!==this.originProject.projectArchitecture)return;const{miniappDirPath:t,devtoolsVersion:i,devtoolMessagehub:r}=e;this._nativeCompiler=new nativecompiler_1.NativeCompiler({project:this._precompileProject,devtoolMessagehub:r,devtoolsVersion:i,miniappDirPath:t}),await this._nativeCompiler.ready()}getPreCompileOptions(){var e,t;return{targetPlatform:null===(e=this._precompileProject)||void 0===e?void 0:e.targetPlatform,targetPlatformDefines:null===(t=this._precompileProject)||void 0===t?void 0:t.targetPlatformDefines}}async changePreCompileOptions(e){var t;await this.getPreCompileProject(),(null===(t=this._precompileProject)||void 0===t?void 0:t.targetPlatform)!==e.targetPlatform&&(this._precompileProject.updateConditionCompileOptions(e),await new Promise(e=>setTimeout(e,500)))}async setLocale(e){(await this.getSummerCompiler()).setLocale(e)}destroy(){var e,t,i,r,s;(null===(e=this._summerCompiler)||void 0===e?void 0:e.isSummer)&&this._summerCompiler.destroy(),null===(t=this._analyzer)||void 0===t||t.destroy(),this._analyzer=void 0,null===(i=this._nativeCompiler)||void 0===i||i.destroy(),null===(s=null===(r=this.originProject)||void 0===r?void 0:r.destroy)||void 0===s||s.call(r)}}exports.Builder=Builder;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Builder=void 0;const tslib_1=require("tslib"),nodePath=tslib_1.__importStar(require("path")),index_1=require("./precompiler/index"),nativecompiler_1=require("./nativecompiler"),createSummer_1=require("./createSummer"),singletontask_1=require("../utils/singletontask"),code_analyse_1=require("../common/code-analyse"),tools_1=require("../utils/tools");class CodeDataFileHelper{constructor(e){var t;this.project=e,this._listeners=[],this.onFileChange=()=>{this._listeners.forEach(e=>{e()})},null===(t=e.event)||void 0===t||t.on("fileChange",this.onFileChange)}destroy(){var e;null===(e=this.project.event)||void 0===e||e.off("fileChange",this.onFileChange)}get prefix(){return"miniProgram"===this.project.type?this.project.miniprogramRoot:"miniProgramPlugin"===this.project.type?this.project.pluginRoot:""}stat(e){const t=this.project.stat(this.prefix,e),i=!!(null==t?void 0:t.isFile),r=!!(null==t?void 0:t.isDirectory);if(!i&&!r)return;return{isFile:i,isDirectory:r,size:null==t?void 0:t.size,mtime:(null==t?void 0:t.mtimeMs)||0}}mtime(e){const t=this.stat(e);return t?t.mtime:0}exist(e){return this.project.exists(this.prefix,e)}existDir(e){if(this.exist(e)){const t=this.stat(e);return!!(null==t?void 0:t.isDirectory)}return!1}existFile(e){if(this.exist(e)){const t=this.stat(e);return!!(null==t?void 0:t.isFile)}return!1}getFileList(e="",t=""){const i=this.project.getFileList(this.prefix,t);return this.excludeRoot(i,this.prefix)}excludeRoot(e=[],t=""){return t?e.map(e=>nodePath.posix.relative(t,e)):e}async getString(e){return this.project.getFile(this.prefix,e).toString()}async getLocalFileString(e){return this.project.getFile(this.prefix,e).toString("utf-8")}async getJSON(e){const t=await this.getString(e);try{return JSON.parse(t)}catch(e){return null}}async readdir(e){const{files:t,dirs:i}=this.project.getFilesAndDirs();e.endsWith("/")||(e+="/");const r=t.filter(t=>t.startsWith(e));return i.filter(t=>t.startsWith(e)).concat(r).filter(t=>t.slice(e.length).indexOf("/")<0).map(t=>t.slice(e.length))}watchFileChange(e){this._listeners.push(e)}}class Builder{constructor(e,t){this._getPreCompileProject=async()=>{const{targetPlatform:e,targetPlatformDefines:t}=this._options,i=await this.getPreCompiler(),r=await i.getPreCompileProject({targetPlatform:e,targetPlatformDefines:t,runEnv:"main process"});return await r.ready(),r},this._getSummerCompiler=async()=>{if(!this._summerCompiler){const{summerCompilerClass:e,projectInfo:t,cachePath:i="",devtoolMessagehub:r}=this._options,s=await this.getPreCompileProject(),o=await this.getAnalyzer();e?(this._summerCompiler=new e(s,i,t,r,o,this._options.filterFactory),await this._summerCompiler.ready()):this._summerCompiler=await(0,createSummer_1.getSummerCompiler)(s,o)}return this._summerCompiler},this.originProject=e,this._options=t}async getCompiler(){return this.getSummerCompiler()}async getAnalyzer(){if(this._analyzer)return this._analyzer;const e=await this.getPreCompileProject();return this._analyzer=new code_analyse_1.Analyzer({root:nodePath.join(e.projectPath,e.miniprogramRoot),type:"miniprogram",fileHelper:new CodeDataFileHelper(e),compilerPlugins:(0,tools_1.getCompilerPlugins)(e)}),this._analyzer}async getPreCompileProject(){return this._precompileProject||(this._getPrecompileProjectTask||(this._getPrecompileProjectTask=new singletontask_1.SingletonTask(this._getPreCompileProject)),this._precompileProject=await this._getPrecompileProjectTask.getResult(!0)),this._precompileProject}async getPreCompiler(){if(!this._preCompiler){const{devtoolMessagehub:e,consoleDisplay:t}=this._options;this._preCompiler=new index_1.PreCompiler(this.originProject,e,t)}return this._preCompiler}async getSummerCompiler(){var e;return this._getSummerCompilerTask||(this._getSummerCompilerTask=new singletontask_1.SingletonTask(this._getSummerCompiler)),null===(e=this._getSummerCompilerTask)||void 0===e?void 0:e.getResult(!0)}async ready(){return this._checkReadyTask||(this._checkReadyTask=new singletontask_1.SingletonTask(this.init.bind(this,this._options))),await this._checkReadyTask.getResult()}async init(){}async getNativeCompiler(){return this._nativeCompiler||await this.initNativeCompiler(this._options),this._nativeCompiler}async initNativeCompiler(e){if("multiPlatform"!==this.originProject.projectArchitecture)return;const{miniappDirPath:t,devtoolsVersion:i,devtoolMessagehub:r}=e,s=await this.getPreCompileProject();this._nativeCompiler=new nativecompiler_1.NativeCompiler({project:s,devtoolMessagehub:r,devtoolsVersion:i,miniappDirPath:t}),await this._nativeCompiler.ready()}getPreCompileOptions(){var e,t;return{targetPlatform:null===(e=this._precompileProject)||void 0===e?void 0:e.targetPlatform,targetPlatformDefines:null===(t=this._precompileProject)||void 0===t?void 0:t.targetPlatformDefines}}async changePreCompileOptions(e){const t=await this.getPreCompileProject();(null==t?void 0:t.targetPlatform)!==e.targetPlatform&&(t.updateConditionCompileOptions(e),await new Promise(e=>setTimeout(e,500)))}async setLocale(e){(await this.getSummerCompiler()).setLocale(e)}destroy(){var e,t,i,r,s;(null===(e=this._summerCompiler)||void 0===e?void 0:e.isSummer)&&this._summerCompiler.destroy(),null===(t=this._analyzer)||void 0===t||t.destroy(),this._analyzer=void 0,null===(i=this._nativeCompiler)||void 0===i||i.destroy(),null===(s=null===(r=this.originProject)||void 0===r?void 0:r.destroy)||void 0===s||s.call(r)}}exports.Builder=Builder;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.NativeCompiler=void 0;const tslib_1=require("tslib"),path_1=tslib_1.__importDefault(require("path")),define_1=require("../../config/define"),processManager_1=require("../../utils/subprocess/processManager"),messageHub_1=require("../../utils/messageHub"),singletontask_1=require("../../utils/singletontask");class NativeCompiler{constructor(s){this.initedPromise=null,this.onProgressUpdate=(s,e,i)=>{const t="doing"===e?"doing":"done"===e?"success":"error";this.messageHub.showBuildLog(""+s,t,i)},this.messageHub=new messageHub_1.MessageHub(s.devtoolMessagehub),this.project=s.project,this.miniappDirPath=s.miniappDirPath,this.devtoolsVersion=s.devtoolsVersion}async ready(){return this._checkReadyTask||(this._checkReadyTask=new singletontask_1.SingletonTask(this.init.bind(this))),await this._checkReadyTask.getResult()}async init(){return this.initedPromise||(this.initedPromise=(async()=>{await this.createSubProcessManager()})()),this.initedPromise}async createSubProcessManager(){const s=path_1.default.posix.join(__dirname,"./nativeEntryProcess.js");this.subProcessManager=new processManager_1.SubProcessProxy(this.project,s,{miniappDirPath:this.miniappDirPath,devtoolsVersion:this.devtoolsVersion},{},8892)}async runAndroid(s){const e=define_1.PLATFORM["mini-android"];return await this.subProcessManager.runTask("runNative",{targetPlatform:e,opts:s,fullEnv:global.fullEnv},this.onProgressUpdate)}async runIOS(s){const e=define_1.PLATFORM["mini-ios"];return await this.subProcessManager.runTask("runNative",{targetPlatform:e,opts:s,fullEnv:global.fullEnv},this.onProgressUpdate)}async buildAndroidAPK(s){const e=define_1.PLATFORM["mini-android"];return await this.subProcessManager.runTask("buildNative",{targetPlatform:e,opts:s,fullEnv:global.fullEnv},this.onProgressUpdate)}async buildIOSIPA(s){const e=define_1.PLATFORM["mini-ios"];return await this.subProcessManager.runTask("buildNative",{targetPlatform:e,opts:s,fullEnv:global.fullEnv},this.onProgressUpdate)}async codesignIpa(s){const e=define_1.PLATFORM["mini-ios"];return await this.subProcessManager.runTask("codesignIOSApp",{targetPlatform:e,opts:s,fullEnv:global.fullEnv},this.onProgressUpdate)}async buildAndroidPlugin(s){const e=define_1.PLATFORM["mini-android"];return await this.subProcessManager.runTask("buildNativePlugin",{targetPlatform:e,opts:s,fullEnv:global.fullEnv},this.onProgressUpdate)}async buildIOSPlugin(s){const e=define_1.PLATFORM["mini-ios"];return await this.subProcessManager.runTask("buildNativePlugin",{targetPlatform:e,opts:s,fullEnv:global.fullEnv},this.onProgressUpdate)}async packIOSCloudBuildMaterial(s){const e=define_1.PLATFORM["mini-ios"];return await this.subProcessManager.runTask("packIOSCloudBuildMaterial",{targetPlatform:e,opts:s,fullEnv:global.fullEnv},this.onProgressUpdate)}destroy(){this.subProcessManager.destroy()}}exports.NativeCompiler=NativeCompiler;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.NativeCompiler=void 0;const tslib_1=require("tslib"),path_1=tslib_1.__importDefault(require("path")),define_1=require("../../config/define"),processManager_1=require("../../utils/subprocess/processManager"),messageHub_1=require("../../utils/messageHub"),singletontask_1=require("../../utils/singletontask");class NativeCompiler{constructor(s){this.initedPromise=null,this.onProgressUpdate=(s,e,i)=>{this.messageHub.showBuildLog(""+s,e,i)},this.messageHub=new messageHub_1.MessageHub(s.devtoolMessagehub),this.project=s.project,this.miniappDirPath=s.miniappDirPath,this.devtoolsVersion=s.devtoolsVersion}async ready(){return this._checkReadyTask||(this._checkReadyTask=new singletontask_1.SingletonTask(this.init.bind(this))),await this._checkReadyTask.getResult()}async init(){return this.initedPromise||(this.initedPromise=(async()=>{await this.createSubProcessManager()})()),this.initedPromise}async createSubProcessManager(){const s=path_1.default.posix.join(__dirname,"./nativeEntryProcess.js");this.subProcessManager=new processManager_1.SubProcessProxy(this.project,s,{miniappDirPath:this.miniappDirPath,devtoolsVersion:this.devtoolsVersion},{},8892)}async runAndroid(s){const e=define_1.PLATFORM["mini-android"];return await this.subProcessManager.runTask("runNative",{targetPlatform:e,opts:s,fullEnv:global.fullEnv},this.onProgressUpdate)}async runIOS(s){const e=define_1.PLATFORM["mini-ios"];return await this.subProcessManager.runTask("runNative",{targetPlatform:e,opts:s,fullEnv:global.fullEnv},this.onProgressUpdate)}async buildAndroidAPK(s){const e=define_1.PLATFORM["mini-android"];return await this.subProcessManager.runTask("buildNative",{targetPlatform:e,opts:s,fullEnv:global.fullEnv},this.onProgressUpdate)}async buildIOSIPA(s){const e=define_1.PLATFORM["mini-ios"];return await this.subProcessManager.runTask("buildNative",{targetPlatform:e,opts:s,fullEnv:global.fullEnv},this.onProgressUpdate)}async codesignIpa(s){const e=define_1.PLATFORM["mini-ios"];return await this.subProcessManager.runTask("codesignIOSApp",{targetPlatform:e,opts:s,fullEnv:global.fullEnv},this.onProgressUpdate)}async buildAndroidPlugin(s){const e=define_1.PLATFORM["mini-android"];return await this.subProcessManager.runTask("buildNativePlugin",{targetPlatform:e,opts:s,fullEnv:global.fullEnv},this.onProgressUpdate)}async buildIOSPlugin(s){const e=define_1.PLATFORM["mini-ios"];return await this.subProcessManager.runTask("buildNativePlugin",{targetPlatform:e,opts:s,fullEnv:global.fullEnv},this.onProgressUpdate)}async packIOSCloudBuildMaterial(s){const e=define_1.PLATFORM["mini-ios"];return await this.subProcessManager.runTask("packIOSCloudBuildMaterial",{targetPlatform:e,opts:s,fullEnv:global.fullEnv},this.onProgressUpdate)}async initUSBConnectionProcess(){const s=define_1.PLATFORM["mini-ios"];return await this.subProcessManager.runTask("initUSBConnectionProcess",{targetPlatform:s,fullEnv:global.fullEnv},this.onProgressUpdate)}destroy(){this.subProcessManager.destroy()}}exports.NativeCompiler=NativeCompiler;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.remoteBuildProjectMaterialAbsoluteCacheDir=void 0;const tslib_1=require("tslib"),child_process=tslib_1.__importStar(require("child_process")),path_1=tslib_1.__importDefault(require("path")),fs_extra_1=tslib_1.__importDefault(require("fs-extra")),glob_1=tslib_1.__importDefault(require("glob")),env_1=require("../../../utils/env"),miniapp_builder_1=require("../../../utils/miniapp-builder"),codesign_1=require("../../../utils/codesign"),miniappJson_1=require("../../../utils/miniappJson"),lodash_1=require("lodash"),tools_1=require("../../../utils/tools"),uuidv4=require("uuid/v4"),sizeOf=require("image-size"),plist=require("simple-plist"),errorIOSSdkVersions=["1.0.19"],APPEX_PROFILES_MAPS_FILE="__appexProfilesCacheDir__/profilesMap.json",APPEX_PROFILES_MAPS_FOR_SHELL_FILE="__appexProfilesCacheDir__/profilesMapForShell.txt",defaultIconDirPath=path_1.default.join(__dirname,"../../../static/images/"),getDepReg=e=>new RegExp(`s.subspec '${e}'.*\n(?:.*\n)*?(?:.*sp.vendored_frameworks = \\[\n)((?:.*'.*?'.*\n)*?)(?:.*\\]\n)`,"m"),allowTheme=["Light","LightSpecial","Dark","DarkSpecial","Default"];exports.remoteBuildProjectMaterialAbsoluteCacheDir="__absoluteFile";const iconInfoMap={appStore1024:{size:[1024,1024],scale:1,idiom:"ios-marketing",required:!0},appStore1024Other:{size:[1024,1024],scale:1,idiom:"ios-marketing-other"},mainIcon120:{size:[60,60],scale:2,idiom:"iphone",required:!0},mainIcon180:{size:[60,60],scale:3,idiom:"iphone"},spotlightIcon80:{size:[40,40],scale:2,idiom:"iphone"},spotlightIcon120:{size:[40,40],scale:3,idiom:"iphone"},settingsIcon58:{size:[29,29],scale:2,idiom:"iphone"},settingsIcon87:{size:[29,29],scale:3,idiom:"iphone"},notificationIcon40:{size:[20,20],scale:2,idiom:"iphone"},notificationIcon60:{size:[20,20],scale:3,idiom:"iphone"},ipadMainIcon152:{size:[76,76],scale:2,idiom:"ipad"},ipadMainIcon167:{size:[83.5,83.5],scale:2,idiom:"ipad"},ipadSpotlightIcon40:{size:[40,40],scale:1,idiom:"ipad"},ipadSpotlightIcon80:{size:[40,40],scale:2,idiom:"ipad"},ipadSettingsIcon29:{size:[29,29],scale:1,idiom:"ipad"},ipadSpotlightIcon58:{size:[29,29],scale:2,idiom:"ipad"},ipadNotificationIcon20:{size:[20,20],scale:1,idiom:"ipad"},ipadNotificationIcon40:{size:[20,20],scale:2,idiom:"ipad"}};class buildCloudManager{generateTempDemoIpaPath(e){const i=path_1.default.join(e,"../.."),t=path_1.default.basename(i),n=path_1.default.dirname(i),a=path_1.default.join(n,t+"-operateDir");fs_extra_1.default.existsSync(a)&&fs_extra_1.default.removeSync(a),fs_extra_1.default.ensureDirSync(a);const s=path_1.default.join(a,"Payload/demo.app");return fs_extra_1.default.copySync(e,s),s}generateInfoPlistCFBundleURLTypesItem(e){const i={};return e.CFBundleURLName&&(i.CFBundleURLName=e.CFBundleURLName),e.CFBundleURLSchemes&&(i.CFBundleURLSchemes=[e.CFBundleURLSchemes]),e.CFBundleTypeRole&&(i.CFBundleTypeRole=e.CFBundleTypeRole),i}updatePrivacyBackgroundImage(e,i,t,n,a){t.message("doing","updatePrivacyBackgroundImage "+n);if(fs_extra_1.default.readdirSync(i).forEach(e=>{"privacy_"+n===path_1.default.basename(e,path_1.default.extname(e))&&fs_extra_1.default.removeSync(path_1.default.join(i,e))}),!a)return;path_1.default.isAbsolute(a)||(a=path_1.default.join(e,a)),a=this.getMaterialFilePath(e,a);const s=path_1.default.extname(a),o=path_1.default.join(i,`privacy_${n}${s}`);try{fs_extra_1.default.copyFileSync(a,o)}catch(e){throw t.message("fail",`copy privacy image failed: ${n}, ${a} to ${o}`),e}}async updateIOSInfoPlistInfo(e,i,t,n,a,s){var o,l,r,d,p,u,c,f,_,h;a.progress("update app base info...");const{mobileapp_info:g={}}=i,m=g.mobileapp_id,y=path_1.default.join(t,"Info.plist"),I={},S=(e,i)=>{var t,n;if((null==i?void 0:i.startsWith("%"))&&(null==i?void 0:i.endsWith("%"))){const o=i.slice(1,-1);I[e]=o;const l=(null===(n=null===(t=null==s?void 0:s.base)||void 0===t?void 0:t.ios)||void 0===n?void 0:n[o])||"";return l||a.message("fail",`未在国际化配置 base.json 中找到字段 ${o},请检查`),l}return i};S("UISplashScreenImageName",null===(o=null==n?void 0:n.splashscreen)||void 0===o?void 0:o.customImage),S("UILaunchStoryboardName",null===(l=null==n?void 0:n.splashscreen)||void 0===l?void 0:l.customImage);const x=plist.readFileSync(y);if(x.CFBundleName=S("CFBundleName",n.name),x.CFBundleDisplayName=S("CFBundleDisplayName",n.name),x.CFBundleShortVersionString=n.version,"number"==typeof n.versionCode?x.CFBundleVersion=parseInt(n.versionCode.toString(),10).toString():x.CFBundleVersion=(parseInt(x.CFBundleVersion,10)+1).toString(),x.CFBundleIdentifier=this.getBundleIdentifier(g),Array.isArray(x.CFBundleURLTypes)||(x.CFBundleURLTypes=[]),(null===(d=null===(r=x.CFBundleURLTypes)||void 0===r?void 0:r[0])||void 0===d?void 0:d.CFBundleURLSchemes)&&(x.CFBundleURLTypes[0].CFBundleURLSchemes=[m]),x.CFBundleURLTypes[0]&&(x.CFBundleURLTypes=[x.CFBundleURLTypes[0]]),Object.keys(miniappJson_1.iosPrivacyDescObj).forEach(e=>{var i,t;(null===(i=null==n?void 0:n.privateDescriptions)||void 0===i?void 0:i[e])?x[e]=S(e,null===(t=n.privateDescriptions)||void 0===t?void 0:t[e]):delete x[e]}),!0===(null===(p=null==n?void 0:n.infoPlist)||void 0===p?void 0:p.DisableAppUsesNonExemptEncryption)?x.ITSAppUsesNonExemptEncryption=!1:delete x.ITSAppUsesNonExemptEncryption,x.UIBackgroundModes=[],!0===(null===(u=null==n?void 0:n.infoPlist)||void 0===u?void 0:u.AudioInBackgroundMode)&&x.UIBackgroundModes.push("audio"),!0===(null===(c=null==n?void 0:n.infoPlist)||void 0===c?void 0:c.LocationInBackgroundMode)&&x.UIBackgroundModes.push("location"),!0===(null===(f=null==n?void 0:n.infoPlist)||void 0===f?void 0:f.requiresFullScreen)?x.UIRequiresFullScreen=!0:delete x.UIRequiresFullScreen,"object"==typeof(null===(_=null==n?void 0:n.infoPlist)||void 0===_?void 0:_.CFBundleURLTypes)){const e=this.generateInfoPlistCFBundleURLTypesItem(n.infoPlist.CFBundleURLTypes);x.CFBundleURLTypes.push(e);const{additionalCFBundleURLTypes:i}=n.infoPlist.CFBundleURLTypes;Array.isArray(i)&&i.forEach(e=>{if("object"==typeof e){const i=this.generateInfoPlistCFBundleURLTypesItem(e);x.CFBundleURLTypes.push(i)}})}if(!0===n.enableIpad&&((0,miniappJson_1.iOSAppJsonIsUsingIPadResizable)(e)?(x["UISupportedInterfaceOrientations~ipad"]=["UIInterfaceOrientationPortrait","UIInterfaceOrientationPortraitUpsideDown","UIInterfaceOrientationLandscapeLeft","UIInterfaceOrientationLandscapeRight"],a.progress("ipad is support Landscape")):(x["UISupportedInterfaceOrientations~ipad"]=["UIInterfaceOrientationPortrait","UIInterfaceOrientationPortraitUpsideDown"],a.progress("ipad is not support Landscape"))),null===(h=n.infoPlist)||void 0===h?void 0:h.LSApplicationQueriesSchemes){const e=n.infoPlist.LSApplicationQueriesSchemes.split(",");e.length&&x.LSApplicationQueriesSchemes.push(...e.filter(e=>e))}return plist.writeFileSync(y,x),await this.writeI18NInfoFile(t,s,I),x.CFBundleVersion}getBundleIdentifier(e){return e.ios_flag&&e.bundle_id||e.debug_ios_bundle_id}useGDT(e){return(0,miniappJson_1.iOSMiniAppJsonIsUsingGDT)(e)}async updateIOSAppConfigPlistInfo(e,i,t,n,a,s,o,l="Dark",r){var d,p,u,c;o.progress("update app module info...");const{module_info:f={},cpa_info:_={},cpa_package_info:h={enable_remove_watermark:!1}}=i;if(!_.sdk_key||!_.sdk_key_secret)throw new Error("sdkKey and sdkSecret not found");const g=path_1.default.join(t,"MiniApp.bundle"),m=path_1.default.join(g,"AppConfig.plist"),y=plist.readFileSync(m);h.enable_remove_watermark?y.enableRemoveWatermark=!0:y.splashscreenTheme=l,y.miniModuleId=f.module_id,y.sdkKey=_.sdk_key,y.sdkSecret=_.sdk_key_secret;const{privacy:I={}}=n;y.privacy||(y.privacy={}),y.privacy.enable=!!I.enable;const S=path_1.default.posix.join(g,"configs/privacy.json"),{contentViewImage:x,cancelButtonImage:v,confirmButtonImage:b,template:P}=I;if(I.enable){let i=P||"";if(fs_extra_1.default.ensureDirSync(path_1.default.posix.join(g,"configs")),i.startsWith("%")&&i.endsWith("%")){const t=P.slice(1,-1);i=(null===(p=null===(d=null==r?void 0:r.base)||void 0===d?void 0:d.ios)||void 0===p?void 0:p[t])||"",i||o.message("fail",`未在国际化配置 base.json 中找到字段 ${t},请检查`),Object.keys(r).forEach(i=>{var n,a;if("base"===i)return;let s=null===(a=null===(n=r[i])||void 0===n?void 0:n.ios)||void 0===a?void 0:a[t];if(s){s=this.getMaterialFilePath(e,s);const t=`configs/privacy-${i}.json`,n=path_1.default.posix.join(g,t);fs_extra_1.default.existsSync(s)?fs_extra_1.default.copyFileSync(s,n):o.message("fail",`未找到隐私协议在国际化配置 ${i}.json 中配置的文件 ${s},请检查`)}})}i?(i=this.getMaterialFilePath(e,i),fs_extra_1.default.existsSync(i)?(fs_extra_1.default.copyFileSync(i,S),y.privacy.template="configs/privacy.json"):(o.message("fail",`未找到隐私协议中配置的文件 ${i},请检查`),y.privacy.template="configs/defaultPrivacy.json")):y.privacy.template="configs/defaultPrivacy.json",!0===I.enableNativePlugin&&"string"==typeof I.nativePluginId&&I.nativePluginId.length>2&&(y.privacy.plugin={pluginId:I.nativePluginId,enable:!0})}else y.privacy.template="",fs_extra_1.default.removeSync(S);this.updatePrivacyBackgroundImage(e,t,o,"contentViewImage",x),this.updatePrivacyBackgroundImage(e,t,o,"confirmButtonImage",b),this.updatePrivacyBackgroundImage(e,t,o,"cancelButtonImage",v);const{appMenuEnable:F=!0}=n;y.appMenuEnable=F;const{enableVConsole:j="undefined"}=n;y.enableVConsole=j;const{tpush:B}=n;let C=!1;if("object"==typeof B){const e=path_1.default.posix.join(t,"PlugIns/TPNSService.appex"),i=path_1.default.posix.join(e,"AppConfig.plist");if(this.useTpush(n)){y.TPNSAccessID=B.accessID,y.TPNSAccessKey=B.accessKey,B.clusterDomainName?y.clusterDomainName=B.clusterDomainName:delete y.clusterDomainName;const t=s?"x86_64":"arm64",n=path_1.default.join(a,`appex/${t}/TPNSService.appex`);if(!fs_extra_1.default.existsSync(n))throw new Error("can not found extendsdk: "+n);try{fs_extra_1.default.copySync(n,e),plist.writeFileSync(i,y),C=!0}catch(e){throw new Error("copy TPNSService.appex to app failed: "+e)}}}if(!C)try{const e=path_1.default.posix.join(t,"PlugIns");fs_extra_1.default.existsSync(e)?(fs_extra_1.default.removeSync(e),o.progress("removed PlugIns folder...")):o.progress("no PlugIns folder...")}catch(e){throw new Error("remove TPNSService.appex from app failed: "+e)}if(null===(u=n.useExtendedSdk)||void 0===u?void 0:u.WeAppLBS){if(!n.qmapAPIKey)throw new Error("You need to provide the Tencent Location Service API Key when using LBS SDK.");y.qmapAPIKey=n.qmapAPIKey}const{gdt:w}=n,L=this.useGDT(n);if(y.GDTAd=L?{appid:w.appid,enable:!0,SplashAd:{placementId:w.splashAd_placementId,fetchDelay:w.splashAd_fetchDelay||3,defaultEnable:null===(c=w.splashAd_defaultEnable)||void 0===c||c}}:{appid:"",enable:!1,SplashAd:{placementId:"",fetchDelay:3}},n["mini-plugin"]&&Array.isArray(n["mini-plugin"].ios)){const e=n["mini-plugin"].ios.filter(e=>!!(e.open&&e.pluginId&&e.loadWhenStart)).map(e=>e.pluginId);y.plugins={loadWhenStart:e}}const{enableDebugLog:$=!1}=n;y.enableDebugLog=$;const{debugLogSizeLimit:D=10}=n;isNaN(Number(D))?o.message("fail",`ios debugLogSizeLimit ${D} is NaN`):y.debugLogSizeLimit=Number(D);const{enableOpenUrlNavigate:E=!1}=n;y.enableOpenUrlNavigate=E,plist.writeFileSync(m,y)}async updateIOSAppexInfoPlistInfo(e,i,t,n,a){if(this.useTpush(t)){a.progress("update appex for notification base info...");const{mobileapp_info:s={}}=e,o=path_1.default.join(i,"PlugIns/TPNSService.appex"),l=path_1.default.join(o,"Info.plist"),r=plist.readFileSync(l);r.CFBundleShortVersionString=t.version,a.progress("update appex for CFBundleVersion: "+n),r.CFBundleVersion=n;const d=s.ios_flag&&s.bundle_id||s.debug_ios_bundle_id;r.CFBundleIdentifier=t.tpush.serviceBundleId||d+".service",a.progress("update appex bundle identifier for infoPlist : "+r.CFBundleIdentifier),plist.writeFileSync(l,r)}else a.progress("not using tpush...")}updateBundleIcons(e,i,t,n,a){const s=[],o=[],l=[];for(const r in t){if(!t[r])continue;const d=this.getMaterialFilePath(e,t[r]);if(!d)return void a.message("fail","getMatrialFailed: "+t[r]);const p=iconInfoMap[r];try{const e=sizeOf(d),i=p.size[0]*p.scale,n=p.size[1]*p.scale;if(e.width!==i||e.height!==n){a.progress(`check ${r} size failed, require [${i}, ${n}] but [${e.width}, ${e.height}] ingore ${t[r]} `);continue}}catch(e){a.progress(`get ${r} info failed, ingore ${t[r]}(e: ${e.message})`);continue}const u=path_1.default.extname(d),c=1===p.scale?"":`@${p.scale}x`,f=`${p.size[0]}x${p.size[1]}`,_=r.startsWith("ipad"),h="appStore1024"===r||"appStore1024Other"===r,g="appStore1024Other"===r?n+"Other":n,m=path_1.default.join(i,`${g}${f}${c}${_?"~ipad":""}${u}`),y={from:d,to:m,filename:path_1.default.basename(m),size:f,scale:p.scale+"x",idiom:p.idiom,key:r};s.push(y),h||(_?l.includes(`${g}${f}`)||l.push(`${g}${f}${c}`):o.includes(`${g}${f}`)||o.push(`${g}${f}${c}`))}return{iphoneBundleIconFiles:o,ipadBundleIconFiles:l,addFiles:s}}async updateIOSIcons(e,i,t,n,a,s){s.progress("update app icons...");const{icons:o={}}=n,l=a&&!env_1.isWin&&!!t;s.progress("genAssetCar: "+l);const r=glob_1.default.sync("AppIcon*.+(png|jpg|jpeg|webp)",{nodir:!0,cwd:i}).map(e=>path_1.default.join(i,e)),d="AppIcon-"+uuidv4().slice(0,8),p=this.updateBundleIcons(e,i,o,d,s);if(!p)throw new Error("updateBundleIcons failed");const{iphoneBundleIconFiles:u=[],ipadBundleIconFiles:c=[],addFiles:f=[]}=p,_={};for(const e in iconInfoMap){if(!iconInfoMap[e].required||o[e])continue;const i=iconInfoMap[e].size[0]*iconInfoMap[e].scale,t=iconInfoMap[e].size[1]*iconInfoMap[e].scale;if(_[e]=path_1.default.join(defaultIconDirPath,`donut-icon${i}x${t}.png`),s.progress(`using default app icons when ${e} is not config...`),!fs_extra_1.default.existsSync(_[e]))throw new Error(`required ${e} but not default or set`)}const h=this.updateBundleIcons(e,i,_,d,s);if(!h)throw new Error("updateBundleIcons WithDefaultIcon failed");const{iphoneBundleIconFiles:g,ipadBundleIconFiles:m,addFiles:y}=h;if(u.push(...g),c.push(...m),f.push(...y),!u.length&&!c.length)return;r.forEach(e=>{fs_extra_1.default.existsSync(e)&&fs_extra_1.default.removeSync(e)});const I=path_1.default.join(t,"__assetCarOperateDir/assetsCar/"),S=path_1.default.join(I,`Assets.xcassets/${d}.appiconset/`);l&&(fs_extra_1.default.ensureDirSync(S),fs_extra_1.default.emptyDirSync(S));const x=[];let v=!1;if(f.forEach(e=>{fs_extra_1.default.existsSync(e.to)&&fs_extra_1.default.removeSync(e.to),fs_extra_1.default.copyFileSync(e.from,e.to),l&&(fs_extra_1.default.copySync(e.from,path_1.default.join(S,e.filename)),console.log("看看啊",path_1.default.join(S,e.filename)),"ios-marketing-other"===e.idiom&&(v=!0),x.push({filename:e.filename,size:e.size,scale:e.scale,idiom:e.idiom}))}),l&&fs_extra_1.default.writeJsonSync(path_1.default.join(S,"Contents.json"),{images:x,info:{author:"xcode",version:1}},{spaces:"\t"}),l){const e=path_1.default.join(__dirname,"../../../static/scripts/assetsCar/"),t=path_1.default.join(I,"createAssetsCar");fs_extra_1.default.copySync(e,I);try{await(0,codesign_1.checkXcodeEnv)(s),child_process.execSync(`"${t}" ${d}`,{env:(0,env_1.getProcessEnv)()})}catch(e){s.progress("createAssetsCar failed "+(e.message||""))}const n=path_1.default.join(I,"build/Assets.car"),a=path_1.default.join(i,"Assets.car");fs_extra_1.default.copyFileSync(n,a)}else{const e=path_1.default.join(i,"Assets.car");fs_extra_1.default.removeSync(e)}const b=path_1.default.join(i,"Info.plist"),P=plist.readFileSync(b);if(!P.CFBundleIcons){const e={CFBundlePrimaryIcon:{}};P.CFBundleIcons=e}v&&(P.CFBundleIcons.CFBundleAlternateIcons={OtherAppStoreIcon:{CFBundleIconFiles:[d+"Other"],CFBundleIconName:"OtherAppStoreIcon"}}),P.CFBundleIcons.CFBundlePrimaryIcon.CFBundleIconName=d,P.CFBundleIcons.CFBundlePrimaryIcon.CFBundleIconFiles=u,P["CFBundleIcons~ipad"]||(P["CFBundleIcons~ipad"]={CFBundlePrimaryIcon:{}}),P["CFBundleIcons~ipad"].CFBundlePrimaryIcon.CFBundleIconName=d,P["CFBundleIcons~ipad"].CFBundlePrimaryIcon.CFBundleIconFiles=c,P.NSAppTransportSecurity={NSAllowsArbitraryLoads:!0},plist.writeFileSync(b,P)}replaceLaunchScreenImage(e,i,t,n,a,s){const o=path_1.default.join(e,"01J-lp-oVM-view-Ze5-6b-2t3.nib");let l=fs_extra_1.default.readFileSync(o).toString("hex");if(!i.endsWith(".png"))return void n.message("fail","IOS 启动页图片配置格式错误,必须为 PNG 格式, 错误配置:"+i);const r=this.getMaterialFilePath(a,i),d=t+".png",p="LaunchScreen-"+uuidv4().slice(0,12),u=p+".png",c=path_1.default.join(s,u);fs_extra_1.default.copyFileSync(r,c);const f=Buffer.from(d,"utf-8").toString("hex"),_=Buffer.from(u,"utf-8").toString("hex");return-1!==l.indexOf(f)?(l=l.replace(f,_),console.log("replace storyboard customImage success")):console.log("replace storyboard customImage fail"),fs_extra_1.default.writeFileSync(o,Buffer.from(l,"hex")),p}async updateSplashScreen(e,i,t,n,a="Dark",s){var o,l,r;let d;n.progress("update splashscreen image..."),allowTheme.includes(a)&&(d=path_1.default.join(i,`/Base.lproj/LaunchScreen${a}.storyboardc`)),d&&fs_extra_1.default.existsSync(d)&&fs_extra_1.default.copySync(d,path_1.default.join(i,"/Base.lproj/LaunchScreen.storyboardc")),allowTheme.forEach(e=>{const t=path_1.default.join(i,`/Base.lproj/LaunchScreen${e}.storyboardc`);fs_extra_1.default.existsSync(t)&&fs_extra_1.default.removeSync(t)});let p=null===(o=null==t?void 0:t.splashscreen)||void 0===o?void 0:o.customImage;if(!p)return;const u=path_1.default.join(i,"Info.plist"),c=plist.readFileSync(u),f=c.UISplashScreenImageName;if(glob_1.default.sync("LaunchScreen-*.+(png|jpg|jpeg|webp)",{nodir:!0,cwd:i}).forEach(e=>{const t=path_1.default.join(i,e);fs_extra_1.default.removeSync(t)}),p.startsWith("%")&&(null==p?void 0:p.endsWith("%"))){const t=p.slice(1,-1),a=(null===(r=null===(l=null==s?void 0:s.base)||void 0===l?void 0:l.ios)||void 0===r?void 0:r[t])||"";if(!a)return void n.message("fail",`未在国际化配置 base.json 中找到字段 ${t},请检查,启动页国际化配置失败`);p=a,Object.keys(s).forEach(a=>{var o,l;if("base"===a)return;const r=null===(l=null===(o=s[a])||void 0===o?void 0:o.ios)||void 0===l?void 0:l[t];if(r){const t=path_1.default.join(i,`/${a}.lproj/LaunchScreen_${a}.storyboardc`);fs_extra_1.default.ensureDirSync(path_1.default.join(t,"..")),fs_extra_1.default.copySync(path_1.default.join(i,"/Base.lproj/LaunchScreen.storyboardc"),t);const s=this.replaceLaunchScreenImage(t,this.getMaterialFilePath(e,r),f,n,e,i);n.progress(`update ${a} splashscreen image...`);const o=fs_extra_1.default.readFileSync(path_1.default.join(i,a+".lproj/InfoPlist.strings"),"utf8");let l="";l=s?o.replace("__UISplashScreenImageName__",`UISplashScreenImageName = "${s}";\n`).replace("__UILaunchStoryboardName__",`UILaunchStoryboardName = "LaunchScreen_${a}";\n`):o.replace("__UISplashScreenImageName__","").replace("__UILaunchStoryboardName__",""),fs_extra_1.default.writeFileSync(path_1.default.join(i,a+".lproj/InfoPlist.strings"),l),n.progress(`update ${a} splashscreen image success`)}})}n.progress("update base splashscreen image...");const _=this.replaceLaunchScreenImage(path_1.default.join(i,"/Base.lproj/LaunchScreen.storyboardc"),this.getMaterialFilePath(e,p),f,n,e,i);n.progress("update base splashscreen image success"),_&&(c.UISplashScreenImageName=_,c.UILaunchStoryboardName="LaunchScreen",plist.writeFileSync(u,c))}genUseExtendedSdk(e){const i=Object.assign({},e.useExtendedSdk||{});for(const t in e)if("object"==typeof e[t])for(const n in e[t])if(n.startsWith("useExtendedLib_WeApp")&&!0===e[t][n]){i[n.slice("useExtendedLib_".length)]=!0}return!i.WeAppLBS||i.WeAppOpenFuns||i.WeAppOpenFuns_HasPay||(i.WeAppOpenFuns=!0),i}async updateExtendedSdk(e,i,t,n,a,s){const o=path_1.default.join(i,"Frameworks");fs_extra_1.default.ensureDirSync(o),s.progress("update extendsdk...");const l=path_1.default.join(t,"WeAppSDK.podspec"),r=fs_extra_1.default.readFileSync(l,"utf-8"),d=this.genUseExtendedSdk(a);s.progress("useExtendedSdks: "+JSON.stringify(d));const{mobileapp_info:p={}}=e,u=this.getBundleIdentifier(p);if(d.WeAppOpenFuns&&d.WeAppOpenFuns_HasPay)throw new Error("OpenFuncs SDK 只可勾选使用一个,请按需勾选使用");const c={};for(const e in d){if(!d[e])continue;const i=getDepReg(e),a=r.match(i);if(!(null==a?void 0:a[1]))throw new Error(`拓展模块 ${e} 不存在或已被移除,请检查 project.miniapp.json -> 对应平台 -> useExtendedSdk 删除配置 ${e},版本配置差异请参考更新日志或 https://dev.weixin.qq.com/docs/framework/dev/sdk/difflog.html`);const s=[];if(a[1].split("\n").forEach(e=>{const i=e.match(/.*'(.*?)',/);if(null==i?void 0:i[1]){const e=i[1].split("/").pop(),a=path_1.default.join(t,"Libs",n,e);if(!fs_extra_1.default.existsSync(a))throw new Error(`拓展模块 ${e} 不存在或已被移除,请检查 project.miniapp.json -> 对应平台 -> useExtendedSdk 删除配置 ${e},版本配置差异请参考更新日志或 https://dev.weixin.qq.com/docs/framework/dev/sdk/difflog.html`);const l=path_1.default.join(o,e);fs_extra_1.default.copySync(a,l),s.push(path_1.default.basename(e));const r=path_1.default.join(l,"info.plist");if(!fs_extra_1.default.existsSync(r))throw new Error("can not found extendsdk info.plist: "+e);this.changeExtendSDKInfoplistBundleId(r,u,e)}}),s.length){c[s.shift()]=s}}const f=path_1.default.join(i,"DyFrameworks.plist");fs_extra_1.default.existsSync(f)&&fs_extra_1.default.removeSync(f),plist.writeFileSync(f,c)}async updatePrivacyInfo(e,i,t){var n;const a=null===(n=null==i?void 0:i.privacy)||void 0===n?void 0:n.privacyInfo;a&&(a.endsWith("PrivacyInfo.xcprivacy")?fs_extra_1.default.existsSync(a)?(fs_extra_1.default.copySync(a,path_1.default.join(e,"/PrivacyInfo.xcprivacy")),t.progress("隐私清单文件替换成功")):t.message("fail","隐私清单文件替换失败,文件不存在,将使用默认文件"):t.message("fail","隐私清单文件替换失败,文件名必须为 PrivacyInfo.xcprivacy,将使用默认文件"))}async updatePlugin(e,i,t,n,a,s,o,l){if(!i.length)return;const r=path_1.default.join(e,"Frameworks"),d=path_1.default.join(e,"PlugIns");fs_extra_1.default.ensureDirSync(r),l.progress("update plugin...");const p=this.prepareAppexProfileConfig(i,n,t,a,s,o,n.version,l);if(!p)throw new Error("依赖的多端插件需要配置对应的profile");const u={};if(n["mini-plugin"]&&Array.isArray(n["mini-plugin"].ios)){n["mini-plugin"].ios.forEach(e=>{e.open&&e.pluginId&&"string"==typeof e.resourcePath&&e.resourcePath.length>0&&(u[e.pluginId]=e.resourcePath)})}i.forEach(i=>{const{pluginId:n}=i,a=i.dir,s=n+".framework",o=path_1.default.join(r,s);if(-1!==a.indexOf("local-miniapp-plugin")){const e=fs_extra_1.default.statSync(a),{mtime:i}=e;l.progress(`${n}.framework 正在使用本地版本,修改时间为 ${i}`)}fs_extra_1.default.existsSync(o)&&fs_extra_1.default.removeSync(o);const c=path_1.default.join(a,s);if(fs_extra_1.default.existsSync(c)){fs_extra_1.default.copySync(c,o),this.copyResourcesToMainBundle(c,e),this.copyUserResourcePathIntoPlugins(n,t,u[n],path_1.default.join(o,"MiniPlugin.bundle"),l);fs_extra_1.default.readdirSync(a).forEach(i=>{if(i.endsWith(".appex")){const s=path_1.default.parse(i).name,o=p[s],r=path_1.default.join(d,i);if(!o||!0!==o.enable)return;l.progress(`${n} 插件使用 appex 中 : ${i}`),fs_extra_1.default.existsSync(r)&&fs_extra_1.default.removeSync(r),fs_extra_1.default.ensureDirSync(r);const c=path_1.default.join(a,i);fs_extra_1.default.copySync(c,r),(null==o?void 0:o.profilePath)&&fs_extra_1.default.copySync(o.profilePath,path_1.default.join(r,"embedded.mobileprovision")),this.copyResourcesToMainBundle(c,e),this.copyUserResourcePathIntoPlugins(n,t,u[n],path_1.default.join(r,"MiniPlugin.bundle"),l)}})}else fs_extra_1.default.copySync(a,o),this.copyResourcesToMainBundle(a,e),this.copyUserResourcePathIntoPlugins(n,t,u[n],path_1.default.join(o,"MiniPlugin.bundle"),l)})}copyUserResourcePathIntoPlugins(e,i,t,n,a){const s=n;if(t){const n=path_1.default.basename(t),o=this.getMaterialFilePath(i,t);if(o){a.progress(`${e}.framework 正在拷贝配置的资源:${t}`);const i=fs_extra_1.default.lstatSync(o);fs_extra_1.default.ensureDirSync(s),i.isDirectory()?fs_extra_1.default.copySync(o,s):i.isFile()&&fs_extra_1.default.copyFileSync(o,path_1.default.join(s,n))}}}copyResourcesToMainBundle(e,i){const t=path_1.default.join(e,"MiniPlugin.bundle"),n=path_1.default.join(t,"PluginConfig.plist");if(fs_extra_1.default.existsSync(n)){const e=plist.readFileSync(n).CopyResourcesToMainBundle;(null==e?void 0:e.length)&&e.forEach(e=>{const n=path_1.default.join(t,e);fs_extra_1.default.existsSync(n)&&fs_extra_1.default.copySync(n,path_1.default.join(i,e))})}}prepareAppexProfileConfig(e,i,t,n,a,s,o,l){if(!n)return void l.message("doing","miniappCacheDirPath is missing");let r=!1;const d={};if(i["mini-plugin"]&&Array.isArray(i["mini-plugin"].ios)){i["mini-plugin"].ios.forEach(e=>{if(e.open&&e.pluginId&&"object"==typeof e.appexProfiles)for(const i in e.appexProfiles){l.message("doing",`检查插件 ${e.pluginId} ${i} appex 配置中 ...`);const n=e.appexProfiles[i];if(!0===n.enable){const s=`${e.pluginId}_${i}`;d[s]={enable:!0};let o=n.profilePath;if(a&&(o=n.distributeProfilePath),n.bundleID&&o){const a=path_1.default.join(t,o);fs_extra_1.default.existsSync(a)?(d[s].bundleID=n.bundleID,d[s].profilePath=path_1.default.join(t,o)):(r=!0,l.message("fail",`${e.pluginId} 中 ${i} 的 profilePath 无法找到对应的文件:${a}(需要在小程序项目路径下,填入相对于项目根目录的路径)`))}else r=!0,l.message("fail",`${e.pluginId}中${i} 是 无效的appexProfiles配置。需要配置 bundleID,profilePath,distributeProfilePath。profile 文件需要放置在小程序项目内,然后配置相对于小程序项目根目录的相对路径。分发证书构建的情况下, 一定需要配置distributeProfilePath。查看文档了解详情。`)}}})}if(e.forEach(e=>{fs_extra_1.default.readdirSync(e.dir).forEach(i=>{if(i.endsWith(".appex")){const t=path_1.default.parse(i).name,n=d[t];if(n&&!0===n.enable)if(n.bundleID&&n.profilePath){if(n.bundleID&&n.profilePath){const t=path_1.default.join(e.dir,i,"info.plist"),a=n.bundleID;this.changeInfoplistBundleId(t,a),this.changeInfoplistBundleVersion(t,s,o),l.message("doing",`${e.pluginId} ${i} ${a} ${t} 处理 appex bundle ID 中`)}}else r=!0,l.message("fail",`${e.pluginId} 的 多端插件包含了${t.slice(e.pluginId.length+1)} 的 appex。开发者需要在project.miniapp.json 中 mini-plugin 配置下对应合理的 profile 文件。查看文档了解详情。`)}})}),r)return!1;if(!(0,lodash_1.isEmpty)(d)){const e=path_1.default.join(n,APPEX_PROFILES_MAPS_FILE);fs_extra_1.default.existsSync(e)&&fs_extra_1.default.removeSync(e),fs_extra_1.default.ensureFileSync(e);const i={};for(const e in d)i[e]={bundleID:d[e].bundleID,profilePath:d[e].profilePath};fs_extra_1.default.writeFileSync(e,JSON.stringify(i));const t=path_1.default.join(n,APPEX_PROFILES_MAPS_FOR_SHELL_FILE);fs_extra_1.default.existsSync(t)&&fs_extra_1.default.removeSync(t),fs_extra_1.default.ensureFileSync(t);const a=Object.keys(d).map(e=>{const i=d[e];return`pluginAppexName:${e};_;_;bundleID:${i.bundleID};_;_;profile:${i.profilePath}\n\n`}).join("");fs_extra_1.default.writeFileSync(t,a)}return d}changeExtendSDKInfoplistBundleId(e,i,t){const n=`${i}.${path_1.default.parse(t).name.replace(/_/g,"")}`;return this.changeInfoplistBundleId(e,n)}changeInfoplistBundleId(e,i){const t=plist.readFileSync(e);return t.CFBundleIdentifier=i,plist.writeFileSync(e,t),t.CFBundleIdentifier}changeInfoplistBundleVersion(e,i,t){const n=plist.readFileSync(e);return n.CFBundleVersion=i,n.CFBundleShortVersionString=t,plist.writeFileSync(e,n),n.CFBundleIdentifier}async getEntitlements(e,i,t,n){const{mobileapp_info:a={}}=e;let s=a.ios_universal_link||a.debug_ios_universal_link;return(s.startsWith("https://")||s.startsWith("http://"))&&(s=s.replace(/^http(s)?:\/\//g,"applinks:")),{"com.apple.developer.associated-domains":s}}useTpush(e){return(0,miniappJson_1.iOSMiniAppJsonIsUsingTpush)(e)}async buildCloud(e,i){const{projectPath:t,demoIpaPath:n,sdkPath:a,arch:s="arm64",bindingInfo:o,certificateInfo:l,output:r,miniappCacheDirPath:d,pluginDirList:p,inLandun:u,theme:c,i18nInfo:f}=e,_=this.generateTempDemoIpaPath(n),{selfCertificate:h={}}=l,g=(null==h?void 0:h.isPublish)||!1,m=(0,miniappJson_1.tryGetIOSMiniappJson)(t),y=this.useTpush(m);if((0,lodash_1.isEmpty)(m))throw new Error("获取project.miniapp.json失败");if(errorIOSSdkVersions.includes(m.sdkVersion))throw new Error("当前 mini-ios.sdkVersion 存在缺陷,请参考更新日志进行修改");let I=o;if(l.signType===miniapp_builder_1.miniappSinTypes.appleId.type){const{mobileapp_info:e={}}=I;I=Object.assign(Object.assign({},I),{mobileapp_info:Object.assign(Object.assign({},e),{bundle_id:miniapp_builder_1.DEFAULT_BUNDLE_ID,debug_ios_bundle_id:miniapp_builder_1.DEFAULT_BUNDLE_ID})})}const S=await this.updateIOSInfoPlistInfo(t,I,_,m,i,f);await this.updateIOSAppConfigPlistInfo(t,I,_,m,a,!1,i,c,f),await this.updateIOSAppexInfoPlistInfo(I,_,m,S,i),await this.updateIOSIcons(t,_,d,m,g,i),await this.updateSplashScreen(t,_,m,i,c,f),await this.updateExtendedSdk(I,_,a,s,m,i),await this.updatePlugin(_,p,t,m,d,g,S,i),await this.updatePrivacyInfo(_,m,i);const x=await this.getEntitlements(I,_,m,i),{mobileapp_info:v={}}=I;let b;b=l.signType===miniapp_builder_1.miniappSinTypes.appleId.type?miniapp_builder_1.DEFAULT_BUNDLE_ID:v.ios_flag&&v.bundle_id||v.debug_ios_bundle_id;const P={bundleId:b,output:r,entitlements:x};if(m.buildCloud&&(m.buildCloud.certificate&&"string"==typeof m.buildCloud.certificate&&(P.certificate=m.buildCloud.certificate),m.buildCloud.profile&&"string"==typeof m.buildCloud.profile&&(P.profile=path_1.default.join(t,m.buildCloud.profile)),y&&m.buildCloud.tpnsProfile&&"string"==typeof m.buildCloud.tpnsProfile&&(P.tpnsProfile=path_1.default.join(t,m.buildCloud.tpnsProfile))),h.isPublish){const e=await(0,codesign_1.codesignAndExport)(t,_,d||"",P,i,y,!0===u);if(!0!==e.success)throw new Error("Build ipa failed:"+(e.errMsg||"codesignAndExport failed"))}return{projectPath:t,demoIpaPath:_,opts:P,iosMiniappJson:m,isPublish:g}}async writeI18NInfoFile(e,i,t){Object.keys(i).forEach(n=>{if("base"===n)return;let a="";Object.keys(t).forEach(e=>{var s,o,l,r;"UISplashScreenImageName"!==e?"UILaunchStoryboardName"!==e?(null===(o=null===(s=i[n])||void 0===s?void 0:s.ios)||void 0===o?void 0:o[t[e]])&&(a+=`${e} = "${null===(r=null===(l=i[n])||void 0===l?void 0:l.ios)||void 0===r?void 0:r[t[e]]}";\n`):a+="__UILaunchStoryboardName__\n":a+="__UISplashScreenImageName__\n"}),a&&(fs_extra_1.default.ensureDirSync(path_1.default.join(e,n+".lproj")),fs_extra_1.default.writeFileSync(path_1.default.join(e,n+".lproj/InfoPlist.strings"),a))})}getMaterialFilePath(e,i){if(!i)return"";let t=i;if(path_1.default.isAbsolute(i)||(t=path_1.default.join(e,i)),fs_extra_1.default.existsSync(t))return t;const n=(0,tools_1.generateMD5)(i),a=path_1.default.basename(i),s=path_1.default.join(e,exports.remoteBuildProjectMaterialAbsoluteCacheDir,`${n}_${a}`);return fs_extra_1.default.existsSync(s)?s:""}}exports.default=new buildCloudManager;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.remoteBuildProjectMaterialAbsoluteCacheDir=void 0;const tslib_1=require("tslib"),child_process=tslib_1.__importStar(require("child_process")),path_1=tslib_1.__importDefault(require("path")),fs_extra_1=tslib_1.__importDefault(require("fs-extra")),glob_1=tslib_1.__importDefault(require("glob")),env_1=require("../../../utils/env"),miniapp_builder_1=require("../../../utils/miniapp-builder"),codesign_1=require("../../../utils/codesign"),miniappJson_1=require("../../../utils/miniappJson"),lodash_1=require("lodash"),tools_1=require("../../../utils/tools"),uuidv4=require("uuid/v4"),sizeOf=require("image-size"),plist=require("simple-plist"),errorIOSSdkVersions=["1.0.19"],APPEX_PROFILES_MAPS_FILE="__appexProfilesCacheDir__/profilesMap.json",APPEX_PROFILES_MAPS_FOR_SHELL_FILE="__appexProfilesCacheDir__/profilesMapForShell.txt",defaultIconDirPath=path_1.default.join(__dirname,"../../../static/images/"),getDepReg=e=>new RegExp(`s.subspec '${e}'.*\n(?:.*\n)*?(?:.*sp.vendored_frameworks = \\[\n)((?:.*'.*?'.*\n)*?)(?:.*\\]\n)`,"m"),allowTheme=["Light","LightSpecial","Dark","DarkSpecial","Default"];exports.remoteBuildProjectMaterialAbsoluteCacheDir="__absoluteFile";const iconInfoMap={appStore1024:{size:[1024,1024],scale:1,idiom:"ios-marketing",required:!0},appStore1024Other:{size:[1024,1024],scale:1,idiom:"ios-marketing-other"},mainIcon120:{size:[60,60],scale:2,idiom:"iphone",required:!0},mainIcon180:{size:[60,60],scale:3,idiom:"iphone"},spotlightIcon80:{size:[40,40],scale:2,idiom:"iphone"},spotlightIcon120:{size:[40,40],scale:3,idiom:"iphone"},settingsIcon58:{size:[29,29],scale:2,idiom:"iphone"},settingsIcon87:{size:[29,29],scale:3,idiom:"iphone"},notificationIcon40:{size:[20,20],scale:2,idiom:"iphone"},notificationIcon60:{size:[20,20],scale:3,idiom:"iphone"},ipadMainIcon152:{size:[76,76],scale:2,idiom:"ipad"},ipadMainIcon167:{size:[83.5,83.5],scale:2,idiom:"ipad"},ipadSpotlightIcon40:{size:[40,40],scale:1,idiom:"ipad"},ipadSpotlightIcon80:{size:[40,40],scale:2,idiom:"ipad"},ipadSettingsIcon29:{size:[29,29],scale:1,idiom:"ipad"},ipadSpotlightIcon58:{size:[29,29],scale:2,idiom:"ipad"},ipadNotificationIcon20:{size:[20,20],scale:1,idiom:"ipad"},ipadNotificationIcon40:{size:[20,20],scale:2,idiom:"ipad"}};class buildCloudManager{generateTempDemoIpaPath(e){const i=path_1.default.join(e,"../.."),t=path_1.default.basename(i),n=path_1.default.dirname(i),a=path_1.default.join(n,t+"-operateDir");fs_extra_1.default.existsSync(a)&&fs_extra_1.default.removeSync(a),fs_extra_1.default.ensureDirSync(a);const s=path_1.default.join(a,"Payload/demo.app");return fs_extra_1.default.copySync(e,s),s}generateInfoPlistCFBundleURLTypesItem(e){const i={};return e.CFBundleURLName&&(i.CFBundleURLName=e.CFBundleURLName),e.CFBundleURLSchemes&&(i.CFBundleURLSchemes=[e.CFBundleURLSchemes]),e.CFBundleTypeRole&&(i.CFBundleTypeRole=e.CFBundleTypeRole),i}updatePrivacyBackgroundImage(e,i,t,n,a){t.message("doing","updatePrivacyBackgroundImage "+n);if(fs_extra_1.default.readdirSync(i).forEach(e=>{"privacy_"+n===path_1.default.basename(e,path_1.default.extname(e))&&fs_extra_1.default.removeSync(path_1.default.join(i,e))}),!a)return;path_1.default.isAbsolute(a)||(a=path_1.default.join(e,a)),a=this.getMaterialFilePath(e,a);const s=path_1.default.extname(a),o=path_1.default.join(i,`privacy_${n}${s}`);try{fs_extra_1.default.copyFileSync(a,o)}catch(e){throw t.message("error",`copy privacy image failed: ${n}, ${a} to ${o}`),e}}async updateIOSInfoPlistInfo(e,i,t,n,a,s){var o,r,l,d,p,u,c,f,_,h;a.progress("update app base info...");const{mobileapp_info:m={}}=i,g=m.mobileapp_id,y=path_1.default.join(t,"Info.plist"),I={},S=(e,i)=>{var t,n;if((null==i?void 0:i.startsWith("%"))&&(null==i?void 0:i.endsWith("%"))){const o=i.slice(1,-1);I[e]=o;const r=(null===(n=null===(t=null==s?void 0:s.base)||void 0===t?void 0:t.ios)||void 0===n?void 0:n[o])||"";return r||a.message("error",`未在国际化配置 base.json 中找到字段 ${o},请检查`),r}return i};S("UISplashScreenImageName",null===(o=null==n?void 0:n.splashscreen)||void 0===o?void 0:o.customImage),S("UILaunchStoryboardName",null===(r=null==n?void 0:n.splashscreen)||void 0===r?void 0:r.customImage);const x=plist.readFileSync(y);if(x.CFBundleName=S("CFBundleName",n.name),x.CFBundleDisplayName=S("CFBundleDisplayName",n.name),x.CFBundleShortVersionString=n.version,"number"==typeof n.versionCode?x.CFBundleVersion=parseInt(n.versionCode.toString(),10).toString():x.CFBundleVersion=(parseInt(x.CFBundleVersion,10)+1).toString(),x.CFBundleIdentifier=this.getBundleIdentifier(m),Array.isArray(null==n?void 0:n.openMimeTypes)&&this.validateCFBundleDocumentTypes(n.openMimeTypes,a)&&(x.CFBundleDocumentTypes=n.openMimeTypes,a.message("doing","openMimeTypes 应用成功")),Array.isArray(x.CFBundleURLTypes)||(x.CFBundleURLTypes=[]),(null===(d=null===(l=x.CFBundleURLTypes)||void 0===l?void 0:l[0])||void 0===d?void 0:d.CFBundleURLSchemes)&&(x.CFBundleURLTypes[0].CFBundleURLSchemes=[g]),x.CFBundleURLTypes[0]&&(x.CFBundleURLTypes=[x.CFBundleURLTypes[0]]),Object.keys(miniappJson_1.iosPrivacyDescObj).forEach(e=>{var i,t;(null===(i=null==n?void 0:n.privateDescriptions)||void 0===i?void 0:i[e])?x[e]=S(e,null===(t=n.privateDescriptions)||void 0===t?void 0:t[e]):delete x[e]}),!0===(null===(p=null==n?void 0:n.infoPlist)||void 0===p?void 0:p.DisableAppUsesNonExemptEncryption)?x.ITSAppUsesNonExemptEncryption=!1:delete x.ITSAppUsesNonExemptEncryption,x.UIBackgroundModes=[],!0===(null===(u=null==n?void 0:n.infoPlist)||void 0===u?void 0:u.AudioInBackgroundMode)&&x.UIBackgroundModes.push("audio"),!0===(null===(c=null==n?void 0:n.infoPlist)||void 0===c?void 0:c.LocationInBackgroundMode)&&x.UIBackgroundModes.push("location"),!0===(null===(f=null==n?void 0:n.infoPlist)||void 0===f?void 0:f.requiresFullScreen)?x.UIRequiresFullScreen=!0:delete x.UIRequiresFullScreen,"object"==typeof(null===(_=null==n?void 0:n.infoPlist)||void 0===_?void 0:_.CFBundleURLTypes)){const e=this.generateInfoPlistCFBundleURLTypesItem(n.infoPlist.CFBundleURLTypes);x.CFBundleURLTypes.push(e);const{additionalCFBundleURLTypes:i}=n.infoPlist.CFBundleURLTypes;Array.isArray(i)&&i.forEach(e=>{if("object"==typeof e){const i=this.generateInfoPlistCFBundleURLTypesItem(e);x.CFBundleURLTypes.push(i)}})}if(!0===n.enableIpad&&((0,miniappJson_1.iOSAppJsonIsUsingIPadResizable)(e)?(x["UISupportedInterfaceOrientations~ipad"]=["UIInterfaceOrientationPortrait","UIInterfaceOrientationPortraitUpsideDown","UIInterfaceOrientationLandscapeLeft","UIInterfaceOrientationLandscapeRight"],a.progress("ipad is support Landscape")):(x["UISupportedInterfaceOrientations~ipad"]=["UIInterfaceOrientationPortrait","UIInterfaceOrientationPortraitUpsideDown"],a.progress("ipad is not support Landscape"))),null===(h=n.infoPlist)||void 0===h?void 0:h.LSApplicationQueriesSchemes){const e=n.infoPlist.LSApplicationQueriesSchemes.split(",");e.length&&x.LSApplicationQueriesSchemes.push(...e.filter(e=>e))}return plist.writeFileSync(y,x),await this.writeI18NInfoFile(t,s,I),x.CFBundleVersion}getBundleIdentifier(e){return e.ios_flag&&e.bundle_id||e.debug_ios_bundle_id}validateCFBundleDocumentTypes(e,i){const t=["Owner","Default"," Alternate","None"],n=["Editor","Viewer"," Shell","None"],a=new Set;for(const s of e){if(a.has(s.CFBundleTypeName))return i.message("error","openMimeTypes 应用失败,存在重复定义的 CFBundleTypeName: "+s.CFBundleTypeName),!1;if(a.add(s.CFBundleTypeName),!t.includes(s.LSHandlerRank))return i.message("error","openMimeTypes 应用失败,存在不合法的 LSHandlerRank: "+s.LSHandlerRank),!1;if(!n.includes(s.CFBundleTypeRole))return i.message("error","openMimeTypes 应用失败,存在不合法的 CFBundleTypeRole: "+s.CFBundleTypeRole),!1;if(!Array.isArray(s.LSItemContentTypes))return i.message("error","openMimeTypes 应用失败,LSItemContentTypes 类型不合法"),!1}return!0}useGDT(e){return(0,miniappJson_1.iOSMiniAppJsonIsUsingGDT)(e)}async updateIOSAppConfigPlistInfo(e,i,t,n,a,s,o,r="Dark",l){var d,p,u,c;o.progress("update app module info...");const{module_info:f={},cpa_info:_={},cpa_package_info:h={enable_remove_watermark:!1}}=i;if(!_.sdk_key||!_.sdk_key_secret)throw new Error("sdkKey and sdkSecret not found");const m=path_1.default.join(t,"MiniApp.bundle"),g=path_1.default.join(m,"AppConfig.plist"),y=plist.readFileSync(g);h.enable_remove_watermark?y.enableRemoveWatermark=!0:y.splashscreenTheme=r,y.miniModuleId=f.module_id,y.sdkKey=_.sdk_key,y.sdkSecret=_.sdk_key_secret;const{privacy:I={}}=n;y.privacy||(y.privacy={}),y.privacy.enable=!!I.enable;const S=path_1.default.posix.join(m,"configs/privacy.json"),{contentViewImage:x,cancelButtonImage:v,confirmButtonImage:b,template:F}=I;if(I.enable){let i=F||"";if(fs_extra_1.default.ensureDirSync(path_1.default.posix.join(m,"configs")),i.startsWith("%")&&i.endsWith("%")){const t=F.slice(1,-1);i=(null===(p=null===(d=null==l?void 0:l.base)||void 0===d?void 0:d.ios)||void 0===p?void 0:p[t])||"",i||o.message("error",`未在国际化配置 base.json 中找到字段 ${t},请检查`),Object.keys(l).forEach(i=>{var n,a;if("base"===i)return;let s=null===(a=null===(n=l[i])||void 0===n?void 0:n.ios)||void 0===a?void 0:a[t];if(s){s=this.getMaterialFilePath(e,s);const t=`configs/privacy-${i}.json`,n=path_1.default.posix.join(m,t);fs_extra_1.default.existsSync(s)?fs_extra_1.default.copyFileSync(s,n):o.message("error",`未找到隐私协议在国际化配置 ${i}.json 中配置的文件 ${s},请检查`)}})}i?(i=this.getMaterialFilePath(e,i),fs_extra_1.default.existsSync(i)?(fs_extra_1.default.copyFileSync(i,S),y.privacy.template="configs/privacy.json"):(o.message("error",`未找到隐私协议中配置的文件 ${i},请检查`),y.privacy.template="configs/defaultPrivacy.json")):y.privacy.template="configs/defaultPrivacy.json",!0===I.enableNativePlugin&&"string"==typeof I.nativePluginId&&I.nativePluginId.length>2&&(y.privacy.plugin={pluginId:I.nativePluginId,enable:!0})}else y.privacy.template="",fs_extra_1.default.removeSync(S);this.updatePrivacyBackgroundImage(e,t,o,"contentViewImage",x),this.updatePrivacyBackgroundImage(e,t,o,"confirmButtonImage",b),this.updatePrivacyBackgroundImage(e,t,o,"cancelButtonImage",v);const{appMenuEnable:P=!0}=n;y.appMenuEnable=P;const{enableVConsole:B="undefined"}=n;y.enableVConsole=B;const{tpush:j}=n;let C=!1;if("object"==typeof j){const e=path_1.default.posix.join(t,"PlugIns/TPNSService.appex"),i=path_1.default.posix.join(e,"AppConfig.plist");if(this.useTpush(n)){y.TPNSAccessID=j.accessID,y.TPNSAccessKey=j.accessKey,j.clusterDomainName?y.clusterDomainName=j.clusterDomainName:delete y.clusterDomainName;const t=s?"x86_64":"arm64",n=path_1.default.join(a,`appex/${t}/TPNSService.appex`);if(!fs_extra_1.default.existsSync(n))throw new Error("can not found extendsdk: "+n);try{fs_extra_1.default.copySync(n,e),plist.writeFileSync(i,y),C=!0}catch(e){throw new Error("copy TPNSService.appex to app failed: "+e)}}}if(!C)try{const e=path_1.default.posix.join(t,"PlugIns");fs_extra_1.default.existsSync(e)?(fs_extra_1.default.removeSync(e),o.progress("removed PlugIns folder...")):o.progress("no PlugIns folder...")}catch(e){throw new Error("remove TPNSService.appex from app failed: "+e)}if(null===(u=n.useExtendedSdk)||void 0===u?void 0:u.WeAppLBS){if(!n.qmapAPIKey)throw new Error("You need to provide the Tencent Location Service API Key when using LBS SDK.");y.qmapAPIKey=n.qmapAPIKey}const{gdt:w}=n,L=this.useGDT(n);if(y.GDTAd=L?{appid:w.appid,enable:!0,SplashAd:{placementId:w.splashAd_placementId,fetchDelay:w.splashAd_fetchDelay||3,defaultEnable:null===(c=w.splashAd_defaultEnable)||void 0===c||c}}:{appid:"",enable:!1,SplashAd:{placementId:"",fetchDelay:3}},n["mini-plugin"]&&Array.isArray(n["mini-plugin"].ios)){const e=n["mini-plugin"].ios.filter(e=>!!(e.open&&e.pluginId&&e.loadWhenStart)).map(e=>e.pluginId);y.plugins={loadWhenStart:e}}const{enableDebugLog:D=!1}=n;y.enableDebugLog=D;const{debugLogSizeLimit:$=10}=n;isNaN(Number($))?o.message("error",`ios debugLogSizeLimit ${$} is NaN`):y.debugLogSizeLimit=Number($);const{enableOpenUrlNavigate:A=!1}=n;y.enableOpenUrlNavigate=A,plist.writeFileSync(g,y)}async updateIOSAppexInfoPlistInfo(e,i,t,n,a){if(this.useTpush(t)){a.progress("update appex for notification base info...");const{mobileapp_info:s={}}=e,o=path_1.default.join(i,"PlugIns/TPNSService.appex"),r=path_1.default.join(o,"Info.plist"),l=plist.readFileSync(r);l.CFBundleShortVersionString=t.version,a.progress("update appex for CFBundleVersion: "+n),l.CFBundleVersion=n;const d=s.ios_flag&&s.bundle_id||s.debug_ios_bundle_id;l.CFBundleIdentifier=t.tpush.serviceBundleId||d+".service",a.progress("update appex bundle identifier for infoPlist : "+l.CFBundleIdentifier),plist.writeFileSync(r,l)}else a.progress("not using tpush...")}updateBundleIcons(e,i,t,n,a){const s=[],o=[],r=[];for(const l in t){if(!t[l])continue;const d=this.getMaterialFilePath(e,t[l]);if(!d)return void a.message("error","getMatrialFailed: "+t[l]);const p=iconInfoMap[l];try{const e=sizeOf(d),i=p.size[0]*p.scale,n=p.size[1]*p.scale;if(e.width!==i||e.height!==n){a.progress(`check ${l} size failed, require [${i}, ${n}] but [${e.width}, ${e.height}] ingore ${t[l]} `);continue}}catch(e){a.progress(`get ${l} info failed, ingore ${t[l]}(e: ${e.message})`);continue}const u=path_1.default.extname(d),c=1===p.scale?"":`@${p.scale}x`,f=`${p.size[0]}x${p.size[1]}`,_=l.startsWith("ipad"),h="appStore1024"===l||"appStore1024Other"===l,m="appStore1024Other"===l?n+"Other":n,g=path_1.default.join(i,`${m}${f}${c}${_?"~ipad":""}${u}`),y={from:d,to:g,filename:path_1.default.basename(g),size:f,scale:p.scale+"x",idiom:p.idiom,key:l};s.push(y),h||(_?r.includes(`${m}${f}`)||r.push(`${m}${f}${c}`):o.includes(`${m}${f}`)||o.push(`${m}${f}${c}`))}return{iphoneBundleIconFiles:o,ipadBundleIconFiles:r,addFiles:s}}async updateIOSIcons(e,i,t,n,a,s){s.progress("update app icons...");const{icons:o={}}=n,r=a&&!env_1.isWin&&!!t;s.progress("genAssetCar: "+r);const l=glob_1.default.sync("AppIcon*.+(png|jpg|jpeg|webp)",{nodir:!0,cwd:i}).map(e=>path_1.default.join(i,e)),d="AppIcon-"+uuidv4().slice(0,8),p=this.updateBundleIcons(e,i,o,d,s);if(!p)throw new Error("updateBundleIcons failed");const{iphoneBundleIconFiles:u=[],ipadBundleIconFiles:c=[],addFiles:f=[]}=p,_={};for(const e in iconInfoMap){if(!iconInfoMap[e].required||o[e])continue;const i=iconInfoMap[e].size[0]*iconInfoMap[e].scale,t=iconInfoMap[e].size[1]*iconInfoMap[e].scale;if(_[e]=path_1.default.join(defaultIconDirPath,`donut-icon${i}x${t}.png`),s.progress(`using default app icons when ${e} is not config...`),!fs_extra_1.default.existsSync(_[e]))throw new Error(`required ${e} but not default or set`)}const h=this.updateBundleIcons(e,i,_,d,s);if(!h)throw new Error("updateBundleIcons WithDefaultIcon failed");const{iphoneBundleIconFiles:m,ipadBundleIconFiles:g,addFiles:y}=h;if(u.push(...m),c.push(...g),f.push(...y),!u.length&&!c.length)return;l.forEach(e=>{fs_extra_1.default.existsSync(e)&&fs_extra_1.default.removeSync(e)});const I=path_1.default.join(t,"__assetCarOperateDir/assetsCar/"),S=path_1.default.join(I,`Assets.xcassets/${d}.appiconset/`);r&&(fs_extra_1.default.ensureDirSync(S),fs_extra_1.default.emptyDirSync(S));const x=[];let v=!1;if(f.forEach(e=>{fs_extra_1.default.existsSync(e.to)&&fs_extra_1.default.removeSync(e.to),fs_extra_1.default.copyFileSync(e.from,e.to),r&&(fs_extra_1.default.copySync(e.from,path_1.default.join(S,e.filename)),"ios-marketing-other"===e.idiom&&(v=!0),x.push({filename:e.filename,size:e.size,scale:e.scale,idiom:e.idiom}))}),r&&fs_extra_1.default.writeJsonSync(path_1.default.join(S,"Contents.json"),{images:x,info:{author:"xcode",version:1}},{spaces:"\t"}),r){const e=path_1.default.join(__dirname,"../../../static/scripts/assetsCar/"),t=path_1.default.join(I,"createAssetsCar");fs_extra_1.default.copySync(e,I);try{await(0,codesign_1.checkXcodeEnv)(s),child_process.execSync(`"${t}" ${d}`,{env:(0,env_1.getProcessEnv)()})}catch(e){s.progress("createAssetsCar failed "+(e.message||""))}const n=path_1.default.join(I,"build/Assets.car"),a=path_1.default.join(i,"Assets.car");fs_extra_1.default.copyFileSync(n,a)}else{const e=path_1.default.join(i,"Assets.car");fs_extra_1.default.removeSync(e)}const b=path_1.default.join(i,"Info.plist"),F=plist.readFileSync(b);if(!F.CFBundleIcons){const e={CFBundlePrimaryIcon:{}};F.CFBundleIcons=e}v&&(F.CFBundleIcons.CFBundleAlternateIcons={OtherAppStoreIcon:{CFBundleIconFiles:[d+"Other"],CFBundleIconName:"OtherAppStoreIcon"}}),F.CFBundleIcons.CFBundlePrimaryIcon.CFBundleIconName=d,F.CFBundleIcons.CFBundlePrimaryIcon.CFBundleIconFiles=u,F["CFBundleIcons~ipad"]||(F["CFBundleIcons~ipad"]={CFBundlePrimaryIcon:{}}),F["CFBundleIcons~ipad"].CFBundlePrimaryIcon.CFBundleIconName=d,F["CFBundleIcons~ipad"].CFBundlePrimaryIcon.CFBundleIconFiles=c,F.NSAppTransportSecurity={NSAllowsArbitraryLoads:!0},plist.writeFileSync(b,F)}replaceLaunchScreenImage(e,i,t,n,a,s){const o=path_1.default.join(e,"01J-lp-oVM-view-Ze5-6b-2t3.nib");let r=fs_extra_1.default.readFileSync(o).toString("hex");if(!i.endsWith(".png"))return void n.message("error","IOS 启动页图片配置格式错误,必须为 PNG 格式, 错误配置:"+i);const l=this.getMaterialFilePath(a,i),d=t+".png",p="LaunchScreen-"+uuidv4().slice(0,12),u=p+".png",c=path_1.default.join(s,u);fs_extra_1.default.copyFileSync(l,c);const f=Buffer.from(d,"utf-8").toString("hex"),_=Buffer.from(u,"utf-8").toString("hex");return-1!==r.indexOf(f)?(r=r.replace(f,_),console.log("replace storyboard customImage success")):console.log("replace storyboard customImage fail"),fs_extra_1.default.writeFileSync(o,Buffer.from(r,"hex")),p}async updateSplashScreen(e,i,t,n,a="Dark",s){var o,r,l;let d;n.progress("update splashscreen image..."),allowTheme.includes(a)&&(d=path_1.default.join(i,`/Base.lproj/LaunchScreen${a}.storyboardc`)),d&&fs_extra_1.default.existsSync(d)&&fs_extra_1.default.copySync(d,path_1.default.join(i,"/Base.lproj/LaunchScreen.storyboardc")),allowTheme.forEach(e=>{const t=path_1.default.join(i,`/Base.lproj/LaunchScreen${e}.storyboardc`);fs_extra_1.default.existsSync(t)&&fs_extra_1.default.removeSync(t)});let p=null===(o=null==t?void 0:t.splashscreen)||void 0===o?void 0:o.customImage;if(!p)return;const u=path_1.default.join(i,"Info.plist"),c=plist.readFileSync(u),f=c.UISplashScreenImageName;if(glob_1.default.sync("LaunchScreen-*.+(png|jpg|jpeg|webp)",{nodir:!0,cwd:i}).forEach(e=>{const t=path_1.default.join(i,e);fs_extra_1.default.removeSync(t)}),p.startsWith("%")&&(null==p?void 0:p.endsWith("%"))){const t=p.slice(1,-1),a=(null===(l=null===(r=null==s?void 0:s.base)||void 0===r?void 0:r.ios)||void 0===l?void 0:l[t])||"";if(!a)return void n.message("error",`未在国际化配置 base.json 中找到字段 ${t},请检查,启动页国际化配置失败`);p=a,Object.keys(s).forEach(a=>{var o,r;if("base"===a)return;const l=null===(r=null===(o=s[a])||void 0===o?void 0:o.ios)||void 0===r?void 0:r[t];if(l){const t=path_1.default.join(i,`/${a}.lproj/LaunchScreen_${a}.storyboardc`);fs_extra_1.default.ensureDirSync(path_1.default.join(t,"..")),fs_extra_1.default.copySync(path_1.default.join(i,"/Base.lproj/LaunchScreen.storyboardc"),t);const s=this.replaceLaunchScreenImage(t,this.getMaterialFilePath(e,l),f,n,e,i);n.progress(`update ${a} splashscreen image...`);const o=fs_extra_1.default.readFileSync(path_1.default.join(i,a+".lproj/InfoPlist.strings"),"utf8");let r="";r=s?o.replace("__UISplashScreenImageName__",`UISplashScreenImageName = "${s}";\n`).replace("__UILaunchStoryboardName__",`UILaunchStoryboardName = "LaunchScreen_${a}";\n`):o.replace("__UISplashScreenImageName__","").replace("__UILaunchStoryboardName__",""),fs_extra_1.default.writeFileSync(path_1.default.join(i,a+".lproj/InfoPlist.strings"),r),n.progress(`update ${a} splashscreen image success`)}})}n.progress("update base splashscreen image...");const _=this.replaceLaunchScreenImage(path_1.default.join(i,"/Base.lproj/LaunchScreen.storyboardc"),this.getMaterialFilePath(e,p),f,n,e,i);n.progress("update base splashscreen image success"),_&&(c.UISplashScreenImageName=_,c.UILaunchStoryboardName="LaunchScreen",plist.writeFileSync(u,c))}genUseExtendedSdk(e,i){const t=Object.assign({},e.useExtendedSdk||{});for(const i in e)if("object"==typeof e[i])for(const n in e[i])if(n.startsWith("useExtendedLib_WeApp")&&!0===e[i][n]){t[n.slice("useExtendedLib_".length)]=!0}return!t.WeAppLBS||t.WeAppOpenFuns||t.WeAppOpenFuns_HasPay||(t.WeAppOpenFuns=!0),"RemoteDebug"===(null==i?void 0:i.debugType)&&(t.WeAppUSB=!0),t}async updateExtendedSdk(e,i,t,n,a,s,o){const r=path_1.default.join(i,"Frameworks");fs_extra_1.default.ensureDirSync(r),o.progress("update extendsdk...");const l=path_1.default.join(t,"WeAppSDK.podspec"),d=fs_extra_1.default.readFileSync(l,"utf-8"),p=this.genUseExtendedSdk(a,s);o.progress("useExtendedSdks: "+JSON.stringify(p));const{mobileapp_info:u={}}=e,c=this.getBundleIdentifier(u);if(p.WeAppOpenFuns&&p.WeAppOpenFuns_HasPay)throw new Error("OpenFuncs SDK 只可勾选使用一个,请按需勾选使用");const f={};for(const e in p){if(!p[e])continue;const i=getDepReg(e),a=d.match(i);if(!(null==a?void 0:a[1]))throw new Error(`拓展模块 ${e} 不存在或已被移除,请检查 project.miniapp.json -> 对应平台 -> useExtendedSdk 删除配置 ${e},版本配置差异请参考更新日志或 https://dev.weixin.qq.com/docs/framework/dev/sdk/difflog.html`);const s=[];if(a[1].split("\n").forEach(e=>{const i=e.match(/.*'(.*?)',/);if(null==i?void 0:i[1]){const e=i[1].split("/").pop(),a=path_1.default.join(t,"Libs",n,e);if(!fs_extra_1.default.existsSync(a))throw new Error(`拓展模块 ${e} 不存在或已被移除,请检查 project.miniapp.json -> 对应平台 -> useExtendedSdk 删除配置 ${e},版本配置差异请参考更新日志或 https://dev.weixin.qq.com/docs/framework/dev/sdk/difflog.html`);const o=path_1.default.join(r,e);fs_extra_1.default.copySync(a,o),s.push(path_1.default.basename(e));const l=path_1.default.join(o,"info.plist");if(!fs_extra_1.default.existsSync(l))throw new Error("can not found extendsdk info.plist: "+e);this.changeExtendSDKInfoplistBundleId(l,c,e)}}),s.length){f[s.shift()]=s}}const _=path_1.default.join(i,"DyFrameworks.plist");fs_extra_1.default.existsSync(_)&&fs_extra_1.default.removeSync(_),plist.writeFileSync(_,f)}async updatePrivacyInfo(e,i,t){var n;const a=null===(n=null==i?void 0:i.privacy)||void 0===n?void 0:n.privacyInfo;a&&(a.endsWith("PrivacyInfo.xcprivacy")?fs_extra_1.default.existsSync(a)?(fs_extra_1.default.copySync(a,path_1.default.join(e,"/PrivacyInfo.xcprivacy")),t.progress("隐私清单文件替换成功")):t.message("error","隐私清单文件替换失败,文件不存在,将使用默认文件"):t.message("error","隐私清单文件替换失败,文件名必须为 PrivacyInfo.xcprivacy,将使用默认文件"))}async updatePlugin(e,i,t,n,a,s,o,r){if(!i.length)return;const l=path_1.default.join(e,"Frameworks"),d=path_1.default.join(e,"PlugIns");fs_extra_1.default.ensureDirSync(l),r.progress("update plugin...");const p=this.prepareAppexProfileConfig(i,n,t,a,s,o,n.version,r);if(!p)throw new Error("依赖的多端插件需要配置对应的profile");const u={};if(n["mini-plugin"]&&Array.isArray(n["mini-plugin"].ios)){n["mini-plugin"].ios.forEach(e=>{e.open&&e.pluginId&&"string"==typeof e.resourcePath&&e.resourcePath.length>0&&(u[e.pluginId]=e.resourcePath)})}i.forEach(i=>{const{pluginId:n}=i,a=i.dir,s=n+".framework",o=path_1.default.join(l,s);if(-1!==a.indexOf("local-miniapp-plugin")){const e=fs_extra_1.default.statSync(a),{mtime:i}=e;r.progress(`${n}.framework 正在使用本地版本,修改时间为 ${i}`)}fs_extra_1.default.existsSync(o)&&fs_extra_1.default.removeSync(o);const c=path_1.default.join(a,s);if(fs_extra_1.default.existsSync(c)){fs_extra_1.default.copySync(c,o),this.copyResourcesToMainBundle(c,e),this.copyUserResourcePathIntoPlugins(n,t,u[n],path_1.default.join(o,"MiniPlugin.bundle"),r);fs_extra_1.default.readdirSync(a).forEach(i=>{if(i.endsWith(".appex")){const s=path_1.default.parse(i).name,o=p[s],l=path_1.default.join(d,i);if(!o||!0!==o.enable)return;r.progress(`${n} 插件使用 appex 中 : ${i}`),fs_extra_1.default.existsSync(l)&&fs_extra_1.default.removeSync(l),fs_extra_1.default.ensureDirSync(l);const c=path_1.default.join(a,i);fs_extra_1.default.copySync(c,l),(null==o?void 0:o.profilePath)&&fs_extra_1.default.copySync(o.profilePath,path_1.default.join(l,"embedded.mobileprovision")),this.copyResourcesToMainBundle(c,e),this.copyUserResourcePathIntoPlugins(n,t,u[n],path_1.default.join(l,"MiniPlugin.bundle"),r)}else if(i.endsWith("framework")&&i!==s){const e=path_1.default.join(l,i),t=path_1.default.join(a,i);fs_extra_1.default.existsSync(e)&&fs_extra_1.default.removeSync(e),fs_extra_1.default.copySync(t,e)}})}else fs_extra_1.default.copySync(a,o),this.copyResourcesToMainBundle(a,e),this.copyUserResourcePathIntoPlugins(n,t,u[n],path_1.default.join(o,"MiniPlugin.bundle"),r)})}copyUserResourcePathIntoPlugins(e,i,t,n,a){const s=n;if(t){const n=path_1.default.basename(t),o=this.getMaterialFilePath(i,t);if(o){a.progress(`${e}.framework 正在拷贝配置的资源:${t}`);const i=fs_extra_1.default.lstatSync(o);fs_extra_1.default.ensureDirSync(s),i.isDirectory()?fs_extra_1.default.copySync(o,s):i.isFile()&&fs_extra_1.default.copyFileSync(o,path_1.default.join(s,n))}}}copyResourcesToMainBundle(e,i){const t=path_1.default.join(e,"MiniPlugin.bundle"),n=path_1.default.join(t,"PluginConfig.plist");if(fs_extra_1.default.existsSync(n)){const e=plist.readFileSync(n).CopyResourcesToMainBundle;(null==e?void 0:e.length)&&e.forEach(e=>{const n=path_1.default.join(t,e);fs_extra_1.default.existsSync(n)&&fs_extra_1.default.copySync(n,path_1.default.join(i,e))})}}prepareAppexProfileConfig(e,i,t,n,a,s,o,r){if(!n)return void r.message("doing","miniappCacheDirPath is missing");let l=!1;const d={};if(i["mini-plugin"]&&Array.isArray(i["mini-plugin"].ios)){i["mini-plugin"].ios.forEach(e=>{if(e.open&&e.pluginId&&"object"==typeof e.appexProfiles)for(const i in e.appexProfiles){r.message("doing",`检查插件 ${e.pluginId} ${i} appex 配置中 ...`);const n=e.appexProfiles[i];if(!0===n.enable){const s=`${e.pluginId}_${i}`;d[s]={enable:!0};let o=n.profilePath;if(a&&(o=n.distributeProfilePath),n.bundleID&&o){const a=path_1.default.join(t,o);fs_extra_1.default.existsSync(a)?(d[s].bundleID=n.bundleID,d[s].profilePath=path_1.default.join(t,o)):(l=!0,r.message("error",`${e.pluginId} 中 ${i} 的 profilePath 无法找到对应的文件:${a}(需要在小程序项目路径下,填入相对于项目根目录的路径)`))}else l=!0,r.message("error",`${e.pluginId}中${i} 是 无效的appexProfiles配置。需要配置 bundleID,profilePath,distributeProfilePath。profile 文件需要放置在小程序项目内,然后配置相对于小程序项目根目录的相对路径。分发证书构建的情况下, 一定需要配置distributeProfilePath。查看文档了解详情。`)}}})}if(e.forEach(e=>{fs_extra_1.default.readdirSync(e.dir).forEach(i=>{if(i.endsWith(".appex")){const t=path_1.default.parse(i).name,n=d[t];if(n&&!0===n.enable)if(n.bundleID&&n.profilePath){if(n.bundleID&&n.profilePath){const t=path_1.default.join(e.dir,i,"info.plist"),a=n.bundleID;this.changeInfoplistBundleId(t,a),this.changeInfoplistBundleVersion(t,s,o),r.message("doing",`${e.pluginId} ${i} ${a} ${t} 处理 appex bundle ID 中`)}}else l=!0,r.message("error",`${e.pluginId} 的 多端插件包含了${t.slice(e.pluginId.length+1)} 的 appex。开发者需要在project.miniapp.json 中 mini-plugin 配置下对应合理的 profile 文件。查看文档了解详情。`)}})}),l)return!1;if(!(0,lodash_1.isEmpty)(d)){const e=path_1.default.join(n,APPEX_PROFILES_MAPS_FILE);fs_extra_1.default.existsSync(e)&&fs_extra_1.default.removeSync(e),fs_extra_1.default.ensureFileSync(e);const i={};for(const e in d)i[e]={bundleID:d[e].bundleID,profilePath:d[e].profilePath};fs_extra_1.default.writeFileSync(e,JSON.stringify(i));const t=path_1.default.join(n,APPEX_PROFILES_MAPS_FOR_SHELL_FILE);fs_extra_1.default.existsSync(t)&&fs_extra_1.default.removeSync(t),fs_extra_1.default.ensureFileSync(t);const a=Object.keys(d).map(e=>{const i=d[e];return`pluginAppexName:${e};_;_;bundleID:${i.bundleID};_;_;profile:${i.profilePath}\n\n`}).join("");fs_extra_1.default.writeFileSync(t,a)}return d}changeExtendSDKInfoplistBundleId(e,i,t){const n=`${i}.${path_1.default.parse(t).name.replace(/_/g,"")}`;return this.changeInfoplistBundleId(e,n)}changeInfoplistBundleId(e,i){const t=plist.readFileSync(e);return t.CFBundleIdentifier=i,plist.writeFileSync(e,t),t.CFBundleIdentifier}changeInfoplistBundleVersion(e,i,t){const n=plist.readFileSync(e);return n.CFBundleVersion=i,n.CFBundleShortVersionString=t,plist.writeFileSync(e,n),n.CFBundleIdentifier}async getEntitlements(e,i,t,n){const{mobileapp_info:a={}}=e;let s=a.ios_universal_link||a.debug_ios_universal_link;return(s.startsWith("https://")||s.startsWith("http://"))&&(s=s.replace(/^http(s)?:\/\//g,"applinks:")),{"com.apple.developer.associated-domains":s}}useTpush(e){return(0,miniappJson_1.iOSMiniAppJsonIsUsingTpush)(e)}async buildCloud(e,i){const{projectPath:t,demoIpaPath:n,sdkPath:a,arch:s="arm64",bindingInfo:o,certificateInfo:r,output:l,miniappCacheDirPath:d,pluginDirList:p,inLandun:u,theme:c,i18nInfo:f,debugInfo:_}=e,h=this.generateTempDemoIpaPath(n),{selfCertificate:m={}}=r,g=(null==m?void 0:m.isPublish)||!1,y=(0,miniappJson_1.tryGetIOSMiniappJson)(t),I=this.useTpush(y);if((0,lodash_1.isEmpty)(y))throw new Error("获取project.miniapp.json失败");if(errorIOSSdkVersions.includes(y.sdkVersion))throw new Error("当前 mini-ios.sdkVersion 存在缺陷,请参考更新日志进行修改");let S=o;if(r.signType===miniapp_builder_1.miniappSinTypes.appleId.type){const{mobileapp_info:e={}}=S;S=Object.assign(Object.assign({},S),{mobileapp_info:Object.assign(Object.assign({},e),{bundle_id:miniapp_builder_1.DEFAULT_BUNDLE_ID,debug_ios_bundle_id:miniapp_builder_1.DEFAULT_BUNDLE_ID})})}const x=await this.updateIOSInfoPlistInfo(t,S,h,y,i,f);await this.updateIOSAppConfigPlistInfo(t,S,h,y,a,!1,i,c,f),await this.updateIOSAppexInfoPlistInfo(S,h,y,x,i),await this.updateIOSIcons(t,h,d,y,g,i),await this.updateSplashScreen(t,h,y,i,c,f),await this.updateExtendedSdk(S,h,a,s,y,_,i),await this.updatePlugin(h,p,t,y,d,g,x,i),await this.updatePrivacyInfo(h,y,i);const v=await this.getEntitlements(S,h,y,i),{mobileapp_info:b={}}=S;let F;F=r.signType===miniapp_builder_1.miniappSinTypes.appleId.type?miniapp_builder_1.DEFAULT_BUNDLE_ID:b.ios_flag&&b.bundle_id||b.debug_ios_bundle_id;const P={bundleId:F,output:l,entitlements:v};if(y.buildCloud&&(y.buildCloud.certificate&&"string"==typeof y.buildCloud.certificate&&(P.certificate=y.buildCloud.certificate),y.buildCloud.profile&&"string"==typeof y.buildCloud.profile&&(P.profile=path_1.default.join(t,y.buildCloud.profile)),I&&y.buildCloud.tpnsProfile&&"string"==typeof y.buildCloud.tpnsProfile&&(P.tpnsProfile=path_1.default.join(t,y.buildCloud.tpnsProfile))),m.isPublish){const e=await(0,codesign_1.codesignAndExport)(t,h,d||"",P,i,I,!0===u);if(!0!==e.success)throw new Error("Build ipa failed:"+(e.errMsg||"codesignAndExport failed"))}return{projectPath:t,demoIpaPath:h,opts:P,iosMiniappJson:y,isPublish:g}}async writeI18NInfoFile(e,i,t){Object.keys(i).forEach(n=>{if("base"===n)return;let a="";Object.keys(t).forEach(e=>{var s,o,r,l;"UISplashScreenImageName"!==e?"UILaunchStoryboardName"!==e?(null===(o=null===(s=i[n])||void 0===s?void 0:s.ios)||void 0===o?void 0:o[t[e]])&&(a+=`${e} = "${null===(l=null===(r=i[n])||void 0===r?void 0:r.ios)||void 0===l?void 0:l[t[e]]}";\n`):a+="__UILaunchStoryboardName__\n":a+="__UISplashScreenImageName__\n"}),a&&(fs_extra_1.default.ensureDirSync(path_1.default.join(e,n+".lproj")),fs_extra_1.default.writeFileSync(path_1.default.join(e,n+".lproj/InfoPlist.strings"),a))})}getMaterialFilePath(e,i){if(!i)return"";let t=i;if(path_1.default.isAbsolute(i)||(t=path_1.default.join(e,i)),fs_extra_1.default.existsSync(t))return t;const n=(0,tools_1.generateMD5)(i),a=path_1.default.basename(i),s=path_1.default.join(e,exports.remoteBuildProjectMaterialAbsoluteCacheDir,`${n}_${a}`);return fs_extra_1.default.existsSync(s)?s:""}}exports.default=new buildCloudManager;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.IOSUtils=void 0;const tslib_1=require("tslib"),child_process=tslib_1.__importStar(require("child_process")),path_1=tslib_1.__importDefault(require("path")),fs_extra_1=tslib_1.__importDefault(require("fs-extra")),env_1=require("../../../utils/env"),deviceUtils=tslib_1.__importStar(require("./device")),projectConfigUtils=tslib_1.__importStar(require("./projectconfig")),cp_1=require("../../../utils/cp"),miniapp_builder_1=require("../../../utils/miniapp-builder"),miniappJson_1=require("../../../utils/miniappJson"),singletontask_1=require("../../../utils/singletontask"),buildCloud_1=tslib_1.__importStar(require("./buildCloud")),tools_1=require("../../../utils/tools"),codesign_1=require("../../../utils/codesign"),ProjectMiniappJsonSplashScreenThemeKey="__splashscreenTheme",_iconInfoMap={appStore1024:{size:[1024,1024],scale:1,idiom:"ios-marketing",required:!0},mainIcon120:{size:[60,60],scale:2,idiom:"iphone",required:!0},mainIcon180:{size:[60,60],scale:3,idiom:"iphone"},spotlightIcon80:{size:[40,40],scale:2,idiom:"iphone"},spotlightIcon120:{size:[40,40],scale:3,idiom:"iphone"},settingsIcon58:{size:[29,29],scale:2,idiom:"iphone"},settingsIcon87:{size:[29,29],scale:3,idiom:"iphone"},notificationIcon40:{size:[20,20],scale:2,idiom:"iphone"},notificationIcon60:{size:[20,20],scale:3,idiom:"iphone"},ipadMainIcon152:{size:[76,76],scale:2,idiom:"ipad"},ipadMainIcon167:{size:[83.5,83.5],scale:2,idiom:"ipad"},ipadSpotlightIcon40:{size:[40,40],scale:1,idiom:"ipad"},ipadSpotlightIcon80:{size:[40,40],scale:2,idiom:"ipad"},ipadSettingsIcon29:{size:[29,29],scale:1,idiom:"ipad"},ipadSpotlightIcon58:{size:[29,29],scale:2,idiom:"ipad"},ipadNotificationIcon20:{size:[20,20],scale:1,idiom:"ipad"},ipadNotificationIcon40:{size:[20,20],scale:2,idiom:"ipad"}},_allowTheme=["Light","LightSpecial","Dark","DarkSpecial","Default"],_getDepReg=e=>new RegExp(`s.subspec '${e}'.*\n(?:.*\n)*?(?:.*sp.vendored_frameworks = \\[\n)((?:.*'.*?'.*\n)*?)(?:.*\\]\n)`,"m"),buildIOSPluginTask={};class IOSUtils{constructor(e,i={},t,n){this.root=e,this.userConfig=i,this.miniappDirPath=t,this.devtoolsVersion=n}getProjectConfig(){const e=projectConfigUtils.getProjectConfig(this.root,this.userConfig);if(!e)throw new Error("iOS project folder not found. Are you sure this is a miniapp project?");return e}getBundleId(e){return child_process.execFileSync("/usr/libexec/PlistBuddy",["-c","Print:CFBundleIdentifier",path_1.default.join(e,"Info.plist")],{encoding:"utf8",env:(0,env_1.getProcessEnv)()}).trim()}tryInstallPod(e,i){const t=this.getProjectConfig(),{sourceDir:n}=t,o={cwd:n,env:(0,env_1.getProcessEnv)()};i.progress("export LANG=en_US.UTF-8 && pod install"),child_process.execSync("export LANG=en_US.UTF-8 && pod install",o)}async runLocal(e,i){const t=this.getProjectConfig(),{sourceDir:n}=t;process.chdir(n),this.tryInstallPod(e,i);const o=path_1.default.basename(t.name,path_1.default.extname(t.name)),s=e.scheme||o;if(i.progress(`Found Xcode ${t.isWorkspace?"workspace":"project"} "${t.name}"`),e.device||e.udid){if(e.udid||e.device){const n=await deviceUtils.getDevices({recorder:i}),o=n.find(i=>i.udid===e.udid||i.name===e.device);if(!o)throw new Error(`Could not find a device with udid(${e.udid}) or device(${e.device}). ${deviceUtils.printFoundDevices(n)}`);if("simulator"===o.type)return void await this.runOnSimulatorLocal(t,s,e,i);await this.runOnDeviceLocal(t,s,o,i)}}else await this.runOnSimulatorLocal(t,s,e,i)}async runCloud(e,i){try{const{deviceType:t,udid:n,projectPath:o,demoIpaPath:s,sdkPath:a,bindingInfo:r,certificateInfo:c,arch:l="arm64",pluginDirList:d,miniappCacheDirPath:p,theme:u,i18nInfo:h}=e,f=buildCloud_1.default.generateTempDemoIpaPath(s),_="simulator"===t,m=(0,miniappJson_1.tryGetIOSMiniappJson)(o);let g=r;if(c.signType===miniapp_builder_1.miniappSinTypes.appleId.type){const{mobileapp_info:e={}}=g;g=Object.assign(Object.assign({},g),{mobileapp_info:Object.assign(Object.assign({},e),{bundle_id:miniapp_builder_1.DEFAULT_BUNDLE_ID,debug_ios_bundle_id:miniapp_builder_1.DEFAULT_BUNDLE_ID})})}const b=await buildCloud_1.default.updateIOSInfoPlistInfo(o,g,f,m,i,h);await buildCloud_1.default.updateIOSAppConfigPlistInfo(o,g,f,m,a,_,i,u,h),await buildCloud_1.default.updateIOSAppexInfoPlistInfo(g,f,m,b,i),await buildCloud_1.default.updateIOSIcons(o,f,"",m,!1,i),await buildCloud_1.default.updateSplashScreen(o,f,m,i,u,h),await buildCloud_1.default.updateExtendedSdk(g,f,a,l,m,i),await buildCloud_1.default.updatePlugin(f,d,o,m,p,!1,b,i);const v=await buildCloud_1.default.getEntitlements(g,f,m,i);if("device"===t){const{mobileapp_info:e={}}=g,t=e.ios_flag&&e.bundle_id||e.debug_ios_bundle_id;await(0,miniapp_builder_1.signAndInstallOrExport)(o,f,p,c,{bundleId:t,install:!0,deviceId:n,entitlements:v},{recorder:i,miniappDirPath:this.miniappDirPath,devtoolsVersion:this.devtoolsVersion})}else await this.runOnSimulatorCloud(f,{udid:n},i)}catch(e){throw new Error("Run the app failed:"+e.message)}}async buildLocal(e,i){const t=this.getProjectConfig();process.chdir(t.sourceDir);const n=path_1.default.basename(t.name,path_1.default.extname(t.name)),o=e.scheme||n;this.tryInstallPod(e,i),i.progress("start build ipa...");const s=await this.buildProjectArchive(t,{output:e.output,scheme:o},i),a=await this.exportArchive(t,s,e,i);return console.log("Successfully build ipa: "+a),a}async buildCloud(e,i){try{const{projectPath:t,certificateInfo:n,miniappCacheDirPath:o}=e,s=await buildCloud_1.default.buildCloud(e,i),{demoIpaPath:a,opts:r}=s,c={recorder:i,miniappDirPath:this.miniappDirPath,devtoolsVersion:this.devtoolsVersion};s.isPublish||await(0,miniapp_builder_1.signAndInstallOrExport)(t,a,o,n,r,c)}catch(e){throw new Error("Build ipa failed:"+e.message)}}async genProjectMaterialMap(e,i,t,n){var o,s;const a=buildCloud_1.remoteBuildProjectMaterialAbsoluteCacheDir,r=path_1.default.join(i,a),c=(0,miniappJson_1.tryGetIOSMiniappJson)(e);function l(e,i){fs_extra_1.default.ensureDirSync(path_1.default.dirname(i)),fs_extra_1.default.copyFileSync(e,i)}function d(t,n,o=!0){if(!n){if(o)return"";throw new Error(`file cant be empty for cloud build, key: ${t} , fileName: ${n}`)}if(path_1.default.isAbsolute(n)){const e=path_1.default.basename(n);if(!fs_extra_1.default.existsSync(n)){if(o)return"";throw new Error(`file cant be empty for cloud build, key: ${t} , fileName: ${n}`)}const i=(0,tools_1.generateMD5)(n);return l(n,path_1.default.join(r,`${i}_${e}`)),path_1.default.join(a,e)}const s=path_1.default.join(e,n),c=path_1.default.join(i,n);if(!fs_extra_1.default.existsSync(s)){if(o)return"";throw new Error(`file cant be empty for cloud build, key: ${t} , fileName: ${n}`)}return l(s,c),n}fs_extra_1.default.ensureDirSync(r);const{privacy:p={},icons:u={},splashscreen:h={},buildCloud:f={}}=c,_=d("project.miniapp.json","project.miniapp.json",!1),m=d("project.config.json","project.config.json",!1),g=(0,miniappJson_1.getMiniprogramRoot)(e),b=d("app.json",path_1.default.join(g,"app.json"),!1),{template:v,contentViewImage:y,cancelButtonImage:S,confirmButtonImage:w}=p,P=d("privacy template",v),I=d("privacy contentViewImage",y),x=d("privacy cancelButtonImage",S),j=d("privacy confirmButtonImage",w),E=[];for(const e in u)if(u[e]){const i=d("icons."+e,u[e],!1);i&&E.push(i)}const O=d("splashscreen.customImage",h.customImage),{p12:D,profile:C,tpnsProfile:A}=f,$=d("p12 Path",D,!1),T=d("profile Path",C,!1);let k=void 0;!0===(null===(o=null==c?void 0:c.tpush)||void 0===o?void 0:o.useExtendedLib_WeAppTPNS)&&(k=d("tpns profile Path",A,!0!==(null===(s=null==c?void 0:c.tpush)||void 0===s?void 0:s.useExtendedLib_WeAppTPNS)));const B="miniapp/ios/i18nInfo.json",U=path_1.default.join(e,B),F=d("i18n",B,!0);if(fs_extra_1.default.existsSync(U)){const i=function(e,i){function t(i,t,n){if(t[n]&&"object"==typeof t[n][i])for(const o in t[n][i])if("object"==typeof t[n][i]){const s=t[n][i][o];if("string"==typeof s&&s.length>0){fs_extra_1.default.existsSync(path_1.default.isAbsolute(s)?s:path_1.default.join(e,s))&&d(`i18nFiles.${n}.${o}`,s,!0)}}}try{const n=fs_extra_1.default.readJSONSync(path_1.default.join(e,i));for(const e in n)t("ios",n,e),t("android",n,e)}catch(e){return e.message}}(e,B);if(i)throw n.message("fail",i),new Error("copyi18NFiles error "+i)}const L=path_1.default.join(i,"project.miniapp.json");try{const e=fs_extra_1.default.readJsonSync(L);let{theme:i}=t;t.theme||(i="Dark"),e.__splashscreenTheme=i,fs_extra_1.default.writeJSONSync(L,e)}catch(e){throw new Error(`ReadWriteJsonFailed projectMiniappJsonCacheFilePath: ${L},error ${e.message}`)}const M=c["mini-plugin"];return M&&Array.isArray(M.ios)&&M.ios.forEach(e=>{!0===e.open&&e.resourcePath&&d(`mini-plugin ios ${e.pluginId}:${e.resourcePath}`,e.resourcePath)}),{projectMiniappJson:_,projectConfigJson:m,appJson:b,privacyJson:P,privacyContentViewImage:I,privacyCancelButtonImage:x,privacyConfirmButtonImage:j,icons:E,splashScreen:O,p12:$,profile:T,tpnsProfile:k,i18nJson:F}}async codesignIOSApp(e,i){const{projectPath:t,demoIpaPath:n,opts:o}=e,s=await(0,codesign_1.codesignAndExport)(t,n,e.miniappCacheDir||"",o,i,e.isUsingTpush,!1,!0);if(!0!==s.success)throw new Error("Build ipa failed:"+(s.errMsg||"codesignAndExport failed"))}async packIOSCloudBuildMaterial(e,i){i.progress("start uploadProjectAllMaterial");const{projectPath:t,matrialDistPath:n,theme:o}=e;await this.genProjectMaterialMap(t,n,e,i);i.progress("packIOSCloudBuildMaterial done")}launchSimulator(e,i){let t;try{t=JSON.parse(child_process.execFileSync("xcrun",["simctl","list","--json","devices"],{encoding:"utf8",env:(0,env_1.getProcessEnv)()}))}catch(e){throw new Error("Could not get the simulator list from Xcode. Please open Xcode and try running project directly from there to resolve the remaining issues."+e.message)}const n=["iPhone 13","iPhone 12","iPhone 11"].reduce((e,i)=>e||deviceUtils.findMatchingSimulator(t,{device:i}),deviceUtils.findMatchingSimulator(t,e));if(!n)throw new Error("No simulator available with "+(e.device?`name "${e.device}"`:`udid "${e.udid}"`));const o=child_process.execFileSync("xcode-select",["-p"],{encoding:"utf8",env:(0,env_1.getProcessEnv)()}).trim();if(child_process.execFileSync("open",[o+"/Applications/Simulator.app","--args","-CurrentDeviceUDID",n.udid],{env:(0,env_1.getProcessEnv)()}),!n.booted){const e=deviceUtils.formattedDeviceName(n);i.progress("Launching "+e),child_process.spawnSync("xcrun",["simctl","boot",n.udid],{env:(0,env_1.getProcessEnv)()})}return n}async runOnSimulatorCloud(e,i,t){const{udid:n}=i,o=this.launchSimulator({udid:n},t);await this.installAppOnSimulator(o,e,t),await this.launchAppOnSimulator(o,e,t)}async runOnSimulatorLocal(e,i,t,n){const o=this.launchSimulator(t,n),{appPath:s}=await this.buildProjectApp(e,{udid:o.udid,scheme:i},n);await this.installAppOnSimulator(o,s,n),await this.launchAppOnSimulator(o,s,n)}async runOnDeviceLocal(e,i,t,n){const{appPath:o}=await this.buildProjectApp(e,{udid:t.udid,scheme:i},n);if("catalyst"===t.type){child_process.spawn(`${o}/${i}`,[],{detached:!0,stdio:"ignore",env:(0,env_1.getProcessEnv)()}).unref()}else{const e=["--bundle",o,"--id",t.udid,"--justlaunch"];n.progress("Installing and launching your app on "+t.name);const i=path_1.default.join(__dirname,"../../../vendor/ios-deploy/ios-deploy");await(0,cp_1.spawnSync)(i,e,{},n)}return n.progress("Install successfully the app to the device.")}buildProjectApp(e,i,t){return new Promise((n,o)=>{const{scheme:s,udid:a}=i,r=[e.isWorkspace?"-workspace":"-project",e.name,"-scheme",s];let c;a&&r.push("-destination","id="+a),t.progress(`Building (using "xcodebuild ${r.join(" ")}")`),this.xcbeautifyAvailable()?c=child_process.spawn("xcbeautify",[],{stdio:["pipe",process.stdout,process.stderr],env:(0,env_1.getProcessEnv)()}):this.xcprettyAvailable()&&(c=child_process.spawn("xcpretty",[],{stdio:["pipe",process.stdout,process.stderr],env:(0,env_1.getProcessEnv)()}));const l=child_process.spawn("xcodebuild",r,{env:(0,env_1.getProcessEnv)()});let d="",p="";l.stdout.on("data",e=>{const i=e.toString();t.progress(i),d+=i,c&&c.stdin.write(e)}),l.stderr.on("data",e=>{const i=e.toString();p+=i,t.progress(i)}),l.on("close",i=>{if(c&&c.stdin.end(),0!==i)return void o(new Error(` Failed to build iOS project.\n We ran "xcodebuild" command but it exited with error code ${i}. To debug build\n logs further, consider building your app with Xcode.app, by opening\n ${e.name}.\n ${c?void 0:`${d}\n${p}`}\n `));let a;try{a=this.getBuildInfo(e,d,s)}catch(e){o(e)}t.progress("Successfully built the app"),n(a)})})}async installAppOnSimulator(e,i,t){const n=["simctl","install",e.udid,i];await(0,cp_1.spawnSync)("xcrun",n,{},t)}async launchAppOnSimulator(e,i,t){const n=this.getBundleId(i),o=["simctl","launch",e.udid,n];await(0,cp_1.spawnSync)("xcrun",o,{},t),t.progress("Successfully launched the app on the simulator")}async buildProjectArchive(e,i,t){const{output:n,scheme:o,udid:s}=i,a=path_1.default.join(n,"./app"),{sourceDir:r}=e;fs_extra_1.default.ensureDirSync(path_1.default.dirname(a));const c=["archive",e.isWorkspace?"-workspace":"-project",e.name,"-scheme",o,"-archivePath",a];s&&c.push("-destination","id="+s);try{if(await(0,cp_1.spawnSync)("xcodebuild",c,{cwd:r},t),!fs_extra_1.default.existsSync(a+".xcarchive"))throw new Error(`Failed to build iOS project.\n ${a+".xcarchive"} does not found\n `);return t.progress(`Successfully archive the app: ${a}.xcarchive`),a+".xcarchive"}catch(i){throw new Error(`Failed to build iOS project. To debug build\n logs further, consider building your app with Xcode.app, by opening\n ${e.name}.\n `)}}async exportArchive(e,i,t,n){const o=path_1.default.join(t.output,"ipa");fs_extra_1.default.ensureDirSync(o),fs_extra_1.default.emptyDirSync(o);const{exportOptionPlistPath:s}=t;if(!s)throw new Error("build ios ipa require exportOptionPlistPath in project.miniapp.json");let a="";a=path_1.default.isAbsolute(s)?s:path_1.default.join(t.projectPath,s);const r=["-exportArchive","-archivePath",i,"-exportOptionsPlist",a,"-exportPath",o];try{await(0,cp_1.spawnSync)("xcodebuild",r,{cwd:e.sourceDir},n)}catch(i){throw new Error(`To debug build\n logs further, consider building your app with Xcode.app, by opening\n ${e.name}.\n `)}return fs_extra_1.default.removeSync(i),o}getTargetPaths(e){const i=JSON.parse(e);for(const e in i){if("app"===i[e].buildSettings.WRAPPER_EXTENSION)return{targetBuildDir:i[e].buildSettings.TARGET_BUILD_DIR,executableFolderPath:i[e].buildSettings.EXECUTABLE_FOLDER_PATH}}return{}}getBuildInfo(e,i,t){const n=this.getPlatformName(i),o=[e.isWorkspace?"-workspace":"-project",e.name,"-scheme",t,"-sdk",n,"-showBuildSettings","-json"].join(" "),s=child_process.execSync("xcodebuild "+o,{encoding:"utf8",cwd:e.sourceDir,env:(0,env_1.getProcessEnv)()}),a=this.getBuildProductDir(i),{executableFolderPath:r}=this.getTargetPaths(s);if(!r)throw new Error("Failed to get the app name.");return{sdk:n,appPath:`${a}/${r}`}}getPlatformName(e){const i=/export PLATFORM_NAME\\?="?(\w+)"?$/m.exec(e);if(!i)throw new Error("Couldn't find PLATFORM_NAME in xcodebuild output.");return i[1]}getBuildProductDir(e){const i=/export BUILT_PRODUCTS_DIR\\?="?(.+)"?$/m.exec(e);if(!i)throw new Error("Couldn't find BUILT_PRODUCTS_DIR in xcodebuild output.");return i[1]}xcbeautifyAvailable(){try{child_process.execSync("xcbeautify --version",{stdio:[0,"pipe","ignore"],env:(0,env_1.getProcessEnv)()})}catch(e){return!1}return!0}xcprettyAvailable(){try{child_process.execSync("xcpretty --version",{stdio:[0,"pipe","ignore"],env:(0,env_1.getProcessEnv)()})}catch(e){return!1}return!0}async buildPlugin(e,i){const{pluginId:t,projectPath:n,buildShellPath:o}=e;i.progress("start build native plugin...");try{const e=[n,t];fs_extra_1.default.chmodSync(o,"777"),buildIOSPluginTask[t]?(i.message("fail","存在未结束的插件构建任务,需等待构建结束..."),await buildIOSPluginTask[t].getResult(!0)):(buildIOSPluginTask[t]=new singletontask_1.SingletonTask(cp_1.spawnSyncExecShell.bind(null,o,e,{},i)),await buildIOSPluginTask[t].getResult(!0),buildIOSPluginTask[t]=void 0)}catch(e){throw buildIOSPluginTask[t]=void 0,new Error("build plugin failed: "+e)}}async writeI18NInfoFile(e,i,t){Object.keys(i).forEach(n=>{if("base"===n)return;let o="";Object.keys(t).forEach(e=>{var s,a,r,c;(null===(a=null===(s=i[n])||void 0===s?void 0:s.ios)||void 0===a?void 0:a[t[e]])&&(o+=`${e} = "${null===(c=null===(r=i[n])||void 0===r?void 0:r.ios)||void 0===c?void 0:c[t[e]]}";\n`)}),o&&(fs_extra_1.default.ensureDirSync(path_1.default.join(e,n+".lproj")),fs_extra_1.default.writeFileSync(path_1.default.join(e,n+".lproj/InfoPlist.strings"),o))})}}exports.IOSUtils=IOSUtils;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.IOSUtils=void 0;const tslib_1=require("tslib"),child_process=tslib_1.__importStar(require("child_process")),path_1=tslib_1.__importDefault(require("path")),fs_extra_1=tslib_1.__importDefault(require("fs-extra")),env_1=require("../../../utils/env"),deviceUtils=tslib_1.__importStar(require("./device")),projectConfigUtils=tslib_1.__importStar(require("./projectconfig")),cp_1=require("../../../utils/cp"),miniapp_builder_1=require("../../../utils/miniapp-builder"),usbProcess_1=require("../../../utils/usbProcess"),miniappJson_1=require("../../../utils/miniappJson"),singletontask_1=require("../../../utils/singletontask"),buildCloud_1=tslib_1.__importStar(require("./buildCloud")),tools_1=require("../../../utils/tools"),codesign_1=require("../../../utils/codesign"),ProjectMiniappJsonSplashScreenThemeKey="__splashscreenTheme",_iconInfoMap={appStore1024:{size:[1024,1024],scale:1,idiom:"ios-marketing",required:!0},mainIcon120:{size:[60,60],scale:2,idiom:"iphone",required:!0},mainIcon180:{size:[60,60],scale:3,idiom:"iphone"},spotlightIcon80:{size:[40,40],scale:2,idiom:"iphone"},spotlightIcon120:{size:[40,40],scale:3,idiom:"iphone"},settingsIcon58:{size:[29,29],scale:2,idiom:"iphone"},settingsIcon87:{size:[29,29],scale:3,idiom:"iphone"},notificationIcon40:{size:[20,20],scale:2,idiom:"iphone"},notificationIcon60:{size:[20,20],scale:3,idiom:"iphone"},ipadMainIcon152:{size:[76,76],scale:2,idiom:"ipad"},ipadMainIcon167:{size:[83.5,83.5],scale:2,idiom:"ipad"},ipadSpotlightIcon40:{size:[40,40],scale:1,idiom:"ipad"},ipadSpotlightIcon80:{size:[40,40],scale:2,idiom:"ipad"},ipadSettingsIcon29:{size:[29,29],scale:1,idiom:"ipad"},ipadSpotlightIcon58:{size:[29,29],scale:2,idiom:"ipad"},ipadNotificationIcon20:{size:[20,20],scale:1,idiom:"ipad"},ipadNotificationIcon40:{size:[20,20],scale:2,idiom:"ipad"}},_allowTheme=["Light","LightSpecial","Dark","DarkSpecial","Default"],_getDepReg=e=>new RegExp(`s.subspec '${e}'.*\n(?:.*\n)*?(?:.*sp.vendored_frameworks = \\[\n)((?:.*'.*?'.*\n)*?)(?:.*\\]\n)`,"m"),buildIOSPluginTask={};class IOSUtils{constructor(e,i={},t,o){this.root=e,this.userConfig=i,this.miniappDirPath=t,this.devtoolsVersion=o}getProjectConfig(){const e=projectConfigUtils.getProjectConfig(this.root,this.userConfig);if(!e)throw new Error("iOS project folder not found. Are you sure this is a miniapp project?");return e}getBundleId(e){return child_process.execFileSync("/usr/libexec/PlistBuddy",["-c","Print:CFBundleIdentifier",path_1.default.join(e,"Info.plist")],{encoding:"utf8",env:(0,env_1.getProcessEnv)()}).trim()}tryInstallPod(e,i){const t=this.getProjectConfig(),{sourceDir:o}=t,n={cwd:o,env:(0,env_1.getProcessEnv)()};i.progress("export LANG=en_US.UTF-8 && pod install"),child_process.execSync("export LANG=en_US.UTF-8 && pod install",n)}async runLocal(e,i){const t=this.getProjectConfig(),{sourceDir:o}=t;process.chdir(o),this.tryInstallPod(e,i);const n=path_1.default.basename(t.name,path_1.default.extname(t.name)),s=e.scheme||n;if(i.progress(`Found Xcode ${t.isWorkspace?"workspace":"project"} "${t.name}"`),e.device||e.udid){if(e.udid||e.device){const o=await deviceUtils.getDevices({recorder:i}),n=o.find(i=>i.udid===e.udid||i.name===e.device);if(!n)throw new Error(`Could not find a device with udid(${e.udid}) or device(${e.device}). ${deviceUtils.printFoundDevices(o)}`);if("simulator"===n.type)return void await this.runOnSimulatorLocal(t,s,e,i);await this.runOnDeviceLocal(t,s,n,i)}}else await this.runOnSimulatorLocal(t,s,e,i)}async runCloud(e,i){try{const{deviceType:t,udid:o,projectPath:n,demoIpaPath:s,sdkPath:r,bindingInfo:a,certificateInfo:c,arch:l="arm64",pluginDirList:d,miniappCacheDirPath:u,theme:p,i18nInfo:h,debugInfo:f}=e,_=buildCloud_1.default.generateTempDemoIpaPath(s),m="simulator"===t,g=(0,miniappJson_1.tryGetIOSMiniappJson)(n);let b=a;if(c.signType===miniapp_builder_1.miniappSinTypes.appleId.type){const{mobileapp_info:e={}}=b;b=Object.assign(Object.assign({},b),{mobileapp_info:Object.assign(Object.assign({},e),{bundle_id:miniapp_builder_1.DEFAULT_BUNDLE_ID,debug_ios_bundle_id:miniapp_builder_1.DEFAULT_BUNDLE_ID})})}const v=await buildCloud_1.default.updateIOSInfoPlistInfo(n,b,_,g,i,h);await buildCloud_1.default.updateIOSAppConfigPlistInfo(n,b,_,g,r,m,i,p,h),await buildCloud_1.default.updateIOSAppexInfoPlistInfo(b,_,g,v,i),await buildCloud_1.default.updateIOSIcons(n,_,"",g,!1,i),await buildCloud_1.default.updateSplashScreen(n,_,g,i,p,h),await buildCloud_1.default.updateExtendedSdk(b,_,r,l,g,f,i),await buildCloud_1.default.updatePlugin(_,d,n,g,u,!1,v,i);const y=await buildCloud_1.default.getEntitlements(b,_,g,i);if("device"===t){const{mobileapp_info:e={}}=b,t=e.ios_flag&&e.bundle_id||e.debug_ios_bundle_id;await(0,miniapp_builder_1.signAndInstallOrExport)(n,_,u,c,{bundleId:t,install:!0,deviceId:o,entitlements:y},{recorder:i,miniappDirPath:this.miniappDirPath,devtoolsVersion:this.devtoolsVersion})}else await this.runOnSimulatorCloud(_,{udid:o},i)}catch(e){throw new Error(e.message)}}async buildLocal(e,i){const t=this.getProjectConfig();process.chdir(t.sourceDir);const o=path_1.default.basename(t.name,path_1.default.extname(t.name)),n=e.scheme||o;this.tryInstallPod(e,i),i.progress("start build ipa...");const s=await this.buildProjectArchive(t,{output:e.output,scheme:n},i),r=await this.exportArchive(t,s,e,i);return console.log("Successfully build ipa: "+r),r}async buildCloud(e,i){try{const{projectPath:t,certificateInfo:o,miniappCacheDirPath:n}=e,s=await buildCloud_1.default.buildCloud(e,i),{demoIpaPath:r,opts:a}=s,c={recorder:i,miniappDirPath:this.miniappDirPath,devtoolsVersion:this.devtoolsVersion};s.isPublish||await(0,miniapp_builder_1.signAndInstallOrExport)(t,r,n,o,a,c)}catch(e){throw new Error(e.message)}}async genProjectMaterialMap(e,i,t,o){var n,s;const r=buildCloud_1.remoteBuildProjectMaterialAbsoluteCacheDir,a=path_1.default.join(i,r),c=(0,miniappJson_1.tryGetIOSMiniappJson)(e);function l(e,i){fs_extra_1.default.ensureDirSync(path_1.default.dirname(i)),fs_extra_1.default.copyFileSync(e,i)}function d(t,o,n=!0){if(!o){if(n)return"";throw new Error(`file cant be empty for cloud build, key: ${t} , fileName: ${o}`)}if(path_1.default.isAbsolute(o)){const e=path_1.default.basename(o);if(!fs_extra_1.default.existsSync(o)){if(n)return"";throw new Error(`file cant be empty for cloud build, key: ${t} , fileName: ${o}`)}const i=(0,tools_1.generateMD5)(o);return l(o,path_1.default.join(a,`${i}_${e}`)),path_1.default.join(r,e)}const s=path_1.default.join(e,o),c=path_1.default.join(i,o);if(!fs_extra_1.default.existsSync(s)){if(n)return"";throw new Error(`file cant be empty for cloud build, key: ${t} , fileName: ${o}`)}return l(s,c),o}fs_extra_1.default.ensureDirSync(a);const{privacy:u={},icons:p={},splashscreen:h={},buildCloud:f={}}=c,_=d("project.miniapp.json","project.miniapp.json",!1),m=d("project.config.json","project.config.json",!1),g=(0,miniappJson_1.getMiniprogramRoot)(e),b=d("app.json",path_1.default.join(g,"app.json"),!1),{template:v,contentViewImage:y,cancelButtonImage:S,confirmButtonImage:P}=u,w=d("privacy template",v),I=d("privacy contentViewImage",y),x=d("privacy cancelButtonImage",S),j=d("privacy confirmButtonImage",P),E=[];for(const e in p)if(p[e]){const i=d("icons."+e,p[e],!1);i&&E.push(i)}const O=d("splashscreen.customImage",h.customImage),{p12:D,profile:C,tpnsProfile:A}=f,$=d("p12 Path",D,!1),T=d("profile Path",C,!1);let k=void 0;!0===(null===(n=null==c?void 0:c.tpush)||void 0===n?void 0:n.useExtendedLib_WeAppTPNS)&&(k=d("tpns profile Path",A,!0!==(null===(s=null==c?void 0:c.tpush)||void 0===s?void 0:s.useExtendedLib_WeAppTPNS)));const U="miniapp/ios/i18nInfo.json",B=path_1.default.join(e,U),F=d("i18n",U,!0);if(fs_extra_1.default.existsSync(B)){const i=function(e,i){function t(i,t,o){if(t[o]&&"object"==typeof t[o][i])for(const n in t[o][i])if("object"==typeof t[o][i]){const s=t[o][i][n];if("string"==typeof s&&s.length>0){fs_extra_1.default.existsSync(path_1.default.isAbsolute(s)?s:path_1.default.join(e,s))&&d(`i18nFiles.${o}.${n}`,s,!0)}}}try{const o=fs_extra_1.default.readJSONSync(path_1.default.join(e,i));for(const e in o)t("ios",o,e),t("android",o,e)}catch(e){return e.message}}(e,U);if(i)throw o.message("error",i),new Error("copyi18NFiles error "+i)}const M=path_1.default.join(i,"project.miniapp.json");try{const e=fs_extra_1.default.readJsonSync(M);let{theme:i}=t;t.theme||(i="Dark"),e.__splashscreenTheme=i,fs_extra_1.default.writeJSONSync(M,e)}catch(e){throw new Error(`ReadWriteJsonFailed projectMiniappJsonCacheFilePath: ${M},error ${e.message}`)}const L=c["mini-plugin"];return L&&Array.isArray(L.ios)&&L.ios.forEach(e=>{!0===e.open&&e.resourcePath&&d(`mini-plugin ios ${e.pluginId}:${e.resourcePath}`,e.resourcePath)}),{projectMiniappJson:_,projectConfigJson:m,appJson:b,privacyJson:w,privacyContentViewImage:I,privacyCancelButtonImage:x,privacyConfirmButtonImage:j,icons:E,splashScreen:O,p12:$,profile:T,tpnsProfile:k,i18nJson:F}}async codesignIOSApp(e,i){const{projectPath:t,demoIpaPath:o,opts:n}=e,s=await(0,codesign_1.codesignAndExport)(t,o,e.miniappCacheDir||"",n,i,e.isUsingTpush,!1,!0);if(!0!==s.success)throw new Error("Build ipa failed:"+(s.errMsg||"codesignAndExport failed"))}async packIOSCloudBuildMaterial(e,i){i.progress("start uploadProjectAllMaterial");const{projectPath:t,matrialDistPath:o,theme:n}=e;await this.genProjectMaterialMap(t,o,e,i);i.progress("packIOSCloudBuildMaterial done")}async initUSBConnectionProcess(e,i){await(0,usbProcess_1.startUSBManagerProcess)(e,i)&&i.progress("Init USB Process Successfully")}launchSimulator(e,i){let t;try{t=JSON.parse(child_process.execFileSync("xcrun",["simctl","list","--json","devices"],{encoding:"utf8",env:(0,env_1.getProcessEnv)()}))}catch(e){throw new Error("Could not get the simulator list from Xcode. Please open Xcode and try running project directly from there to resolve the remaining issues."+e.message)}const o=["iPhone 13","iPhone 12","iPhone 11"].reduce((e,i)=>e||deviceUtils.findMatchingSimulator(t,{device:i}),deviceUtils.findMatchingSimulator(t,e));if(!o)throw new Error("No simulator available with "+(e.device?`name "${e.device}"`:`udid "${e.udid}"`));const n=child_process.execFileSync("xcode-select",["-p"],{encoding:"utf8",env:(0,env_1.getProcessEnv)()}).trim();if(child_process.execFileSync("open",[n+"/Applications/Simulator.app","--args","-CurrentDeviceUDID",o.udid],{env:(0,env_1.getProcessEnv)()}),!o.booted){const e=deviceUtils.formattedDeviceName(o);i.progress("Launching "+e),child_process.spawnSync("xcrun",["simctl","boot",o.udid],{env:(0,env_1.getProcessEnv)()})}return o}async runOnSimulatorCloud(e,i,t){const{udid:o}=i,n=this.launchSimulator({udid:o},t);await this.installAppOnSimulator(n,e,t),await this.launchAppOnSimulator(n,e,t)}async runOnSimulatorLocal(e,i,t,o){const n=this.launchSimulator(t,o),{appPath:s}=await this.buildProjectApp(e,{udid:n.udid,scheme:i},o);await this.installAppOnSimulator(n,s,o),await this.launchAppOnSimulator(n,s,o)}async runOnDeviceLocal(e,i,t,o){const{appPath:n}=await this.buildProjectApp(e,{udid:t.udid,scheme:i},o);if("catalyst"===t.type){child_process.spawn(`${n}/${i}`,[],{detached:!0,stdio:"ignore",env:(0,env_1.getProcessEnv)()}).unref()}else{const e=["--bundle",n,"--id",t.udid,"--justlaunch"];o.progress("Installing and launching your app on "+t.name);const i=path_1.default.join(__dirname,"../../../vendor/ios-deploy/ios-deploy");await(0,cp_1.spawnSync)(i,e,{},o)}return o.progress("Install successfully the app to the device.")}buildProjectApp(e,i,t){return new Promise((o,n)=>{const{scheme:s,udid:r}=i,a=[e.isWorkspace?"-workspace":"-project",e.name,"-scheme",s];let c;r&&a.push("-destination","id="+r),t.progress(`Building (using "xcodebuild ${a.join(" ")}")`),this.xcbeautifyAvailable()?c=child_process.spawn("xcbeautify",[],{stdio:["pipe",process.stdout,process.stderr],env:(0,env_1.getProcessEnv)()}):this.xcprettyAvailable()&&(c=child_process.spawn("xcpretty",[],{stdio:["pipe",process.stdout,process.stderr],env:(0,env_1.getProcessEnv)()}));const l=child_process.spawn("xcodebuild",a,{env:(0,env_1.getProcessEnv)()});let d="",u="";l.stdout.on("data",e=>{const i=e.toString();t.progress(i),d+=i,c&&c.stdin.write(e)}),l.stderr.on("data",e=>{const i=e.toString();u+=i,t.progress(i)}),l.on("close",i=>{if(c&&c.stdin.end(),0!==i)return void n(new Error(` Failed to build iOS project.\n We ran "xcodebuild" command but it exited with error code ${i}. To debug build\n logs further, consider building your app with Xcode.app, by opening\n ${e.name}.\n ${c?void 0:`${d}\n${u}`}\n `));let r;try{r=this.getBuildInfo(e,d,s)}catch(e){n(e)}t.progress("Successfully built the app"),o(r)})})}async installAppOnSimulator(e,i,t){const o=["simctl","install",e.udid,i];await(0,cp_1.spawnSync)("xcrun",o,{},t)}async launchAppOnSimulator(e,i,t){const o=this.getBundleId(i),n=["simctl","launch",e.udid,o];await(0,cp_1.spawnSync)("xcrun",n,{},t),t.progress("Successfully launched the app on the simulator")}async buildProjectArchive(e,i,t){const{output:o,scheme:n,udid:s}=i,r=path_1.default.join(o,"./app"),{sourceDir:a}=e;fs_extra_1.default.ensureDirSync(path_1.default.dirname(r));const c=["archive",e.isWorkspace?"-workspace":"-project",e.name,"-scheme",n,"-archivePath",r];s&&c.push("-destination","id="+s);try{if(await(0,cp_1.spawnSync)("xcodebuild",c,{cwd:a},t),!fs_extra_1.default.existsSync(r+".xcarchive"))throw new Error(`Failed to build iOS project.\n ${r+".xcarchive"} does not found\n `);return t.progress(`Successfully archive the app: ${r}.xcarchive`),r+".xcarchive"}catch(i){throw new Error(`Failed to build iOS project. To debug build\n logs further, consider building your app with Xcode.app, by opening\n ${e.name}.\n `)}}async exportArchive(e,i,t,o){const n=path_1.default.join(t.output,"ipa");fs_extra_1.default.ensureDirSync(n),fs_extra_1.default.emptyDirSync(n);const{exportOptionPlistPath:s}=t;if(!s)throw new Error("build ios ipa require exportOptionPlistPath in project.miniapp.json");let r="";r=path_1.default.isAbsolute(s)?s:path_1.default.join(t.projectPath,s);const a=["-exportArchive","-archivePath",i,"-exportOptionsPlist",r,"-exportPath",n];try{await(0,cp_1.spawnSync)("xcodebuild",a,{cwd:e.sourceDir},o)}catch(i){throw new Error(`To debug build\n logs further, consider building your app with Xcode.app, by opening\n ${e.name}.\n `)}return fs_extra_1.default.removeSync(i),n}getTargetPaths(e){const i=JSON.parse(e);for(const e in i){if("app"===i[e].buildSettings.WRAPPER_EXTENSION)return{targetBuildDir:i[e].buildSettings.TARGET_BUILD_DIR,executableFolderPath:i[e].buildSettings.EXECUTABLE_FOLDER_PATH}}return{}}getBuildInfo(e,i,t){const o=this.getPlatformName(i),n=[e.isWorkspace?"-workspace":"-project",e.name,"-scheme",t,"-sdk",o,"-showBuildSettings","-json"].join(" "),s=child_process.execSync("xcodebuild "+n,{encoding:"utf8",cwd:e.sourceDir,env:(0,env_1.getProcessEnv)()}),r=this.getBuildProductDir(i),{executableFolderPath:a}=this.getTargetPaths(s);if(!a)throw new Error("Failed to get the app name.");return{sdk:o,appPath:`${r}/${a}`}}getPlatformName(e){const i=/export PLATFORM_NAME\\?="?(\w+)"?$/m.exec(e);if(!i)throw new Error("Couldn't find PLATFORM_NAME in xcodebuild output.");return i[1]}getBuildProductDir(e){const i=/export BUILT_PRODUCTS_DIR\\?="?(.+)"?$/m.exec(e);if(!i)throw new Error("Couldn't find BUILT_PRODUCTS_DIR in xcodebuild output.");return i[1]}xcbeautifyAvailable(){try{child_process.execSync("xcbeautify --version",{stdio:[0,"pipe","ignore"],env:(0,env_1.getProcessEnv)()})}catch(e){return!1}return!0}xcprettyAvailable(){try{child_process.execSync("xcpretty --version",{stdio:[0,"pipe","ignore"],env:(0,env_1.getProcessEnv)()})}catch(e){return!1}return!0}async buildPlugin(e,i){const{pluginId:t,projectPath:o,buildShellPath:n}=e;i.progress("start build native plugin...");try{const e=[o,t];fs_extra_1.default.chmodSync(n,"777"),buildIOSPluginTask[t]?(i.message("error","存在未结束的插件构建任务,需等待构建结束..."),await buildIOSPluginTask[t].getResult(!0)):(buildIOSPluginTask[t]=new singletontask_1.SingletonTask(cp_1.spawnSyncExecShell.bind(null,n,e,{},i)),await buildIOSPluginTask[t].getResult(!0),buildIOSPluginTask[t]=void 0)}catch(e){throw buildIOSPluginTask[t]=void 0,new Error("build plugin failed: "+e)}}async writeI18NInfoFile(e,i,t){Object.keys(i).forEach(o=>{if("base"===o)return;let n="";Object.keys(t).forEach(e=>{var s,r,a,c;(null===(r=null===(s=i[o])||void 0===s?void 0:s.ios)||void 0===r?void 0:r[t[e]])&&(n+=`${e} = "${null===(c=null===(a=i[o])||void 0===a?void 0:a.ios)||void 0===c?void 0:c[t[e]]}";\n`)}),n&&(fs_extra_1.default.ensureDirSync(path_1.default.join(e,o+".lproj")),fs_extra_1.default.writeFileSync(path_1.default.join(e,o+".lproj/InfoPlist.strings"),n))})}}exports.IOSUtils=IOSUtils;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.NativeCompiler=void 0;const define_1=require("../../config/define"),miniappJson_1=require("../../utils/miniappJson"),android_1=require("./android"),ios_1=require("./ios");class NativeCompiler{constructor(t){this.projectPath=t.projectInfo.projectPath,this.miniappDirPath=t.miniappDirPath,this.devtoolsVersion=t.devtoolsVersion}getHandler(t){let i=null;const e=(0,miniappJson_1.getMiniappJson)(this.projectPath,t);return t===define_1.PLATFORM["mini-android"]?i=new android_1.AndroidUtils(e.projectPath,e.project,this.miniappDirPath,this.devtoolsVersion):t===define_1.PLATFORM["mini-ios"]&&(i=new ios_1.IOSUtils(e.projectPath,e.project,this.miniappDirPath,this.devtoolsVersion)),i}validNativePlatform(t){return t===define_1.PLATFORM["mini-android"]||t===define_1.PLATFORM["mini-ios"]}async getAndroidDevices(){const t=this.getHandler(define_1.PLATFORM["mini-android"]);return await t.getDevices()}async getIOSDevices(){const t=this.getHandler(define_1.PLATFORM["mini-ios"]);return await t.getDevices()}async run(t,i){const{targetPlatform:e,opts:a}=t;if(!this.validNativePlatform(e))return;const r=(0,miniappJson_1.getMiniappJson)(this.projectPath,e),s=this.getHandler(e);let n={};const{buildType:o="LOCAL"}=a;return"LOCAL"===o?(n=r.runArgs||{},await s.runLocal(Object.assign(Object.assign({projectPath:this.projectPath},n),a),i)):await s.runCloud(Object.assign({projectPath:this.projectPath},a),i)}async build(t,i){const{targetPlatform:e,opts:a={}}=t;if(!this.validNativePlatform(e))return;const r=this.getHandler(e),s=(0,miniappJson_1.getMiniappJson)(this.projectPath,e);let n={};const{buildType:o="LOCAL"}=a;return"LOCAL"===o?(n=s.buildArgs||{},await r.buildLocal(Object.assign(Object.assign({projectPath:this.projectPath},n),a),i)):await r.buildCloud(Object.assign({projectPath:this.projectPath},a),i)}async buildPlugin(t,i){const{targetPlatform:e,opts:a={}}=t;if(!this.validNativePlatform(e))return;const r=this.getHandler(e);return await r.buildPlugin(Object.assign({projectPath:this.projectPath},a),i)}async packIOSCloudBuildMaterial(t,i){const{targetPlatform:e,opts:a={}}=t;if(!this.validNativePlatform(e))return;const r=this.getHandler(e);return await r.packIOSCloudBuildMaterial(Object.assign({projectPath:this.projectPath},a),i)}async codesignIOSApp(t,i){const{targetPlatform:e,opts:a={}}=t;if(!this.validNativePlatform(e))return;const r=this.getHandler(e);return await r.codesignIOSApp(Object.assign({projectPath:this.projectPath},a),i)}}exports.NativeCompiler=NativeCompiler;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.NativeCompiler=void 0;const define_1=require("../../config/define"),miniappJson_1=require("../../utils/miniappJson"),android_1=require("./android"),ios_1=require("./ios");class NativeCompiler{constructor(t){this.projectPath=t.projectInfo.projectPath,this.miniappDirPath=t.miniappDirPath,this.devtoolsVersion=t.devtoolsVersion}getHandler(t){let i=null;const e=(0,miniappJson_1.getMiniappJson)(this.projectPath,t);return t===define_1.PLATFORM["mini-android"]?i=new android_1.AndroidUtils(e.projectPath,e.project,this.miniappDirPath,this.devtoolsVersion):t===define_1.PLATFORM["mini-ios"]&&(i=new ios_1.IOSUtils(e.projectPath,e.project,this.miniappDirPath,this.devtoolsVersion)),i}validNativePlatform(t){return t===define_1.PLATFORM["mini-android"]||t===define_1.PLATFORM["mini-ios"]}async getAndroidDevices(){const t=this.getHandler(define_1.PLATFORM["mini-android"]);return await t.getDevices()}async getIOSDevices(){const t=this.getHandler(define_1.PLATFORM["mini-ios"]);return await t.getDevices()}async run(t,i){const{targetPlatform:e,opts:a}=t;if(!this.validNativePlatform(e))return;const r=(0,miniappJson_1.getMiniappJson)(this.projectPath,e),n=this.getHandler(e);let s={};const{buildType:o="LOCAL"}=a;return"LOCAL"===o?(s=r.runArgs||{},await n.runLocal(Object.assign(Object.assign({projectPath:this.projectPath},s),a),i)):await n.runCloud(Object.assign({projectPath:this.projectPath},a),i)}async build(t,i){const{targetPlatform:e,opts:a={}}=t;if(!this.validNativePlatform(e))return;const r=this.getHandler(e),n=(0,miniappJson_1.getMiniappJson)(this.projectPath,e);let s={};const{buildType:o="LOCAL"}=a;return"LOCAL"===o?(s=n.buildArgs||{},await r.buildLocal(Object.assign(Object.assign({projectPath:this.projectPath},s),a),i)):await r.buildCloud(Object.assign({projectPath:this.projectPath},a),i)}async buildPlugin(t,i){const{targetPlatform:e,opts:a={}}=t;if(!this.validNativePlatform(e))return;const r=this.getHandler(e);return await r.buildPlugin(Object.assign({projectPath:this.projectPath},a),i)}async packIOSCloudBuildMaterial(t,i){const{targetPlatform:e,opts:a={}}=t;if(!this.validNativePlatform(e))return;const r=this.getHandler(e);return await r.packIOSCloudBuildMaterial(Object.assign({projectPath:this.projectPath},a),i)}async initUSBConnectionProcess(t,i){const{targetPlatform:e}=t;if(!this.validNativePlatform(e))return;const a=this.getHandler(e);return await a.initUSBConnectionProcess({miniappDirPath:a.miniappDirPath,devtoolsVersion:a.devtoolsVersion},i)}async codesignIOSApp(t,i){const{targetPlatform:e,opts:a={}}=t;if(!this.validNativePlatform(e))return;const r=this.getHandler(e);return await r.codesignIOSApp(Object.assign({projectPath:this.projectPath},a),i)}}exports.NativeCompiler=NativeCompiler;
@@ -1 +1 @@
1
- var _a,_b;process.env&&process.env.isDevtools&&require("../../utils/hackrequire/index"),Object.defineProperty(exports,"__esModule",{value:!0}),(null===(_a=process.env)||void 0===_a?void 0:_a.isDevtools)&&require("../../utils/hackrequire/index");const entryProcess_1=require("../../utils/subprocess/entryProcess"),progressRecorder_1=require("../../utils/progressRecorder"),nativeCompiler_1=require("./nativeCompiler");let nativeCompiler;async function initHandler(e){const{projectInfo:i,passData:r}=e.data,{miniappDirPath:a,devtoolsVersion:s}=r;nativeCompiler=new nativeCompiler_1.NativeCompiler({projectInfo:i,miniappDirPath:a,devtoolsVersion:s})}async function messageHandler(e){if(e.type,"request"===e.type){const{id:i,name:r,data:a}=e,s=i,n=new progressRecorder_1.Recorder((e,i,r)=>{process.send({type:"progress",id:e,taskId:s,status:i,message:r})});a.fullEnv&&(global.fullEnv=a.fullEnv);try{let e;const t=`${r}-${s}`;if("buildNative"===r)e=await n.run(t,async()=>await nativeCompiler.build(a,n));else if("runNative"===r)e=await n.run(t,async()=>await nativeCompiler.run(a,n));else if("buildNativePlugin"===r)e=await n.run(t,async()=>await nativeCompiler.buildPlugin(a,n));else if("packIOSCloudBuildMaterial"===r)e=await n.run(t,async()=>await nativeCompiler.packIOSCloudBuildMaterial(a,n));else{if("codesignIOSApp"!==r)throw new Error("unknown command "+r);e=await n.run(t,async()=>await nativeCompiler.codesignIOSApp(a,n))}process.send({type:"response",id:i,data:e})}catch(e){process.send({type:"response",id:i,data:null,error:{code:e.code||-1,message:e.message,stack:e.stack,path:e.path||""}})}}}(0,entryProcess_1.runSubProcess)({initHandler:initHandler,messageHandler:messageHandler,timeout:(null===(_b=process.env)||void 0===_b?void 0:_b.timeout)||3e5});
1
+ var _a,_b;process.env&&process.env.isDevtools&&require("../../utils/hackrequire/index"),Object.defineProperty(exports,"__esModule",{value:!0}),(null===(_a=process.env)||void 0===_a?void 0:_a.isDevtools)&&require("../../utils/hackrequire/index");const entryProcess_1=require("../../utils/subprocess/entryProcess"),progressRecorder_1=require("../../utils/progressRecorder"),nativeCompiler_1=require("./nativeCompiler");let nativeCompiler;async function initHandler(e){const{projectInfo:i,passData:a}=e.data,{miniappDirPath:r,devtoolsVersion:s}=a;nativeCompiler=new nativeCompiler_1.NativeCompiler({projectInfo:i,miniappDirPath:r,devtoolsVersion:s})}async function messageHandler(e){if(e.type,"request"===e.type){const{id:i,name:a,data:r}=e,s=i,n=new progressRecorder_1.Recorder((e,i,a)=>{process.send({type:"progress",id:e,taskId:s,status:i,message:a})});r.fullEnv&&(global.fullEnv=r.fullEnv);try{let e;const t=`${a}-${s}`;if("buildNative"===a)e=await n.run(t,async()=>await nativeCompiler.build(r,n));else if("runNative"===a)e=await n.run(t,async()=>await nativeCompiler.run(r,n));else if("buildNativePlugin"===a)e=await n.run(t,async()=>await nativeCompiler.buildPlugin(r,n));else if("packIOSCloudBuildMaterial"===a)e=await n.run(t,async()=>await nativeCompiler.packIOSCloudBuildMaterial(r,n));else if("initUSBConnectionProcess"===a)e=await n.run(t,async()=>await nativeCompiler.initUSBConnectionProcess(r,n));else{if("codesignIOSApp"!==a)throw new Error("unknown command "+a);e=await n.run(t,async()=>await nativeCompiler.codesignIOSApp(r,n))}process.send({type:"response",id:i,data:e})}catch(e){process.send({type:"response",id:i,data:null,error:{code:e.code||-1,message:e.message,stack:e.stack,path:e.path||""}})}}}(0,entryProcess_1.runSubProcess)({initHandler:initHandler,messageHandler:messageHandler,timeout:(null===(_b=process.env)||void 0===_b?void 0:_b.timeout)||3e5});
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ConditionCompiler=void 0;const tslib_1=require("tslib"),path_1=tslib_1.__importDefault(require("path")),fs_1=tslib_1.__importDefault(require("fs")),define_1=require("../../../config/define"),plant_1=require("./compiler/plant"),json_1=require("./compiler/json"),macro_1=require("./compiler/macro"),minimatch_1=tslib_1.__importDefault(require("minimatch")),tools_1=require("../../../utils/tools"),defaultCompileSetting={targetPlatform:define_1.PLATFORM["mini-weixin"],targetPlatformDefines:{}};class ConditionCompiler{constructor(t,e){this.extToCompiler={},this.project=t,this.devtoolMessagehub=e}getCompiler(t,e){const{targetPlatform:o,targetPlatformDefines:i={}}=e;if(!Object.values(define_1.PLATFORM).includes(o))throw new Error(`platform ${o} is not supported`);if(!this.extToCompiler[t]){let e=null;const r={targetPlatform:o,targetPlatformDefines:i,type:t};e=[".wxml",".wxss",".less",".scss",".wxs",".ts",".js"].includes(t)?new macro_1.MacroConditionCompiler(r):".json"===t?new json_1.JSONConditionCompiler(r):new plant_1.PlantConditionCompiler(r),this.extToCompiler[t]=e}return this.extToCompiler[t].targetPlatform=e.targetPlatform,this.extToCompiler[t].targetPlatformDefines=e.targetPlatformDefines||{},this.extToCompiler[t]}shouldCompile(t){return!this.project.miniprogramRoot||this.project.miniprogramRoot&&t.startsWith(this.project.miniprogramRoot)||"project.config.json"===t||"project.private.config.json"===t}compileFile(t,e=defaultCompileSetting){var o;try{const o=path_1.default.join(this.project.projectPath,t);if(!fs_1.default.existsSync(o))throw Error("no such file or direactory: "+o);const i=path_1.default.extname(o),r=this.getCompiler(i,e).compile(o,this.project.getFile("",t));return Buffer.isBuffer(r)?r:Buffer.from(r)}catch(t){throw null===(o=this.devtoolMessagehub)||void 0===o||o.showBuildLog("compileFile","error",t.message),t}}compileProject(t=defaultCompileSetting){var e;if(!Object.values(define_1.PLATFORM).includes(t.targetPlatform))throw new Error(`platform ${t.targetPlatform} is not supported`);try{const e={},{targetPlatform:o,targetPlatformDefines:i={}}=t,r=this.project.getFileList();for(const t of r){if(!this.shouldCompile(t))continue;const r=this.compileFile(t,{targetPlatform:o,targetPlatformDefines:i});e[t]=r}}catch(t){throw null===(e=this.devtoolMessagehub)||void 0===e||e.showBuildLog("compileProject","error",t.message),t}return{}}filterResourceByPlatfrom(t=defaultCompileSetting){const{targetPlatform:e=define_1.PLATFORM["mini-weixin"]}=t;let o=this.project.getFileList();const i=(0,tools_1.getAppJson)(this.project,e).static||[];for(const t of i){const{pattern:i="",platforms:r=[]}=t,s=path_1.default.join(this.project.miniprogramRoot||"",i);if(!r.includes(e)){const t=o.filter(t=>(0,minimatch_1.default)(t,s));o=o.filter(e=>!t.includes(e)&&e!==s&&!(0,tools_1.normalizePath)(e).startsWith((0,tools_1.normalizePath)(s)))}}return o}}exports.ConditionCompiler=ConditionCompiler;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ConditionCompiler=void 0;const tslib_1=require("tslib"),path_1=tslib_1.__importDefault(require("path")),fs_1=tslib_1.__importDefault(require("fs")),define_1=require("../../../config/define"),plant_1=require("./compiler/plant"),json_1=require("./compiler/json"),macro_1=require("./compiler/macro"),minimatch_1=tslib_1.__importDefault(require("minimatch")),tools_1=require("../../../utils/tools"),defaultCompileSetting={targetPlatform:define_1.PLATFORM["mini-weixin"],targetPlatformDefines:{}};class ConditionCompiler{constructor(t,e,o){this.extToCompiler={},this.project=t,this.devtoolMessagehub=e,this.consoleDisplay=o}getCompiler(t,e){const{targetPlatform:o,targetPlatformDefines:i={}}=e;if(!Object.values(define_1.PLATFORM).includes(o))throw new Error(`platform ${o} is not supported`);if(!this.extToCompiler[t]){let e=null;const r={targetPlatform:o,targetPlatformDefines:i,type:t};e=[".wxml",".wxss",".less",".scss",".wxs",".ts",".js"].includes(t)?new macro_1.MacroConditionCompiler(r):".json"===t?new json_1.JSONConditionCompiler(r):new plant_1.PlantConditionCompiler(r),this.extToCompiler[t]=e}return this.extToCompiler[t].targetPlatform=e.targetPlatform,this.extToCompiler[t].targetPlatformDefines=e.targetPlatformDefines||{},this.extToCompiler[t]}shouldCompile(t){return!this.project.miniprogramRoot||this.project.miniprogramRoot&&t.startsWith(this.project.miniprogramRoot)||"project.config.json"===t||"project.private.config.json"===t}compileFile(t,e=defaultCompileSetting){var o,i;try{const o=path_1.default.join(this.project.projectPath,t);if(!fs_1.default.existsSync(o))throw Error("no such file or direactory: "+o);const i=path_1.default.extname(o),r=this.getCompiler(i,e).compile(o,this.project.getFile("",t));return Buffer.isBuffer(r)?r:Buffer.from(r)}catch(t){throw null===(o=this.devtoolMessagehub)||void 0===o||o.showBuildLog("compileFile","error",t.message),null===(i=this.consoleDisplay)||void 0===i||i.display({command:"DISPLAY_ERROR",data:{error:{message:t.message}}}),t}}compileProject(t=defaultCompileSetting){var e;if(!Object.values(define_1.PLATFORM).includes(t.targetPlatform))throw new Error(`platform ${t.targetPlatform} is not supported`);try{const e={},{targetPlatform:o,targetPlatformDefines:i={}}=t,r=this.project.getFileList();for(const t of r){if(!this.shouldCompile(t))continue;const r=this.compileFile(t,{targetPlatform:o,targetPlatformDefines:i});e[t]=r}}catch(t){throw null===(e=this.devtoolMessagehub)||void 0===e||e.showBuildLog("compileProject","error",t.message),t}return{}}filterResourceByPlatfrom(t=defaultCompileSetting){const{targetPlatform:e=define_1.PLATFORM["mini-weixin"]}=t;let o=this.project.getFileList();const i=(0,tools_1.getAppJson)(this.project,e).static||[];for(const t of i){const{pattern:i="",platforms:r=[]}=t,s=path_1.default.join(this.project.miniprogramRoot||"",i);if(!r.includes(e)){const t=o.filter(t=>(0,minimatch_1.default)(t,s));o=o.filter(e=>!t.includes(e)&&e!==s&&!(0,tools_1.normalizePath)(e).startsWith((0,tools_1.normalizePath)(s)))}}return o}}exports.ConditionCompiler=ConditionCompiler;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ConditionCompiler=exports.PreCompiler=void 0;const precompileProject_1=require("../../project/advance/precompileProject"),define_1=require("../../config/define"),conditioncompile_1=require("./conditioncompile"),defaultCompileSetting={targetPlatform:define_1.PLATFORM["mini-weixin"],targetPlatformDefines:{}};class PreCompiler{constructor(e,o){this.project=e,this.devtoolMessagehub=o}async getPreCompileProject(e=defaultCompileSetting){const{targetPlatform:o=define_1.PLATFORM["mini-weixin"],targetPlatformDefines:i={},runEnv:t}=e,r=new conditioncompile_1.ConditionCompiler(this.project,this.devtoolMessagehub),n=new precompileProject_1.PreCompileProject(this.project,r,{targetPlatform:o,targetPlatformDefines:i,runEnv:t});return await n.ready(),n}}exports.PreCompiler=PreCompiler;var conditioncompile_2=require("./conditioncompile");Object.defineProperty(exports,"ConditionCompiler",{enumerable:!0,get:function(){return conditioncompile_2.ConditionCompiler}});
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ConditionCompiler=exports.PreCompiler=void 0;const precompileProject_1=require("../../project/advance/precompileProject"),define_1=require("../../config/define"),conditioncompile_1=require("./conditioncompile"),defaultCompileSetting={targetPlatform:define_1.PLATFORM["mini-weixin"],targetPlatformDefines:{}};class PreCompiler{constructor(e,o,i){this.project=e,this.devtoolMessagehub=o,this.consoleDisplay=i}async getPreCompileProject(e=defaultCompileSetting){const{targetPlatform:o=define_1.PLATFORM["mini-weixin"],targetPlatformDefines:i={},runEnv:t}=e,r=new conditioncompile_1.ConditionCompiler(this.project,this.devtoolMessagehub,this.consoleDisplay),n=new precompileProject_1.PreCompileProject(this.project,r,{targetPlatform:o,targetPlatformDefines:i,runEnv:t});return await n.ready(),n}}exports.PreCompiler=PreCompiler;var conditioncompile_2=require("./conditioncompile");Object.defineProperty(exports,"ConditionCompiler",{enumerable:!0,get:function(){return conditioncompile_2.ConditionCompiler}});
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PreCompileProject=void 0;const tslib_1=require("tslib"),path_1=tslib_1.__importDefault(require("path")),stream_1=require("stream"),baseProject_1=require("../baseProject"),tools_1=require("../../utils/tools"),define_1=require("../../config/define");class PreCompileProject extends baseProject_1.BaseProject{constructor(t,e,i){var r,s,o;if(super(),this.event=new stream_1.EventEmitter,this.targetPlatform=define_1.PLATFORM["mini-weixin"],this.targetPlatformDefines={},this._fileBufferCache={},this.onFileChange=async(t,e)=>{if(e=(0,tools_1.normalizePath)(e).replace(/\/$/,"").replace(/^\//,""),"add"===t&&(this.cacheDirName(this._dirSet,path_1.default.posix.dirname(e)),this._fileSet.add(e),this.shouldConditionalCompile()?this._fileBufferCache[e]=this.conditionCompiler.compileFile(e,{targetPlatform:this.targetPlatform,targetPlatformDefines:this.targetPlatformDefines}):this._fileBufferCache[e]=this.project.getFile("",e)),"addDir"===t&&this.cacheDirName(this._dirSet,e),"unlink"===t&&(this.deleteDirOrFileOfSet(this._dirSet,this._fileSet,e),this._fileBufferCache[e]&&delete this._fileBufferCache[e]),"unlinkDir"===t&&this.deleteDirOrFileOfSet(this._dirSet,this._fileSet,e),"change"===t&&delete this._fileBufferCache[e],this.event.emit("fileChange",t,e),"change"===t&&e===path_1.default.posix.join(this.project.miniprogramRoot||"","app.json")){const t=Array.from(this._fileSet);this.updateFileAndDirs(),this.notifyRefreshFileOrDirs(t)}},this.project=t,this._projectPath=(0,tools_1.normalizePath)(t.projectPath),this._projectArchitecture=t.projectArchitecture,this._miniprogramRoot=t.miniprogramRoot||"",this._pluginRoot=t.pluginRoot,this._appid=t.appid,this._type=t.type?t.type:"miniProgram",this._privateKey=t.privateKey,this.ignores=t.ignores||[],null===(r=this.project.event)||void 0===r||r.on("fileChange",(t,e)=>{this.onFileChange(t,e)}),null===(s=this.project.event)||void 0===s||s.on("optionsChange",t=>{this.updateOptions(t)}),this.runEnv=i.runEnv,null===(o=this.project)||void 0===o?void 0:o.setting)this.setting=this.project.setting;else{const t=this.getProjectConfig();(null==t?void 0:t.setting)&&(this.setting=t.setting)}this.conditionCompiler=e,this.updateConditionCompileOptions({targetPlatform:i.targetPlatform||define_1.PLATFORM["mini-weixin"],targetPlatformDefines:i.targetPlatformDefines}),this.packOptions=t.packOptions||{ignore:[],include:[]}}async ready(){await this.wait(this.init.bind(this))}async init(){this.updateFileAndDirs()}shouldConditionalCompile(){var t;return!!(null===(t=this.project.setting)||void 0===t?void 0:t.condition)}updateOptions(t){this._appid=t.appid,this._attr=t.attr,this._type=this.getProjectType(t.attr,t.compileType),this._miniprogramRoot=t.miniprogramRoot,this._pluginRoot=t.pluginRoot,this._projectArchitecture=t.projectArchitecture,this.packOptions=t.packOptions||{ignore:[],include:[]}}updateConditionCompileOptions(t){const e=this.targetPlatform;if(this.targetPlatform=t.targetPlatform||define_1.PLATFORM["mini-weixin"],this.targetPlatformDefines=t.targetPlatformDefines||{},this.targetPlatform!==e){this._fileBufferCache={};const t=Array.from(this._fileSet);this.updateFileAndDirs(),this.notifyRefreshFileOrDirs(t),this.event.emit("precompileOptionsChange",{targetPlatform:this.targetPlatform,targetPlatformDefines:this.targetPlatformDefines})}}updateFileAndDirs(){var t,e;if(null===(t=this._fileSet)||void 0===t||t.clear(),null===(e=this._dirSet)||void 0===e||e.clear(),this.shouldConditionalCompile()){const t=this.conditionCompiler.filterResourceByPlatfrom({targetPlatform:this.targetPlatform});for(const e of t){const t=e.replace(/\\/g,path_1.default.posix.sep);this._fileSet.add(t),this.cacheDirName(this._dirSet,t)}}else{const{files:t,dirs:e}=this.project.getFilesAndDirs();this._fileSet=new Set(t),this._dirSet=new Set(e)}}get srcPath(){return this.project.srcPath||""}async attr(){return await this.project.attr()}async serialize(){const t=await super.serialize();return Object.assign(Object.assign({},t),{targetPlatform:this.targetPlatform,targetPlatformDefines:this.targetPlatformDefines})}getSrcFile(t="",e){return this.project.getFile(t,e)}getFile(t="",e){const i=this.getTargetPath(t,e);return this._fileBufferCache[i]||(this.shouldConditionalCompile()?this._fileBufferCache[i]=this.conditionCompiler.compileFile(i,{targetPlatform:this.targetPlatform,targetPlatformDefines:this.targetPlatformDefines}):this._fileBufferCache[i]=this.project.getFile(t,e)),this._fileBufferCache[i]}notifyRefreshFileOrDirs(t){const e=Array.from(this._fileSet);e.length!==t.length&&(e.forEach(e=>{t.includes(e)||this.event.emit("fileChange","add",e)}),t.forEach(t=>{e.includes(t)||this.event.emit("fileChange","unlink",t)}))}clearCache(){var t,e;this._fileBufferCache={},null===(e=(t=this.project).clearCache)||void 0===e||e.call(t)}}exports.PreCompileProject=PreCompileProject;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PreCompileProject=void 0;const tslib_1=require("tslib"),path_1=tslib_1.__importDefault(require("path")),stream_1=require("stream"),baseProject_1=require("../baseProject"),tools_1=require("../../utils/tools"),define_1=require("../../config/define");class PreCompileProject extends baseProject_1.BaseProject{constructor(t,e,i){var r,s,o;if(super(),this.event=new stream_1.EventEmitter,this.targetPlatform=define_1.PLATFORM["mini-weixin"],this.targetPlatformDefines={},this._fileBufferCache={},this.onFileChange=async(t,e)=>{if(e=(0,tools_1.normalizePath)(e).replace(/\/$/,"").replace(/^\//,""),"add"===t&&(this.cacheDirName(this._dirSet,path_1.default.posix.dirname(e)),this._fileSet.add(e)),"addDir"===t&&this.cacheDirName(this._dirSet,e),"unlink"===t&&(this.deleteDirOrFileOfSet(this._dirSet,this._fileSet,e),this._fileBufferCache[e]&&delete this._fileBufferCache[e]),"unlinkDir"===t&&this.deleteDirOrFileOfSet(this._dirSet,this._fileSet,e),"change"===t&&delete this._fileBufferCache[e],this.event.emit("fileChange",t,e),"change"===t&&e===path_1.default.posix.join(this.project.miniprogramRoot||"","app.json")){const t=Array.from(this._fileSet);this.updateFileAndDirs(),this.notifyRefreshFileOrDirs(t)}},this.project=t,this._projectPath=(0,tools_1.normalizePath)(t.projectPath),this._projectArchitecture=t.projectArchitecture,this._miniprogramRoot=t.miniprogramRoot||"",this._pluginRoot=t.pluginRoot,this._appid=t.appid,this._type=t.type?t.type:"miniProgram",this._privateKey=t.privateKey,this.ignores=t.ignores||[],null===(r=this.project.event)||void 0===r||r.on("fileChange",(t,e)=>{this.onFileChange(t,e)}),null===(s=this.project.event)||void 0===s||s.on("optionsChange",t=>{this.updateOptions(t)}),this.runEnv=i.runEnv,null===(o=this.project)||void 0===o?void 0:o.setting)this.setting=this.project.setting;else{const t=this.getProjectConfig();(null==t?void 0:t.setting)&&(this.setting=t.setting)}this.conditionCompiler=e,this.updateConditionCompileOptions({targetPlatform:i.targetPlatform||define_1.PLATFORM["mini-weixin"],targetPlatformDefines:i.targetPlatformDefines}),this.packOptions=t.packOptions||{ignore:[],include:[]}}async ready(){await this.wait(this.init.bind(this))}async init(){this.updateFileAndDirs()}shouldConditionalCompile(){var t;return!!(null===(t=this.project.setting)||void 0===t?void 0:t.condition)}updateOptions(t){this._appid=t.appid,this._attr=t.attr,this._type=this.getProjectType(t.attr,t.compileType),this._miniprogramRoot=t.miniprogramRoot,this._pluginRoot=t.pluginRoot,this._projectArchitecture=t.projectArchitecture,this.packOptions=t.packOptions||{ignore:[],include:[]}}updateConditionCompileOptions(t){const e=this.targetPlatform;if(this.targetPlatform=t.targetPlatform||define_1.PLATFORM["mini-weixin"],this.targetPlatformDefines=t.targetPlatformDefines||{},this.targetPlatform!==e){this._fileBufferCache={};const t=Array.from(this._fileSet);this.updateFileAndDirs(),this.notifyRefreshFileOrDirs(t),this.event.emit("precompileOptionsChange",{targetPlatform:this.targetPlatform,targetPlatformDefines:this.targetPlatformDefines})}}updateFileAndDirs(){var t,e;if(null===(t=this._fileSet)||void 0===t||t.clear(),null===(e=this._dirSet)||void 0===e||e.clear(),this.shouldConditionalCompile()){const t=this.conditionCompiler.filterResourceByPlatfrom({targetPlatform:this.targetPlatform});for(const e of t){const t=e.replace(/\\/g,path_1.default.posix.sep);this._fileSet.add(t),this.cacheDirName(this._dirSet,t)}}else{const{files:t,dirs:e}=this.project.getFilesAndDirs();this._fileSet=new Set(t),this._dirSet=new Set(e)}}get srcPath(){return this.project.srcPath||""}async attr(){return await this.project.attr()}async serialize(){const t=await super.serialize();return Object.assign(Object.assign({},t),{targetPlatform:this.targetPlatform,targetPlatformDefines:this.targetPlatformDefines})}getSrcFile(t="",e){return this.project.getFile(t,e)}getFile(t="",e){var i;const r=this.getTargetPath(t,e);if(!this._fileBufferCache[r]){if("condition"!==(null===(i=this._fileBufferCache[r])||void 0===i?void 0:i.type)&&this.shouldConditionalCompile())try{const t=this.conditionCompiler.compileFile(r,{targetPlatform:this.targetPlatform,targetPlatformDefines:this.targetPlatformDefines});return this._fileBufferCache[r]={content:t,type:"condition"},this._fileBufferCache[r].content}catch(t){}this._fileBufferCache[r]={content:this.project.getFile(t,e),type:"raw"}}return this._fileBufferCache[r].content}notifyRefreshFileOrDirs(t){const e=Array.from(this._fileSet);e.length!==t.length&&(e.forEach(e=>{t.includes(e)||this.event.emit("fileChange","add",e)}),t.forEach(t=>{e.includes(t)||this.event.emit("fileChange","unlink",t)}))}clearCache(){var t,e;this._fileBufferCache={},null===(e=(t=this.project).clearCache)||void 0===e||e.call(t)}}exports.PreCompileProject=PreCompileProject;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.BaseProject=void 0;const tslib_1=require("tslib"),path_1=tslib_1.__importDefault(require("path")),stream_1=require("stream"),fs_extra_1=tslib_1.__importDefault(require("fs-extra")),tools_1=require("../utils/tools"),waitable_1=tslib_1.__importDefault(require("../utils/waitable"));class BaseProject extends waitable_1.default{constructor(){super(...arguments),this._projectPath="",this._projectArchitecture="miniProgram",this._type="miniProgram",this._privateKey="",this.ignores=[],this.setting={},this._dirSet=new Set,this._fileSet=new Set,this.event=new stream_1.EventEmitter}get projectPath(){return this._projectPath}get projectArchitecture(){return this._projectArchitecture}get srcPath(){let t="";return"miniProgramPlugin"!==this._type&&"miniGamePlugin"!==this._type||(t=(0,tools_1.normalizePath)(path_1.default.join(this.projectPath,this.pluginRoot||""))),t=(0,tools_1.normalizePath)(path_1.default.join(this.projectPath,this.miniprogramRoot||"")),(this._projectPath.startsWith("//")||this._projectPath.startsWith("\\\\"))&&(t.startsWith("//")||(t="/"+t)),t}get pluginSrcPath(){return(0,tools_1.normalizePath)(path_1.default.join(this.projectPath,this.pluginRoot||""))}get type(){return this._type}set type(t){this._type=t}get appid(){return this._appid}set appid(t){this._appid=t}get privateKey(){return this._privateKey}set privateKey(t){this._privateKey=t}get miniprogramRoot(){return this._miniprogramRoot||""}set miniprogramRoot(t){this._miniprogramRoot=t}get pluginRoot(){return this._pluginRoot}set pluginRoot(t){this._pluginRoot=t}get nameMappingFromDevtools(){return this._nameMappingFromDevtools}set nameMappingFromDevtools(t){this._nameMappingFromDevtools=t}async attr(){return this._attr}async ready(){await this.wait()}getProjectType(t,e){let i="";return i=(null==t?void 0:t.gameApp)?"miniGamePlugin"===e?"miniGamePlugin":"miniGame":e,i}getProjectConfig(){let t={};const e=path_1.default.join(this.projectPath,"project.config.json");if(fs_extra_1.default.existsSync(e))try{t=fs_extra_1.default.readJsonSync(e)}catch(t){throw new Error("project.config.json not exist")}return t}async serialize(){const{files:t,dirs:e}=this.getFilesAndDirs();return{projectPath:this.projectPath,appid:this.appid,attr:await this.attr(),type:this.type,projectArchitecture:this.projectArchitecture,miniprogramRoot:this.miniprogramRoot,pluginRoot:this.pluginRoot,files:t,dirs:e,setting:this.setting}}updateFiles(){this.updateFileAndDirs(...arguments)}updateOptions(t){this._appid=t.appid,this._attr=t.attr,this._type=this.getProjectType(t.attr,t.compileType),this._miniprogramRoot=t.miniprogramRoot,this._pluginRoot=t.pluginRoot,this._projectArchitecture=t.projectArchitecture,this.packOptions=t.packOptions||{ignore:[],include:[]},this.event.emit("optionsChange",t)}cacheDirName(t,e){t.has(e)||(t.add(e),this.cacheDirName(t,path_1.default.posix.dirname(e)))}deleteDirOrFileOfSet(t,e,i){if(t.has(i)){t.delete(i);const r=i+"/",s=Array.from(t);for(const e of s)e.startsWith(r)&&t.delete(e);const a=Array.from(e);for(const t of a)t.startsWith(r)&&e.delete(t)}e.has(i)&&e.delete(i)}getTargetPath(t="",e=""){return(0,tools_1.normalizePath)(path_1.default.posix.join(t,e)).replace(/\/$/,"").replace(/^\//,"")}getFilesAndDirs(){return{files:Array.from(this._fileSet),dirs:Array.from(this._dirSet)}}exists(t="",e=""){const i=this.getTargetPath(t,e);if(!i.startsWith(t))return!1;if(this._fileSet.has(i)||this._dirSet.has(i))return!0;const r=(0,tools_1.normalizePath)(path_1.default.posix.join(this.projectPath,i));return fs_extra_1.default.existsSync(r)}stat(t="",e=""){if(!this.exists(t,e))return;const i=this.getTargetPath(t,e),r=path_1.default.join(this.projectPath,i);let s={};try{s=fs_extra_1.default.statSync(r)}catch(t){fs_extra_1.default.existsSync(r)||this.deleteDirOrFileOfSet(this._dirSet,this._fileSet,i)}if(this._fileSet.has(i)){return{isFile:!0,isDirectory:!1,size:this.getFileSize(t,e),mtimeMs:s.mtimeMs||""}}return this._dirSet.has(i)?{isFile:!1,isDirectory:!0,size:0,mtimeMs:s.mtimeMs}:void 0}getAllFileInfo(t=""){const e=this.getFileList(t),i={};return e.forEach(t=>{i[t]=this.stat("",t)||{}}),i}getFileList(t="",e=""){return Array.from(this._fileSet).filter(i=>(!e||path_1.default.posix.extname(i)===e)&&!(t&&!i.startsWith(t)))}getSrcFile(t,e){t=t||"";const i=this.getTargetPath(t,e),r=(0,tools_1.normalizePath)(path_1.default.posix.join(this.projectPath,i));return fs_extra_1.default.readFileSync(r,null)}getFile(t,e){return this.getSrcFile(t,e)}getJson(t="",e=""){const i=this.getFile(t,e).toString("utf-8");try{return JSON.parse(i)}catch(i){throw new Error("JSON parse failed: "+this.getTargetPath(t,e))}}getFileSize(t="",e=""){const i=this.getFile(t,e);return i?i.byteLength:0}getExtAppid(){throw new Error("Method not implemented.")}async onFileChange(t,e){e=(0,tools_1.normalizePath)(e).replace(/\/$/,"").replace(/^\//,""),"add"===t&&(this.cacheDirName(this._dirSet,path_1.default.posix.dirname(e)),this._fileSet.add(e)),"addDir"===t&&this.cacheDirName(this._dirSet,e),"unlink"===t&&this.deleteDirOrFileOfSet(this._dirSet,this._fileSet,e),"unlinkDir"===t&&this.deleteDirOrFileOfSet(this._dirSet,this._fileSet,e),"change"===t&&this._fileSet.has(e),this.event.emit("fileChange",t,e)}clearCache(){}}exports.BaseProject=BaseProject;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.BaseProject=void 0;const tslib_1=require("tslib"),path_1=tslib_1.__importDefault(require("path")),stream_1=require("stream"),fs_extra_1=tslib_1.__importDefault(require("fs-extra")),tools_1=require("../utils/tools"),waitable_1=tslib_1.__importDefault(require("../utils/waitable"));class BaseProject extends waitable_1.default{constructor(){super(...arguments),this._projectPath="",this._projectArchitecture="miniProgram",this._type="miniProgram",this._privateKey="",this.ignores=[],this.setting={},this._dirSet=new Set,this._fileSet=new Set,this.event=new stream_1.EventEmitter}get projectPath(){return this._projectPath}get projectArchitecture(){return this._projectArchitecture}get srcPath(){let t="";return"miniProgramPlugin"!==this._type&&"miniGamePlugin"!==this._type||(t=(0,tools_1.normalizePath)(path_1.default.join(this.projectPath,this.pluginRoot||""))),t=(0,tools_1.normalizePath)(path_1.default.join(this.projectPath,this.miniprogramRoot||"")),(this._projectPath.startsWith("//")||this._projectPath.startsWith("\\\\"))&&(t.startsWith("//")||(t="/"+t)),t}get pluginSrcPath(){return(0,tools_1.normalizePath)(path_1.default.join(this.projectPath,this.pluginRoot||""))}get type(){return this._type}set type(t){this._type=t}get appid(){return this._appid}set appid(t){this._appid=t}get privateKey(){return this._privateKey}set privateKey(t){this._privateKey=t}get miniprogramRoot(){return this._miniprogramRoot||""}set miniprogramRoot(t){this._miniprogramRoot=t}get pluginRoot(){return this._pluginRoot}set pluginRoot(t){this._pluginRoot=t}get nameMappingFromDevtools(){return this._nameMappingFromDevtools}set nameMappingFromDevtools(t){this._nameMappingFromDevtools=t}async attr(){return this._attr}async ready(){await this.wait()}getProjectType(t,e){let i="";return i=(null==t?void 0:t.gameApp)?"miniGamePlugin"===e?"miniGamePlugin":"miniGame":e,i}getProjectConfig(){let t={};const e=path_1.default.join(this.projectPath,"project.config.json");if(fs_extra_1.default.existsSync(e))try{t=fs_extra_1.default.readJsonSync(e)}catch(t){throw new Error("project.config.json not exist")}return t}async serialize(){const{files:t,dirs:e}=this.getFilesAndDirs();return{projectPath:this.projectPath,appid:this.appid,attr:await this.attr(),type:this.type,projectArchitecture:this.projectArchitecture,miniprogramRoot:this.miniprogramRoot,pluginRoot:this.pluginRoot,files:t,dirs:e,setting:this.setting}}updateFiles(){this.updateFileAndDirs(...arguments)}updateOptions(t){this._appid=t.appid,this._attr=t.attr,this._type=this.getProjectType(t.attr,t.compileType),this._miniprogramRoot=t.miniprogramRoot,this._pluginRoot=t.pluginRoot,this._projectArchitecture=t.projectArchitecture,this.packOptions=t.packOptions||{ignore:[],include:[]},this.event.emit("optionsChange",t)}cacheDirName(t,e){t.has(e)||(t.add(e),this.cacheDirName(t,path_1.default.posix.dirname(e)))}deleteDirOrFileOfSet(t,e,i){if(t.has(i)){t.delete(i);const r=i+"/",s=Array.from(t);for(const e of s)e.startsWith(r)&&t.delete(e);const a=Array.from(e);for(const t of a)t.startsWith(r)&&e.delete(t)}e.has(i)&&e.delete(i)}getTargetPath(t="",e=""){return(0,tools_1.normalizePath)((0,tools_1.joinPath)(t,e)).replace(/\/$/,"").replace(/^\//,"")}getFilesAndDirs(){return{files:Array.from(this._fileSet),dirs:Array.from(this._dirSet)}}exists(t="",e=""){const i=this.getTargetPath(t,e);if(!i.startsWith(t))return!1;if(this._fileSet.has(i)||this._dirSet.has(i))return!0;const r=(0,tools_1.normalizePath)((0,tools_1.joinPath)(this.projectPath,i));return fs_extra_1.default.existsSync(r)}stat(t="",e=""){if(!this.exists(t,e))return;const i=this.getTargetPath(t,e),r=path_1.default.join(this.projectPath,i);let s={};try{s=fs_extra_1.default.statSync(r)}catch(t){fs_extra_1.default.existsSync(r)||this.deleteDirOrFileOfSet(this._dirSet,this._fileSet,i)}if(this._fileSet.has(i)){return{isFile:!0,isDirectory:!1,size:this.getFileSize(t,e),mtimeMs:s.mtimeMs||""}}return this._dirSet.has(i)?{isFile:!1,isDirectory:!0,size:0,mtimeMs:s.mtimeMs}:void 0}getAllFileInfo(t=""){const e=this.getFileList(t),i={};return e.forEach(t=>{i[t]=this.stat("",t)||{}}),i}getFileList(t="",e=""){return Array.from(this._fileSet).filter(i=>(!e||path_1.default.posix.extname(i)===e)&&!(t&&!i.startsWith(t)))}getSrcFile(t,e){t=t||"";const i=this.getTargetPath(t,e),r=(0,tools_1.normalizePath)((0,tools_1.joinPath)(this.projectPath,i));return fs_extra_1.default.readFileSync(r,null)}getFile(t,e){return this.getSrcFile(t,e)}getJson(t="",e=""){const i=this.getFile(t,e).toString("utf-8");try{return JSON.parse(i)}catch(i){throw new Error("JSON parse failed: "+this.getTargetPath(t,e))}}getFileSize(t="",e=""){const i=this.getFile(t,e);return i?i.byteLength:0}getExtAppid(){throw new Error("Method not implemented.")}async onFileChange(t,e){e=(0,tools_1.normalizePath)(e).replace(/\/$/,"").replace(/^\//,""),"add"===t&&(this.cacheDirName(this._dirSet,path_1.default.posix.dirname(e)),this._fileSet.add(e)),"addDir"===t&&this.cacheDirName(this._dirSet,e),"unlink"===t&&this.deleteDirOrFileOfSet(this._dirSet,this._fileSet,e),"unlinkDir"===t&&this.deleteDirOrFileOfSet(this._dirSet,this._fileSet,e),"change"===t&&this._fileSet.has(e),this.event.emit("fileChange",t,e)}clearCache(){}}exports.BaseProject=BaseProject;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});