miniprogram-ci 2.1.29 → 2.1.30

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 (55) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/README.md +2 -0
  3. package/dist/@types/config/config.d.ts +1 -1
  4. package/dist/@types/modules/corecompiler/baseCompiler.d.ts +1 -0
  5. package/dist/@types/modules/corecompiler/originalCompiler.d.ts +1 -0
  6. package/dist/@types/modules/corecompiler/summer/graph/basegraph.d.ts +2 -0
  7. package/dist/@types/modules/corecompiler/summer/module.d.ts +8 -3
  8. package/dist/@types/modules/corecompiler/summer/pluginconfig.d.ts +1 -1
  9. package/dist/@types/modules/corecompiler/summer/plugins/base/es6module.d.ts +0 -17
  10. package/dist/@types/modules/corecompiler/summer/plugins/filetask/script.d.ts +28 -0
  11. package/dist/@types/modules/corecompiler/summer/plugins/index.d.ts +1 -1
  12. package/dist/@types/modules/corecompiler/summer/plugins/script_task/babel_script_task.d.ts +22 -0
  13. package/dist/@types/modules/corecompiler/summer/plugins/script_task/load_script_task.d.ts +7 -0
  14. package/dist/@types/modules/corecompiler/summer/plugins/script_task/minify_script_task.d.ts +5 -0
  15. package/dist/@types/modules/corecompiler/summer/plugins/script_task/swc_task.d.ts +22 -0
  16. package/dist/@types/modules/corecompiler/summerCompiler.d.ts +4 -0
  17. package/dist/@types/types/devtools.d.ts +9 -0
  18. package/dist/@types/types/summer.d.ts +7 -2
  19. package/dist/@types/utils/env.d.ts +1 -0
  20. package/dist/@types/utils/helper_util.d.ts +1 -1
  21. package/dist/@types/utils/packOptionsHelper.d.ts +1 -0
  22. package/dist/@types/utils/subprocess/processManager.d.ts +1 -1
  23. package/dist/ci/android-miniapp-toolkit/dist/index.js +1 -1
  24. package/dist/ci/build-apk.js +1 -1
  25. package/dist/config/config.js +1 -1
  26. package/dist/modules/corecompiler/original/json/game.js +1 -1
  27. package/dist/modules/corecompiler/originalCompiler.js +1 -1
  28. package/dist/modules/corecompiler/processHandler.js +1 -1
  29. package/dist/modules/corecompiler/summer/graph/basegraph.js +1 -1
  30. package/dist/modules/corecompiler/summer/module.js +1 -1
  31. package/dist/modules/corecompiler/summer/pluginconfig.js +1 -1
  32. package/dist/modules/corecompiler/summer/plugins/base/es6module.js +1 -1
  33. package/dist/modules/corecompiler/summer/plugins/base/javascript.js +1 -1
  34. package/dist/modules/corecompiler/summer/plugins/base/swc.js +1 -1
  35. package/dist/modules/corecompiler/summer/plugins/enhance.js +1 -1
  36. package/dist/modules/corecompiler/summer/plugins/filetask/script.js +1 -0
  37. package/dist/modules/corecompiler/summer/plugins/index.js +1 -1
  38. package/dist/modules/corecompiler/summer/plugins/less.js +1 -1
  39. package/dist/modules/corecompiler/summer/plugins/sass.js +1 -1
  40. package/dist/modules/corecompiler/summer/plugins/script_task/babel_script_task.js +1 -0
  41. package/dist/modules/corecompiler/summer/plugins/script_task/load_script_task.js +1 -0
  42. package/dist/modules/corecompiler/summer/plugins/script_task/minify_script_task.js +1 -0
  43. package/dist/modules/corecompiler/summer/plugins/script_task/swc_task.js +1 -0
  44. package/dist/modules/corecompiler/summer/plugins/terser.js +1 -1
  45. package/dist/modules/corecompiler/summer/plugins/typescript.js +1 -1
  46. package/dist/modules/corecompiler/summer/summer.js +1 -1
  47. package/dist/modules/corecompiler/summerCompiler.js +1 -1
  48. package/dist/modules/createSummer.js +1 -1
  49. package/dist/modules/nativecompiler/ios/buildCloud.js +1 -1
  50. package/dist/utils/cosUpload.js +1 -1
  51. package/dist/utils/env.js +1 -1
  52. package/dist/utils/packOptionsHelper.js +1 -1
  53. package/dist/utils/subprocess/processManager.js +1 -1
  54. package/dist/utils/subprocess/processService.js +1 -1
  55. package/package.json +1 -1
@@ -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"),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"),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,a,r){super(e),this.project=e,this.cachePath=t,this.projectInfo=i,this.devtoolMessagehub=s,this.analyzer=o,this._filterFactory=a,this.onInitFinished=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,a=await this.filterFactory(i),r={},n=s.filter(t=>{const i=path_1.default.posix.join(o,t.source),s=a(e,i);return s!==config_1.EFilterCode.Include&&(r[s]||(r[s]=[]),r[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 r)c[e]?this.onProgressUpdate(e,"warn",c[e].format(r[e].join(","))):this.onProgressUpdate(e,"warn",locales_1.default.config.UNKNOWN_REASON_INGORE_LIST.format(e,r[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"),t="undefined"!=typeof WEBIDE_WEBPECK_DEFINE_PLUGIN?"./summerentryprocess.js":e;this.subProcessManager=new processManager_1.SubProcessProxy(this.project,t,{cachePath:this.cachePath},this.projectInfo,8891,this.onProgressUpdate),this.addProjectListener();this.loadStatus().then(()=>{var e;null===(e=this.onInitFinished)||void 0===e||e.call(this)},e=>{var t;null===(t=this.onInitFinished)||void 0===t||t.call(this,e)}),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){const t="getConf-"+e;if(this.promiseCache.has(t))return this.promiseCache.get(t);performanceMark("request get conf");const i={graphId:e},s=this.subProcessManager.runTask("getConf",i,this.onProgressUpdate);return this.promiseCache.set(t,s),performanceMark("request get conf",!0),s}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 a=new singletontask_1.SingletonTask(this._getPackageFiles.bind(this,e,t,i),o);return this._taskCache.set(o,a),null==a?void 0:a.getResult(!0)}isMiniappPlatformInclude(e){const t=path_1.default.posix.join(this.project.miniprogramRoot,"app.miniapp.json");return(0,tools_1.isMiniappPlatform)(this.project.targetPlatform)&&t===e}async filterUnusedFiles(e,t,i){const s=e?"miniGame":"miniProgram";return(await this.filterFactory(i))(s,t)}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)=>{const o=packOptionsHelper_1.default.relativePath(s);return this.isMiniappPlatformInclude(s)||packOptionsHelper_1.default.isFileIncluded(o)?config_1.EFilterCode.Include:packOptionsHelper_1.default.isIgnoredByRules(o)?config_1.EFilterCode.PackOptionsIgnore:i===miniProgram&&packOptionsHelper_1.default.isIgnoreByUnusedFiles(s,"prod"===e)?config_1.EFilterCode.AnalyseNoUse:t(i,s)}}async getCodeByFileList(e,t){const i={},s={},o=this.isPluginType(e)?this.project.pluginRoot:this.project.miniprogramRoot,a=[];for(const e of t){const t=this.devCodeCacheByPath.get(path_1.default.posix.join(o,e)),r=null==t?void 0:t.codeFile;let n=!1;t&&t.isValid&&r&&!("error"in r)||(n=!0,a.push(e)),r&&!("error"in r)&&(n&&(i[e]=r.md5),s[e]=r)}if(a.length>0){const t=await this.subProcessManager.runTask("getDevCodeByFileList",{graphId:e,fileList:a,cacheMd5:i},this.onProgressUpdate);for(const e in t){const i=t[e],a=path_1.default.posix.join(o,e);"error"in i||""!==i.md5?this.devCodeCacheByPath.set(a,{isValid:!0,codeFile:i}):this.devCodeCacheByPath.delete(a),s[e]=i}}return s}async getExtJSON(){return(await this.getConf(miniProgram)).ext}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(){var e,t,i,s;const o=this.isGameType(this.project.type),a=o?miniGame:miniProgram,r=await this.getConf(a),n=Object.keys(null!==(e=r.pages)&&void 0!==e?e:{}),c=Object.keys(null!==(t=r.comps)&&void 0!==t?t:{}),l=await this.getPackageFiles(a,config_1.FullPkg),g=null!==(i=null==l?void 0:l.map(e=>e.path).filter(e=>e.endsWith(".js")))&&void 0!==i?i:[],p=null!==(s=null==n?void 0:n.filter(e=>!c.includes(e)).map(e=>e+".js").filter(e=>g.includes(e)))&&void 0!==s?s:[],h=c.map(e=>e+".js").filter(e=>g.includes(e)),m=g.filter(e=>e.endsWith(".js")&&e!==(o?"game.js":"app.js")&&!p.includes(e)&&!h.includes(e));return{jsPagesFiles:p,components:h,otherJsFiles:m}}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=[],a=[],r=[];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,r.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,a.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:a,functionalPageFiles:r,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=[],a=[],r={},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(r[e])return;r[e]=!0;const i=encodeURI(e);a.push(""+i)});Object.keys(t.pages).filter(t=>n(t)===e).forEach(e=>{if(r[e])return;r[e]=!0;const t=encodeURI(e);s.push(""+t)});let c=t.packages[e].entry||"";c&&(c=path_1.default.posix.join(e,c),c=c.replace(/\.js$/,"")),i.forEach(e=>{const t=e.replace(/\.js$/,"");r[t]||(r[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:a,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")),a=await this.compileOther(this.isGameType(this.project.type)?miniGame:miniProgram,e.resultType||"prod",o);let r={};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(a).forEach(e=>{r[path_1.default.posix.join("miniprogram",e)]=a[e]}),Object.keys(n).forEach(e=>{r[path_1.default.posix.join("plugin",e)]=n[e]}),Object.keys(s).forEach(e=>{r[path_1.default.posix.join("miniprogram",e)]=s[e]}),Object.keys(t).forEach(e=>{r[path_1.default.posix.join("plugin",e)]=t[e]}),r["project.config.json"]=JSON.stringify({miniprogramRoot:"miniprogram",pluginRoot:"plugin",__compileDebugInfo__:{useSummer:!0}})}else r=Object.assign(Object.assign({},a),s),r["project.config.json"]=JSON.stringify({miniprogramRoot:"",__compileDebugInfo__:{useSummer:!0}});this.onProgressUpdate(111,"success",locales_1.default.config.SUMMER_PACK_FILES_FINISH.format());for(const e of Object.keys(r))"object"==typeof r[e]&&"Buffer"===r[e].type&&(r[e]=Buffer.from(r[e].data));return r}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 a=o.MiniProgramWhiteList;this.isGameType(this.project.type)&&(a=o.GameWhiteList);const r=this.isPluginType(e)?this.project.pluginRoot:this.project.miniprogramRoot,n=await this.filterFactory(t),c=this.project.getFileList(r,"").filter(t=>{const o=path_1.default.posix.extname(t),c=path_1.default.posix.relative(r,t);return!(!a.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(r,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"),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,a,r){super(e),this.project=e,this.cachePath=t,this.projectInfo=i,this.devtoolMessagehub=s,this.analyzer=o,this._filterFactory=a,this.onInitFinished=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}),packOptionsHelper_1.default.clearUnusedFiles()},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,a=await this.filterFactory(i),r={},n=s.filter(t=>{const i=path_1.default.posix.join(o,t.source),s=a(e,i);return s!==config_1.EFilterCode.Include&&(r[s]||(r[s]=[]),r[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 r)c[e]?this.onProgressUpdate(e,"warn",c[e].format(r[e].join(","))):this.onProgressUpdate(e,"warn",locales_1.default.config.UNKNOWN_REASON_INGORE_LIST.format(e,r[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"),t="undefined"!=typeof WEBIDE_WEBPECK_DEFINE_PLUGIN?"./summerentryprocess.js":e;this.subProcessManager=new processManager_1.SubProcessProxy(this.project,t,{cachePath:this.cachePath},this.projectInfo,8891,this.onProgressUpdate),this.addProjectListener();this.loadStatus().then(()=>{var e;null===(e=this.onInitFinished)||void 0===e||e.call(this)},e=>{var t;null===(t=this.onInitFinished)||void 0===t||t.call(this,e)}),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()}getProjectInfo(){return this.projectInfo}updateOptions(e){lodash_1.default.isEqual(e,this.projectInfo)||this.updateOptionsWithoutJudge(e)}updateOptionsWithoutJudge(e){var t;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)}updateOptionsWhenAttrNotChanged(e){var t;lodash_1.default.isEqual(Object.assign(Object.assign({},e),{attr:void 0}),Object.assign(Object.assign({},this.projectInfo),{attr:void 0}))||(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){const t="getConf-"+e;if(this.promiseCache.has(t))return this.promiseCache.get(t);performanceMark("request get conf");const i={graphId:e},s=this.subProcessManager.runTask("getConf",i,this.onProgressUpdate);return this.promiseCache.set(t,s),performanceMark("request get conf",!0),s}async waitSubProcessReady(){await this.subProcessManager.ready()}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 a=new singletontask_1.SingletonTask(this._getPackageFiles.bind(this,e,t,i),o);return this._taskCache.set(o,a),null==a?void 0:a.getResult(!0)}isMiniappPlatformInclude(e){const t=path_1.default.posix.join(this.project.miniprogramRoot,"app.miniapp.json");return(0,tools_1.isMiniappPlatform)(this.project.targetPlatform)&&t===e}async filterUnusedFiles(e,t,i){const s=e?"miniGame":"miniProgram";return(await this.filterFactory(i))(s,t)}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)=>{const o=packOptionsHelper_1.default.relativePath(s);return this.isMiniappPlatformInclude(s)||packOptionsHelper_1.default.isFileIncluded(o)?config_1.EFilterCode.Include:packOptionsHelper_1.default.isIgnoredByRules(o)?config_1.EFilterCode.PackOptionsIgnore:i===miniProgram&&packOptionsHelper_1.default.isIgnoreByUnusedFiles(s,"prod"===e)?config_1.EFilterCode.AnalyseNoUse:t(i,s)}}async getCodeByFileList(e,t){const i={},s={},o=this.isPluginType(e)?this.project.pluginRoot:this.project.miniprogramRoot,a=[];for(const e of t){const t=this.devCodeCacheByPath.get(path_1.default.posix.join(o,e)),r=null==t?void 0:t.codeFile;let n=!1;t&&t.isValid&&r&&!("error"in r)||(n=!0,a.push(e)),r&&!("error"in r)&&(n&&(i[e]=r.md5),s[e]=r)}if(a.length>0){const t=await this.subProcessManager.runTask("getDevCodeByFileList",{graphId:e,fileList:a,cacheMd5:i},this.onProgressUpdate);for(const e in t){const i=t[e],a=path_1.default.posix.join(o,e);"error"in i||""!==i.md5?this.devCodeCacheByPath.set(a,{isValid:!0,codeFile:i}):this.devCodeCacheByPath.delete(a),s[e]=i}}return s}async getExtJSON(){return(await this.getConf(miniProgram)).ext}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(){var e,t,i,s;const o=this.isGameType(this.project.type),a=o?miniGame:miniProgram,r=await this.getConf(a),n=Object.keys(null!==(e=r.pages)&&void 0!==e?e:{}),c=Object.keys(null!==(t=r.comps)&&void 0!==t?t:{}),l=await this.getPackageFiles(a,config_1.FullPkg),p=null!==(i=null==l?void 0:l.map(e=>e.path).filter(e=>e.endsWith(".js")))&&void 0!==i?i:[],g=null!==(s=null==n?void 0:n.filter(e=>!c.includes(e)).map(e=>e+".js").filter(e=>p.includes(e)))&&void 0!==s?s:[],h=c.map(e=>e+".js").filter(e=>p.includes(e)),m=p.filter(e=>e.endsWith(".js")&&e!==(o?"game.js":"app.js")&&!g.includes(e)&&!h.includes(e));return{jsPagesFiles:g,components:h,otherJsFiles:m}}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=[],a=[],r=[];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,r.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,a.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 p=[...s,...o,...i];return n&&p.push("app"),{hasAppJS:n,allFiles:p,pageFiles:i,componentFiles:o,workerFiles:a,functionalPageFiles:r,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=[],a=[],r={},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(r[e])return;r[e]=!0;const i=encodeURI(e);a.push(""+i)});Object.keys(t.pages).filter(t=>n(t)===e).forEach(e=>{if(r[e])return;r[e]=!0;const t=encodeURI(e);s.push(""+t)});let c=t.packages[e].entry||"";c&&(c=path_1.default.posix.join(e,c),c=c.replace(/\.js$/,"")),i.forEach(e=>{const t=e.replace(/\.js$/,"");r[t]||(r[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:a,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")),a=await this.compileOther(this.isGameType(this.project.type)?miniGame:miniProgram,e.resultType||"prod",o);let r={};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(a).forEach(e=>{r[path_1.default.posix.join("miniprogram",e)]=a[e]}),Object.keys(n).forEach(e=>{r[path_1.default.posix.join("plugin",e)]=n[e]}),Object.keys(s).forEach(e=>{r[path_1.default.posix.join("miniprogram",e)]=s[e]}),Object.keys(t).forEach(e=>{r[path_1.default.posix.join("plugin",e)]=t[e]}),r["project.config.json"]=JSON.stringify({miniprogramRoot:"miniprogram",pluginRoot:"plugin",__compileDebugInfo__:{useSummer:!0}})}else r=Object.assign(Object.assign({},a),s),r["project.config.json"]=JSON.stringify({miniprogramRoot:"",__compileDebugInfo__:{useSummer:!0}});this.onProgressUpdate(111,"success",locales_1.default.config.SUMMER_PACK_FILES_FINISH.format());for(const e of Object.keys(r))"object"==typeof r[e]&&"Buffer"===r[e].type&&(r[e]=Buffer.from(r[e].data));return r}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 a=o.MiniProgramWhiteList;this.isGameType(this.project.type)&&(a=o.GameWhiteList);const r=this.isPluginType(e)?this.project.pluginRoot:this.project.miniprogramRoot,n=await this.filterFactory(t),c=this.project.getFileList(r,"").filter(t=>{const o=path_1.default.posix.extname(t),c=path_1.default.posix.relative(r,t);return!(!a.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:()=>{}}),p={};for(const e in l){p[path_1.default.posix.relative(r,e)]=l[e]}return p}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")),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,i,t,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 m=["es6","minified","postcss","uglifyFileName","compileWorklet","enhance","minifyWXML","minifyWXSS","disableUseStrict","swc","useCompilerPlugins","babelSetting","swcSetting","minifyWXMLSetting","condition","targetPlatform"],l=null!==(i=null===(r=this.project)||void 0===r?void 0:r.setting)&&void 0!==i?i:{},c=null!==(t=e.setting)&&void 0!==t?t:{};for(const e of m){const r=l[e],i=c[e];if(!lodash_1.default.isEqual(r,i))return console.info(`shouldCreate return true, project.setting.${e}, before: ${JSON.stringify(r)}, after: ${JSON.stringify(i)}`),!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 i=new ciProject_1.CIProject(e);await i.ready();const t=this.ensureCacheDir(),o=this.getSummerOptions(e),s=new summerCompiler_1.SummerCompiler(i,t,o,{showBuildLog:()=>{}},r,void 0);return await s.ready(),s}getSummerOptions(e){const r=(0,pluginconfig_1.getSummerPluginConfig)(e.setting),i={[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:i,summerPlugins:r,setting:Object.assign({},e.setting),injectedPages:[]}}}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")),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,i,t,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 m=["es6","minified","postcss","uglifyFileName","compileWorklet","enhance","minifyWXML","minifyWXSS","disableUseStrict","swc","useCompilerPlugins","babelSetting","swcSetting","minifyWXMLSetting","condition","targetPlatform","lessSetting","sassSetting"],l=null!==(i=null===(r=this.project)||void 0===r?void 0:r.setting)&&void 0!==i?i:{},c=null!==(t=e.setting)&&void 0!==t?t:{};for(const e of m){const r=l[e],i=c[e];if(!lodash_1.default.isEqual(r,i))return console.info(`shouldCreate return true, project.setting.${e}, before: ${JSON.stringify(r)}, after: ${JSON.stringify(i)}`),!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 i=new ciProject_1.CIProject(e);await i.ready();const t=this.ensureCacheDir(),o=this.getSummerOptions(e),s=new summerCompiler_1.SummerCompiler(i,t,o,{showBuildLog:()=>{}},r,void 0);return await s.ready(),s}getSummerOptions(e){const r=(0,pluginconfig_1.getSummerPluginConfig)(e.setting),i={[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:i,summerPlugins:r,setting:Object.assign({},e.setting),injectedPages:[]}}}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.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,p,d,c,u,f,_,h,y,g;a.progress("update app base info...");const{mobileapp_info:m={}}=i,S=m.mobileapp_id,I=path_1.default.join(t,"Info.plist"),v={},x=(e,i)=>{var t,n;if((null==i?void 0:i.startsWith("%"))&&(null==i?void 0:i.endsWith("%"))){const o=i.slice(1,-1);v[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};x("UISplashScreenImageName",null===(o=null==n?void 0:n.splashscreen)||void 0===o?void 0:o.customImage),x("UISplashScreenVideoName",null===(r=null==n?void 0:n.splashscreen)||void 0===r?void 0:r.customVideo),x("UILaunchStoryboardName",null===(l=null==n?void 0:n.splashscreen)||void 0===l?void 0:l.customImage);const b=plist.readFileSync(I);if("object"==typeof n.customInfoPlist&&!Array.isArray(n.customInfoPlist)){a.progress("initiating user custom info.plist config");const e=n.customInfoPlist;for(const i in e)b[i]=e[i]}if(b.CFBundleName=x("CFBundleName",n.name),b.CFBundleDisplayName=x("CFBundleDisplayName",n.name),b.CFBundleShortVersionString=n.version,"number"==typeof n.versionCode?b.CFBundleVersion=parseInt(n.versionCode.toString(),10).toString():b.CFBundleVersion=(parseInt(b.CFBundleVersion,10)+1).toString(),b.CFBundleIdentifier=this.getBundleIdentifier(m),Array.isArray(null==n?void 0:n.openMimeTypes)&&this.validateCFBundleDocumentTypes(n.openMimeTypes,a)&&(b.CFBundleDocumentTypes=n.openMimeTypes,a.message("doing","openMimeTypes 应用成功")),Array.isArray(b.CFBundleURLTypes)||(b.CFBundleURLTypes=[]),(null===(d=null===(p=b.CFBundleURLTypes)||void 0===p?void 0:p[0])||void 0===d?void 0:d.CFBundleURLSchemes)&&(b.CFBundleURLTypes[0].CFBundleURLSchemes=[S]),b.CFBundleURLTypes[0]&&(b.CFBundleURLTypes=[b.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])?b[e]=x(e,null===(t=n.privateDescriptions)||void 0===t?void 0:t[e]):delete b[e]}),!0===(null===(c=null==n?void 0:n.infoPlist)||void 0===c?void 0:c.DisableAppUsesNonExemptEncryption)?b.ITSAppUsesNonExemptEncryption=!1:delete b.ITSAppUsesNonExemptEncryption,b.UIBackgroundModes=[],!0===(null===(u=null==n?void 0:n.infoPlist)||void 0===u?void 0:u.AudioInBackgroundMode)&&b.UIBackgroundModes.push("audio"),!0===(null===(f=null==n?void 0:n.infoPlist)||void 0===f?void 0:f.LocationInBackgroundMode)&&b.UIBackgroundModes.push("location"),!0===(null===(_=null==n?void 0:n.infoPlist)||void 0===_?void 0:_.requiresFullScreen)?b.UIRequiresFullScreen=!0:delete b.UIRequiresFullScreen,"object"==typeof(null===(h=null==n?void 0:n.infoPlist)||void 0===h?void 0:h.CFBundleURLTypes)){const e=this.generateInfoPlistCFBundleURLTypesItem(n.infoPlist.CFBundleURLTypes);b.CFBundleURLTypes.push(e);const{additionalCFBundleURLTypes:i}=n.infoPlist.CFBundleURLTypes;Array.isArray(i)&&i.forEach(e=>{if("object"==typeof e){const i=this.generateInfoPlistCFBundleURLTypesItem(e);b.CFBundleURLTypes.push(i)}})}if(null===(y=null==n?void 0:n.useExtendedSdk)||void 0===y?void 0:y.WeAppGoogleLogin){if(!(null==n?void 0:n.googleLoginClientID)||!(null==n?void 0:n.googleLoginBundleUrlType))throw new Error("勾选了 Google Login 拓展模块但未填写 googleLoginClientID 或 googleLoginBundleUrlType 将导致拓展模块无法使用");b.GIDClientID=n.googleLoginClientID,Array.isArray(b.CFBundleURLTypes)?b.CFBundleURLTypes.push({CFBundleURLSchemes:[n.googleLoginBundleUrlType]}):b.CFBundleURLTypes=[{CFBundleURLSchemes:[n.googleLoginBundleUrlType]}]}if(!0===n.enableIpad)if(Array.isArray(n.iPadUISupportedInterfaceOrientations)){const e={Portrait:"UIInterfaceOrientationPortrait",PortraitUpsideDown:"UIInterfaceOrientationPortraitUpsideDown",LandscapeLeft:"UIInterfaceOrientationLandscapeLeft",LandscapeRight:"UIInterfaceOrientationLandscapeRight"},i=n.iPadUISupportedInterfaceOrientations.map(i=>e[i]).filter(e=>!!e);b["UISupportedInterfaceOrientations~ipad"]=i}else(0,miniappJson_1.iOSAppJsonIsUsingIPadResizable)(e)?(b["UISupportedInterfaceOrientations~ipad"]=["UIInterfaceOrientationPortrait","UIInterfaceOrientationPortraitUpsideDown","UIInterfaceOrientationLandscapeLeft","UIInterfaceOrientationLandscapeRight"],a.progress("ipad is support Landscape")):(b["UISupportedInterfaceOrientations~ipad"]=["UIInterfaceOrientationPortrait","UIInterfaceOrientationPortraitUpsideDown"],a.progress("ipad is not support Landscape"));if(null===(g=n.infoPlist)||void 0===g?void 0:g.LSApplicationQueriesSchemes){const e=n.infoPlist.LSApplicationQueriesSchemes.split(",");e.length&&b.LSApplicationQueriesSchemes.push(...e.filter(e=>e))}try{plist.writeFileSync(I,b)}catch(e){throw new Error("write info.plist failed!!"+e.messenge)}return await this.writeI18NInfoFile(t,s,v),b.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 p,d,c,u,f,_,h;o.progress("update app module info...");const{module_info:y={},cpa_info:g={},cpa_package_info:m={enable_remove_watermark:!1}}=i;if(!g.sdk_key||!g.sdk_key_secret)throw new Error("sdkKey and sdkSecret not found");const S=path_1.default.join(t,"MiniApp.bundle"),I=path_1.default.join(S,"AppConfig.plist"),v=plist.readFileSync(I);m.enable_remove_watermark?v.enableRemoveWatermark=!0:v.splashscreenTheme=r,v.miniModuleId=y.module_id,v.sdkKey=g.sdk_key,v.sdkSecret=g.sdk_key_secret;const{privacy:x={}}=n;v.privacy||(v.privacy={}),v.privacy.enable=!!x.enable,v.privacy.enableViewOnly=!!x.enableViewOnly;const b=path_1.default.posix.join(S,"configs/privacy.json"),{contentViewImage:F,cancelButtonImage:P,confirmButtonImage:j,template:B}=x;if(x.enable){let i=B||"";if(fs_extra_1.default.ensureDirSync(path_1.default.posix.join(S,"configs")),i.startsWith("%")&&i.endsWith("%")){const t=B.slice(1,-1);i=(null===(d=null===(p=null==l?void 0:l.base)||void 0===p?void 0:p.ios)||void 0===d?void 0:d[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(S,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,b),v.privacy.template="configs/privacy.json"):(o.message("error",`未找到隐私协议中配置的文件 ${i},请检查`),v.privacy.template="configs/defaultPrivacy.json")):v.privacy.template="configs/defaultPrivacy.json",!0===x.enableNativePlugin&&"string"==typeof x.nativePluginId&&x.nativePluginId.length>2&&(v.privacy.plugin={pluginId:x.nativePluginId,enable:!0})}else v.privacy.template="",fs_extra_1.default.removeSync(b);this.updatePrivacyBackgroundImage(e,t,o,"contentViewImage",F),this.updatePrivacyBackgroundImage(e,t,o,"confirmButtonImage",j),this.updatePrivacyBackgroundImage(e,t,o,"cancelButtonImage",P);const{appMenuEnable:L=!0}=n;v.appMenuEnable=L;const{enableVConsole:C="undefined"}=n;if(v.enableVConsole=C,null===(c=n.useExtendedSdk)||void 0===c?void 0:c.WeAppLive){const{weAppLiveLicenseUrl:e,weAppLiveLicenseKey:i}=n.liveInfo||{};e&&i&&(v.weAppLiveLicenseUrl=e,v.weAppLiveLicenseKey=i)}const{tpush:w}=n;let A=!1;if("object"==typeof w){const e=path_1.default.posix.join(t,"PlugIns/TPNSService.appex"),i=path_1.default.posix.join(e,"AppConfig.plist");if(this.useTpush(n)){v.TPNSAccessID=w.accessID,v.TPNSAccessKey=w.accessKey,w.clusterDomainName?v.clusterDomainName=w.clusterDomainName:delete v.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,v),A=!0}catch(e){throw new Error("copy TPNSService.appex to app failed: "+e)}}}if(!A)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.");v.qmapAPIKey=n.qmapAPIKey}const{gdt:D}=n,U=this.useGDT(n);if(v.GDTAd=U?{appid:D.appid,enable:!0,SplashAd:{placementId:D.splashAd_placementId,fetchDelay:D.splashAd_fetchDelay||3,defaultEnable:null===(f=D.splashAd_defaultEnable)||void 0===f||f}}:{appid:"",enable:!1,SplashAd:{placementId:"",fetchDelay:3}},n["mini-plugin"]&&Array.isArray(n["mini-plugin"].ios)){const e=n["mini-plugin"].ios,i=e.filter(e=>!!(e.open&&e.pluginId&&e.loadWhenStart)).map(e=>e.pluginId),t=e.map(e=>e.open?{pluginId:e.pluginId,version:e.isFromLocal?"dev":e.pluginVersion}:void 0).filter(e=>e);v.plugins={loadWhenStart:i,pluginInfoList:t}}const{enableDebugLog:$=!1}=n;v.enableDebugLog=$;const{debugLogSizeLimit:E=10}=n;isNaN(Number(E))?o.message("error",`ios debugLogSizeLimit ${E} is NaN`):v.debugLogSizeLimit=Number(E);const{enableOpenUrlNavigate:O=!1}=n;v.enableOpenUrlNavigate=O;const k=path_1.default.posix.join(S,"configs/locales");if(fs_extra_1.default.ensureDirSync(k),null===(h=null===(_=null==l?void 0:l.base)||void 0===_?void 0:_.ios)||void 0===h?void 0:h.LOCALES){const i=this.getMaterialFilePath(e,l.base.ios.LOCALES);fs_extra_1.default.existsSync(i)?(fs_extra_1.default.copyFileSync(i,path_1.default.posix.join(k,"common-base.json")),o.progress("复制基础语言 locales 配置成功")):o.message("error","未找到基础语言 locales 配置文件: "+i)}Object.keys(l).forEach(i=>{var t,n;if("base"===i)return;const a=null===(n=null===(t=l[i])||void 0===t?void 0:t.ios)||void 0===n?void 0:n.LOCALES;if(a){const t=this.getMaterialFilePath(e,a);fs_extra_1.default.existsSync(t)?(fs_extra_1.default.copyFileSync(t,path_1.default.posix.join(k,`common-${i}.json`)),o.progress(`复制 ${i} 语言 locales 配置成功`)):o.message("error",`未找到 ${i} 语言 locales 配置文件: ${t}`)}}),plist.writeFileSync(I,v)}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 p=s.ios_flag&&s.bundle_id||s.debug_ios_bundle_id;l.CFBundleIdentifier=t.tpush.serviceBundleId||p+".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 p=this.getMaterialFilePath(e,t[l]);if(!p)return void a.message("error","getMatrialFailed: "+t[l]);const d=iconInfoMap[l];try{const e=sizeOf(p),i=d.size[0]*d.scale,n=d.size[1]*d.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 c=path_1.default.extname(p),u=1===d.scale?"":`@${d.scale}x`,f=`${d.size[0]}x${d.size[1]}`,_=l.startsWith("ipad"),h="appStore1024"===l||"appStore1024Other"===l,y="appStore1024Other"===l?n+"Other":n,g=path_1.default.join(i,`${y}${f}${u}${_?"~ipad":""}${c}`),m={from:p,to:g,filename:path_1.default.basename(g),size:f,scale:d.scale+"x",idiom:d.idiom,key:l};s.push(m),h||(_?r.includes(`${y}${f}`)||r.push(`${y}${f}${u}`):o.includes(`${y}${f}`)||o.push(`${y}${f}${u}`))}return{iphoneBundleIconFiles:o,ipadBundleIconFiles:r,addFiles:s}}async updateIOSIcons(e,i,t,n,a,s,o=!1,r=""){s.progress("update app icons...");const{icons:l={}}=n,p=(o||a)&&!!t;s.progress("genAssetCar: "+p);const d=glob_1.default.sync("AppIcon*.+(png|jpg|jpeg|webp)",{nodir:!0,cwd:i}).map(e=>path_1.default.join(i,e)),c="AppIcon-"+uuidv4().slice(0,8),u=this.updateBundleIcons(e,i,l,c,s);if(!u)throw new Error("updateBundleIcons failed");const{iphoneBundleIconFiles:f=[],ipadBundleIconFiles:_=[],addFiles:h=[]}=u,y={};for(const e in iconInfoMap){if(!iconInfoMap[e].required||l[e])continue;const i=iconInfoMap[e].size[0]*iconInfoMap[e].scale,t=iconInfoMap[e].size[1]*iconInfoMap[e].scale;if(y[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(y[e]))throw new Error(`required ${e} but not default or set`)}const g=this.updateBundleIcons(e,i,y,c,s);if(!g)throw new Error("updateBundleIcons WithDefaultIcon failed");const{iphoneBundleIconFiles:m,ipadBundleIconFiles:S,addFiles:I}=g;if(f.push(...m),_.push(...S),h.push(...I),!f.length&&!_.length)return;d.forEach(e=>{fs_extra_1.default.existsSync(e)&&fs_extra_1.default.removeSync(e)});const v=path_1.default.join(t,"__assetCarOperateDir/assetsCar/"),x=path_1.default.join(v,`Assets.xcassets/${c}.appiconset/`);p&&(fs_extra_1.default.ensureDirSync(x),fs_extra_1.default.emptyDirSync(x));const b=[];let F=!1;if(h.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),p&&(fs_extra_1.default.copySync(e.from,path_1.default.join(x,e.filename)),"ios-marketing-other"===e.idiom&&(F=!0),b.push({filename:e.filename,size:e.size,scale:e.scale,idiom:e.idiom}))}),p&&fs_extra_1.default.writeJsonSync(path_1.default.join(x,"Contents.json"),{images:b,info:{author:"xcode",version:1}},{spaces:"\t"}),p){const e=path_1.default.join(__dirname,"../../../static/scripts/assetsCar/"),t=path_1.default.join(v,"createAssetsCar");fs_extra_1.default.copySync(e,v);try{await(0,codesign_1.checkXcodeEnv)(s),child_process.execSync(`"${t}" ${c}`,{env:(0,env_1.getProcessEnv)()})}catch(e){throw new Error("createAssetsCar failed "+(e.message||""))}const n=path_1.default.join(v,"build/Assets.car"),a=path_1.default.join(i,"Assets.car");fs_extra_1.default.copyFileSync(n,a)}else if(r&&fs_extra_1.default.existsSync(r))s.message("success","命中缓存,正在使用缓存的 AssetCar"),fs_extra_1.default.copyFileSync(r,path_1.default.join(i,"Assets.car"));else{const e=path_1.default.join(i,"Assets.car");fs_extra_1.default.removeSync(e),s.message("warn","更新 App 图标可能不生效,可使用远程构建验证图标设置;工具将会缓存图标构建结果")}const P=path_1.default.join(i,"Info.plist"),j=plist.readFileSync(P);if(!j.CFBundleIcons){const e={CFBundlePrimaryIcon:{}};j.CFBundleIcons=e}F&&(j.CFBundleIcons.CFBundleAlternateIcons={OtherAppStoreIcon:{CFBundleIconFiles:[c+"Other"],CFBundleIconName:"OtherAppStoreIcon"}}),j.CFBundleIcons.CFBundlePrimaryIcon.CFBundleIconName=c,j.CFBundleIcons.CFBundlePrimaryIcon.CFBundleIconFiles=f,j["CFBundleIcons~ipad"]||(j["CFBundleIcons~ipad"]={CFBundlePrimaryIcon:{}}),j["CFBundleIcons~ipad"].CFBundlePrimaryIcon.CFBundleIconName=c,j["CFBundleIcons~ipad"].CFBundlePrimaryIcon.CFBundleIconFiles=_,j.NSAppTransportSecurity={NSAllowsArbitraryLoads:!0},plist.writeFileSync(P,j)}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),p=t+".png",d="LaunchScreen-"+uuidv4().slice(0,12),c=d+".png",u=path_1.default.join(s,c);fs_extra_1.default.copyFileSync(l,u);const f=Buffer.from(p,"utf-8").toString("hex"),_=Buffer.from(c,"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")),d}replaceLaunchScreenVideo(e,i,t,n){const a=path_1.default.extname(e);if([".mp4",".mov"].indexOf(a)<0)return void i.message("error","IOS 启动页视频配置格式错误,必须为 mp4 mov 格式, 错误配置:"+e);const s=this.getMaterialFilePath(t,e),o=`${"LaunchScreen-"+uuidv4().slice(0,12)}${a}`,r=path_1.default.join(n,o);return fs_extra_1.default.copyFileSync(s,r),o}async updateSplashScreen(e,i,t,n,a="Dark",s){var o,r,l;let p;n.progress("update splashscreen image..."),allowTheme.includes(a)&&(p=path_1.default.join(i,`/Base.lproj/LaunchScreen${a}.storyboardc`)),p&&fs_extra_1.default.existsSync(p)&&fs_extra_1.default.copySync(p,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 d=null===(o=null==t?void 0:t.splashscreen)||void 0===o?void 0:o.customImage;if(!d)return;const c=path_1.default.join(i,"Info.plist"),u=plist.readFileSync(c),f=u.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)}),d.startsWith("%")&&(null==d?void 0:d.endsWith("%"))){const t=d.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},请检查,启动页国际化配置失败`);d=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,d),f,n,e,i);n.progress("update base splashscreen image success"),_&&(u.UISplashScreenImageName=_,u.UILaunchStoryboardName="LaunchScreen",plist.writeFileSync(c,u))}async updateSplashScreenVideo(e,i,t,n,a){var s,o,r;n.progress("update splashscreen video...");let l=null===(s=null==t?void 0:t.splashscreen)||void 0===s?void 0:s.customVideo;if(!l)return;const p=path_1.default.join(i,"Info.plist"),d=plist.readFileSync(p);if(l.startsWith("%")&&(null==l?void 0:l.endsWith("%"))){const t=l.slice(1,-1),s=(null===(r=null===(o=null==a?void 0:a.base)||void 0===o?void 0:o.ios)||void 0===r?void 0:r[t])||"";if(!s)return void n.message("error",`未在国际化配置 base.json 中找到字段 ${t},请检查,启动页视频国际化配置失败`);l=s,Object.keys(a).forEach(s=>{var o,r;if("base"===s)return;const l=null===(r=null===(o=a[s])||void 0===o?void 0:o.ios)||void 0===r?void 0:r[t];if(l){const t=this.replaceLaunchScreenVideo(this.getMaterialFilePath(e,l),n,e,i);n.progress(`update ${s} splashscreen video...`);const a=fs_extra_1.default.readFileSync(path_1.default.join(i,s+".lproj/InfoPlist.strings"),"utf8");let o="";o=t?a.replace("__UISplashScreenVideoName__",`UISplashScreenVideoName = "${t}";\n`):a.replace("__UISplashScreenVideoName__",""),fs_extra_1.default.writeFileSync(path_1.default.join(i,s+".lproj/InfoPlist.strings"),o),n.progress(`update ${s} splashscreen video success`)}})}n.progress("update base splashscreen video...");const c=this.replaceLaunchScreenVideo(this.getMaterialFilePath(e,l),n,e,i);n.progress("update base splashscreen video success"),c&&(d.UISplashScreenVideoName=c,plist.writeFileSync(p,d))}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"),p=fs_extra_1.default.readFileSync(l,"utf-8"),d=this.genUseExtendedSdk(a,s);o.progress("useExtendedSdks: "+JSON.stringify(d));const{mobileapp_info:c={}}=e,u=this.getBundleIdentifier(c);if(d.WeAppOpenFuns&&d.WeAppOpenFuns_HasPay)throw new Error("OpenFuncs SDK 只可勾选使用一个,请按需勾选使用");const f={},_=["WeAppUSB"];for(const e in d){if(!d[e])continue;const i=getDepReg(e),a=p.match(i);if(!(null==a?void 0:a[1])){if(_.includes(e))continue;throw new Error(`拓展模块 ${e} 不存在或已被移除,请检查 project.miniapp.json -> 对应平台 -> useExtendedSdk 删除配置 ${e},版本配置差异请参考更新日志或 https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/miniapp/changelog/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)){if(_.includes(e+".framework"))return;throw new Error(`拓展模块 ${e} 不存在或已被移除,请检查 project.miniapp.json -> 对应平台 -> useExtendedSdk 删除配置 ${e},版本配置差异请参考更新日志或 https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/miniapp/changelog/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,u,e)}}),s.length){f[s.shift()]=s}}const h=path_1.default.join(i,"DyFrameworks.plist");fs_extra_1.default.existsSync(h)&&fs_extra_1.default.removeSync(h),plist.writeFileSync(h,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){const l={},p={},d=[];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&&(l[e.pluginId]=e.resourcePath),"object"==typeof e.resourceObjects&&Object.keys(e.resourceObjects).length>0&&(p[e.pluginId]=e.resourceObjects)):d.push(e.pluginId)})}if(d.length>0&&r.message("warn","下列插件未启用,请确认project.miniapp.json中的配置:"+d.join(", ")),!i.length)return;const c=path_1.default.join(e,"Frameworks"),u=path_1.default.join(e,"PlugIns");fs_extra_1.default.ensureDirSync(c),r.progress("update plugin...");const f=this.prepareAppexProfileConfig(i,n,t,a,s,o,n.version,r);if(!f)throw new Error("依赖的多端插件需要配置对应的profile");i.forEach(i=>{const{pluginId:n}=i,a=i.dir,s=n+".framework",o=path_1.default.join(c,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 d=path_1.default.join(a,s);if(fs_extra_1.default.existsSync(d)){fs_extra_1.default.copySync(d,o),this.copyResourcesToMainBundle(d,e),this.copyUserResourcePathIntoPlugins(n,t,l[n],p[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=f[s],d=path_1.default.join(u,i);if(!o||!0!==o.enable)return;r.progress(`${n} 插件使用 appex 中 : ${i}`),fs_extra_1.default.existsSync(d)&&fs_extra_1.default.removeSync(d),fs_extra_1.default.ensureDirSync(d);const c=path_1.default.join(a,i);fs_extra_1.default.copySync(c,d),(null==o?void 0:o.profilePath)&&fs_extra_1.default.copySync(o.profilePath,path_1.default.join(d,"embedded.mobileprovision")),this.copyResourcesToMainBundle(c,e),this.copyUserResourcePathIntoPlugins(n,t,l[n],p[n],path_1.default.join(d,"MiniPlugin.bundle"),r)}else if(i.endsWith("framework")&&i!==s){const e=path_1.default.join(c,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,l[n],p[n],path_1.default.join(o,"MiniPlugin.bundle"),r)})}copyUserResourcePathIntoPlugins(e,i,t,n,a,s){const o=a;if(t){const n=path_1.default.basename(t),a=this.getMaterialFilePath(i,t);if(a){s.progress(`${e}.framework 正在拷贝配置的资源:${t}`);const i=fs_extra_1.default.lstatSync(a);fs_extra_1.default.ensureDirSync(o),i.isDirectory()?fs_extra_1.default.copySync(a,o):i.isFile()&&fs_extra_1.default.copyFileSync(a,path_1.default.join(o,n))}}if(n){s.progress(e+".framework 正在写入配置的资源"),fs_extra_1.default.ensureDirSync(o);for(const e in n){const i=n[e],t=path_1.default.join(o,e);fs_extra_1.default.ensureDirSync(o),fs_extra_1.default.ensureFileSync(t),fs_extra_1.default.writeFileSync(t,i)}}}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 p={};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}`;p[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)?(p[s].bundleID=n.bundleID,p[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=p[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)(p)){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 p)i[e]={bundleID:p[e].bundleID,profilePath:p[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(p).map(e=>{const i=p[e];return`pluginAppexName:${e};_;_;bundleID:${i.bundleID};_;_;profile:${i.profilePath}\n\n`}).join("");fs_extra_1.default.writeFileSync(t,a)}return p}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;s=this.polyfillUniversalLink(s);let o=[];t.universalLink&&(o=t.universalLink.split(","),o=o.filter(e=>"string"==typeof e&&e.length>0).map(e=>this.polyfillUniversalLink(e)));let r=[];if(Array.isArray(t.__customAssociatedDomains)){r=(t.__customAssociatedDomains||[]).filter(e=>"string"==typeof e&&e.length>0).map(e=>this.polyfillUniversalLink(e))}return{"com.apple.developer.associated-domains":[s,...o,...r].join("_$_ULinK_$_")}}polyfillUniversalLink(e){let i=e;return(i.startsWith("https://")||i.startsWith("http://"))&&(i=i.replace(/^http(s)?:\/\//g,"applinks:")),i}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:p,pluginDirList:d,inLandun:c,theme:u,i18nInfo:f,debugInfo:_,CILocalBuild:h,cacheAssetCarPath:y}=e,g=this.generateTempDemoIpaPath(n),{selfCertificate:m={}}=r,S=(null==m?void 0:m.isPublish)||!1,I=(0,miniappJson_1.tryGetIOSMiniappJson)(t),v=this.useTpush(I);if((0,lodash_1.isEmpty)(I))throw new Error("获取project.miniapp.json失败");if(errorIOSSdkVersions.includes(I.sdkVersion))throw new Error("当前 mini-ios.sdkVersion 存在缺陷,请参考更新日志进行修改");let x=o;if(r.signType===miniapp_builder_1.miniappSinTypes.appleId.type){const{mobileapp_info:e={}}=x;x=Object.assign(Object.assign({},x),{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 this.updateIOSInfoPlistInfo(t,x,g,I,i,f);await this.updateIOSAppConfigPlistInfo(t,x,g,I,a,!1,i,u,f),await this.updateIOSAppexInfoPlistInfo(x,g,I,b,i),await this.updateIOSIcons(t,g,p,I,S,i,!0===c,y),await this.updateSplashScreen(t,g,I,i,u,f),await this.updateSplashScreenVideo(t,g,I,i,f),await this.updateExtendedSdk(x,g,a,s,I,_,i),await this.updatePlugin(g,d,t,I,p,S,b,i),await this.updatePrivacyInfo(g,I,i),await this.updateIOSAppResource(t,g,I,i);const F=await this.getEntitlements(x,g,I,i),{mobileapp_info:P={}}=x;let j;j=r.signType===miniapp_builder_1.miniappSinTypes.appleId.type?miniapp_builder_1.DEFAULT_BUNDLE_ID:P.ios_flag&&P.bundle_id||P.debug_ios_bundle_id;const B={bundleId:j,output:l,entitlements:F,isPublish:m.isPublish};if(I.buildCloud&&(I.buildCloud.certificate&&"string"==typeof I.buildCloud.certificate&&(B.certificate=I.buildCloud.certificate),I.buildCloud.profile&&"string"==typeof I.buildCloud.profile&&(B.profile=path_1.default.join(t,I.buildCloud.profile)),v&&I.buildCloud.tpnsProfile&&"string"==typeof I.buildCloud.tpnsProfile&&(B.tpnsProfile=path_1.default.join(t,I.buildCloud.tpnsProfile))),h&&(B.profile=m.profilePath,B.certificate=m.certificateName),m.isPublish||h){const e=await(0,codesign_1.codesignAndExport)(t,g,p||"",B,i,v,!0===c);if(!0!==e.success)throw new Error("Build ipa failed:"+(e.errMsg||"codesignAndExport failed"))}return{projectPath:t,demoIpaPath:g,opts:B,iosMiniappJson:I,isPublish:S}}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?"UISplashScreenVideoName"!==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+="__UISplashScreenVideoName__\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:""}updateIOSAppResource(e,i,t,n){const a=t.resourcePath;if(!a)return;const s=this.getMaterialFilePath(e,a);if(s){n.progress("正在拷贝资源至主包:"+s);const e=fs_extra_1.default.lstatSync(s);if(e.isDirectory())this.copyDirectory(s,i,!1);else if(e.isFile()){const e=path_1.default.basename(a),t=path_1.default.join(i,e);if(fs_extra_1.default.existsSync(t))throw new Error(`fail to copy ${s}, overwrite is not allowed`);fs_extra_1.default.copyFileSync(s,t)}}}copyDirectory(e,i,t=!0){if(fs_extra_1.default.ensureDirSync(i),t)fs_extra_1.default.copySync(e,i);else{fs_extra_1.default.readdirSync(e).forEach(n=>{const a=path_1.default.join(e,n),s=path_1.default.join(i,n);if(fs_extra_1.default.statSync(a).isDirectory())this.copyDirectory(a,s,t);else{if(fs_extra_1.default.existsSync(s))throw new Error(`fail to copy ${a}, overwrite is not allowed`);fs_extra_1.default.copyFileSync(a,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&&(Array.isArray(e.CFBundleURLSchemes)?i.CFBundleURLSchemes=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,p,d,c,u,f,_,h,y,g;a.progress("update app base info...");const{mobileapp_info:m={}}=i,S=m.mobileapp_id,I=path_1.default.join(t,"Info.plist"),v={},x=(e,i)=>{var t,n;if((null==i?void 0:i.startsWith("%"))&&(null==i?void 0:i.endsWith("%"))){const o=i.slice(1,-1);v[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};x("UISplashScreenImageName",null===(o=null==n?void 0:n.splashscreen)||void 0===o?void 0:o.customImage),x("UISplashScreenVideoName",null===(r=null==n?void 0:n.splashscreen)||void 0===r?void 0:r.customVideo),x("UILaunchStoryboardName",null===(l=null==n?void 0:n.splashscreen)||void 0===l?void 0:l.customImage);const b=plist.readFileSync(I);if(b.UIBackgroundModes=[],!0===(null===(p=null==n?void 0:n.infoPlist)||void 0===p?void 0:p.AudioInBackgroundMode)&&b.UIBackgroundModes.push("audio"),!0===(null===(d=null==n?void 0:n.infoPlist)||void 0===d?void 0:d.LocationInBackgroundMode)&&b.UIBackgroundModes.push("location"),"object"==typeof n.customInfoPlist&&!Array.isArray(n.customInfoPlist)){a.progress("initiating user custom info.plist config");const e=n.customInfoPlist;for(const i in e)b[i]=e[i]}if(b.CFBundleName=x("CFBundleName",n.name),b.CFBundleDisplayName=x("CFBundleDisplayName",n.name),b.CFBundleShortVersionString=n.version,"number"==typeof n.versionCode?b.CFBundleVersion=parseInt(n.versionCode.toString(),10).toString():b.CFBundleVersion=(parseInt(b.CFBundleVersion,10)+1).toString(),b.CFBundleIdentifier=this.getBundleIdentifier(m),Array.isArray(null==n?void 0:n.openMimeTypes)&&this.validateCFBundleDocumentTypes(n.openMimeTypes,a)&&(b.CFBundleDocumentTypes=n.openMimeTypes,a.message("doing","openMimeTypes 应用成功")),Array.isArray(b.CFBundleURLTypes)||(b.CFBundleURLTypes=[]),(null===(u=null===(c=b.CFBundleURLTypes)||void 0===c?void 0:c[0])||void 0===u?void 0:u.CFBundleURLSchemes)&&(b.CFBundleURLTypes[0].CFBundleURLSchemes=[S]),b.CFBundleURLTypes[0]&&(b.CFBundleURLTypes=[b.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])?b[e]=x(e,null===(t=n.privateDescriptions)||void 0===t?void 0:t[e]):delete b[e]}),!0===(null===(f=null==n?void 0:n.infoPlist)||void 0===f?void 0:f.DisableAppUsesNonExemptEncryption)?b.ITSAppUsesNonExemptEncryption=!1:delete b.ITSAppUsesNonExemptEncryption,!0===(null===(_=null==n?void 0:n.infoPlist)||void 0===_?void 0:_.requiresFullScreen)?b.UIRequiresFullScreen=!0:delete b.UIRequiresFullScreen,"object"==typeof(null===(h=null==n?void 0:n.infoPlist)||void 0===h?void 0:h.CFBundleURLTypes)){const e=this.generateInfoPlistCFBundleURLTypesItem(n.infoPlist.CFBundleURLTypes);b.CFBundleURLTypes.push(e);const{additionalCFBundleURLTypes:i}=n.infoPlist.CFBundleURLTypes;Array.isArray(i)&&i.forEach(e=>{if("object"==typeof e){const i=this.generateInfoPlistCFBundleURLTypesItem(e);b.CFBundleURLTypes.push(i)}})}if(null===(y=null==n?void 0:n.useExtendedSdk)||void 0===y?void 0:y.WeAppGoogleLogin){if(!(null==n?void 0:n.googleLoginClientID)||!(null==n?void 0:n.googleLoginBundleUrlType))throw new Error("勾选了 Google Login 拓展模块但未填写 googleLoginClientID 或 googleLoginBundleUrlType 将导致拓展模块无法使用");b.GIDClientID=n.googleLoginClientID,Array.isArray(b.CFBundleURLTypes)?b.CFBundleURLTypes.push({CFBundleURLSchemes:[n.googleLoginBundleUrlType]}):b.CFBundleURLTypes=[{CFBundleURLSchemes:[n.googleLoginBundleUrlType]}]}if(!0===n.enableIpad)if(Array.isArray(n.iPadUISupportedInterfaceOrientations)){const e={Portrait:"UIInterfaceOrientationPortrait",PortraitUpsideDown:"UIInterfaceOrientationPortraitUpsideDown",LandscapeLeft:"UIInterfaceOrientationLandscapeLeft",LandscapeRight:"UIInterfaceOrientationLandscapeRight"},i=n.iPadUISupportedInterfaceOrientations.map(i=>e[i]).filter(e=>!!e);b["UISupportedInterfaceOrientations~ipad"]=i}else(0,miniappJson_1.iOSAppJsonIsUsingIPadResizable)(e)?(b["UISupportedInterfaceOrientations~ipad"]=["UIInterfaceOrientationPortrait","UIInterfaceOrientationPortraitUpsideDown","UIInterfaceOrientationLandscapeLeft","UIInterfaceOrientationLandscapeRight"],a.progress("ipad is support Landscape")):(b["UISupportedInterfaceOrientations~ipad"]=["UIInterfaceOrientationPortrait","UIInterfaceOrientationPortraitUpsideDown"],a.progress("ipad is not support Landscape"));if(null===(g=n.infoPlist)||void 0===g?void 0:g.LSApplicationQueriesSchemes){const e=n.infoPlist.LSApplicationQueriesSchemes.split(",");e.length&&b.LSApplicationQueriesSchemes.push(...e.filter(e=>e))}try{plist.writeFileSync(I,b)}catch(e){throw new Error("write info.plist failed!!"+e.messenge)}return await this.writeI18NInfoFile(t,s,v),b.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 p,d,c,u,f,_,h;o.progress("update app module info...");const{module_info:y={},cpa_info:g={},cpa_package_info:m={enable_remove_watermark:!1}}=i;if(!g.sdk_key||!g.sdk_key_secret)throw new Error("sdkKey and sdkSecret not found");const S=path_1.default.join(t,"MiniApp.bundle"),I=path_1.default.join(S,"AppConfig.plist"),v=plist.readFileSync(I);m.enable_remove_watermark?v.enableRemoveWatermark=!0:v.splashscreenTheme=r,v.miniModuleId=y.module_id,v.sdkKey=g.sdk_key,v.sdkSecret=g.sdk_key_secret;const{privacy:x={}}=n;v.privacy||(v.privacy={}),v.privacy.enable=!!x.enable,v.privacy.enableViewOnly=!!x.enableViewOnly;const b=path_1.default.posix.join(S,"configs/privacy.json"),{contentViewImage:F,cancelButtonImage:P,confirmButtonImage:j,template:B}=x;if(x.enable){let i=B||"";if(fs_extra_1.default.ensureDirSync(path_1.default.posix.join(S,"configs")),i.startsWith("%")&&i.endsWith("%")){const t=B.slice(1,-1);i=(null===(d=null===(p=null==l?void 0:l.base)||void 0===p?void 0:p.ios)||void 0===d?void 0:d[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(S,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,b),v.privacy.template="configs/privacy.json"):(o.message("error",`未找到隐私协议中配置的文件 ${i},请检查`),v.privacy.template="configs/defaultPrivacy.json")):v.privacy.template="configs/defaultPrivacy.json",!0===x.enableNativePlugin&&"string"==typeof x.nativePluginId&&x.nativePluginId.length>2&&(v.privacy.plugin={pluginId:x.nativePluginId,enable:!0})}else v.privacy.template="",fs_extra_1.default.removeSync(b);this.updatePrivacyBackgroundImage(e,t,o,"contentViewImage",F),this.updatePrivacyBackgroundImage(e,t,o,"confirmButtonImage",j),this.updatePrivacyBackgroundImage(e,t,o,"cancelButtonImage",P);const{appMenuEnable:L=!0}=n;v.appMenuEnable=L;const{enableVConsole:C="undefined"}=n;if(v.enableVConsole=C,null===(c=n.useExtendedSdk)||void 0===c?void 0:c.WeAppLive){const{weAppLiveLicenseUrl:e,weAppLiveLicenseKey:i}=n.liveInfo||{};e&&i&&(v.weAppLiveLicenseUrl=e,v.weAppLiveLicenseKey=i)}const{tpush:w}=n;let A=!1;if("object"==typeof w){const e=path_1.default.posix.join(t,"PlugIns/TPNSService.appex"),i=path_1.default.posix.join(e,"AppConfig.plist");if(this.useTpush(n)){v.TPNSAccessID=w.accessID,v.TPNSAccessKey=w.accessKey,w.clusterDomainName?v.clusterDomainName=w.clusterDomainName:delete v.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,v),A=!0}catch(e){throw new Error("copy TPNSService.appex to app failed: "+e)}}}if(!A)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.");v.qmapAPIKey=n.qmapAPIKey}const{gdt:U}=n,D=this.useGDT(n);if(v.GDTAd=D?{appid:U.appid,enable:!0,SplashAd:{placementId:U.splashAd_placementId,fetchDelay:U.splashAd_fetchDelay||3,defaultEnable:null===(f=U.splashAd_defaultEnable)||void 0===f||f}}:{appid:"",enable:!1,SplashAd:{placementId:"",fetchDelay:3}},n["mini-plugin"]&&Array.isArray(n["mini-plugin"].ios)){const e=n["mini-plugin"].ios,i=e.filter(e=>!!(e.open&&e.pluginId&&e.loadWhenStart)).map(e=>e.pluginId),t=e.map(e=>e.open?{pluginId:e.pluginId,version:e.isFromLocal?"dev":e.pluginVersion}:void 0).filter(e=>e);v.plugins={loadWhenStart:i,pluginInfoList:t}}const{enableDebugLog:$=!1}=n;v.enableDebugLog=$;const{debugLogSizeLimit:E=10}=n;isNaN(Number(E))?o.message("error",`ios debugLogSizeLimit ${E} is NaN`):v.debugLogSizeLimit=Number(E);const{enableOpenUrlNavigate:O=!1}=n;v.enableOpenUrlNavigate=O;const k=path_1.default.posix.join(S,"configs/locales");if(fs_extra_1.default.ensureDirSync(k),null===(h=null===(_=null==l?void 0:l.base)||void 0===_?void 0:_.ios)||void 0===h?void 0:h.LOCALES){const i=this.getMaterialFilePath(e,l.base.ios.LOCALES);fs_extra_1.default.existsSync(i)?(fs_extra_1.default.copyFileSync(i,path_1.default.posix.join(k,"common-base.json")),o.progress("复制基础语言 locales 配置成功")):o.message("error","未找到基础语言 locales 配置文件: "+i)}Object.keys(l).forEach(i=>{var t,n;if("base"===i)return;const a=null===(n=null===(t=l[i])||void 0===t?void 0:t.ios)||void 0===n?void 0:n.LOCALES;if(a){const t=this.getMaterialFilePath(e,a);fs_extra_1.default.existsSync(t)?(fs_extra_1.default.copyFileSync(t,path_1.default.posix.join(k,`common-${i}.json`)),o.progress(`复制 ${i} 语言 locales 配置成功`)):o.message("error",`未找到 ${i} 语言 locales 配置文件: ${t}`)}}),plist.writeFileSync(I,v)}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 p=s.ios_flag&&s.bundle_id||s.debug_ios_bundle_id;l.CFBundleIdentifier=t.tpush.serviceBundleId||p+".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 p=this.getMaterialFilePath(e,t[l]);if(!p)return void a.message("error","getMatrialFailed: "+t[l]);const d=iconInfoMap[l];try{const e=sizeOf(p),i=d.size[0]*d.scale,n=d.size[1]*d.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 c=path_1.default.extname(p),u=1===d.scale?"":`@${d.scale}x`,f=`${d.size[0]}x${d.size[1]}`,_=l.startsWith("ipad"),h="appStore1024"===l||"appStore1024Other"===l,y="appStore1024Other"===l?n+"Other":n,g=path_1.default.join(i,`${y}${f}${u}${_?"~ipad":""}${c}`),m={from:p,to:g,filename:path_1.default.basename(g),size:f,scale:d.scale+"x",idiom:d.idiom,key:l};s.push(m),h||(_?r.includes(`${y}${f}`)||r.push(`${y}${f}${u}`):o.includes(`${y}${f}`)||o.push(`${y}${f}${u}`))}return{iphoneBundleIconFiles:o,ipadBundleIconFiles:r,addFiles:s}}async updateIOSIcons(e,i,t,n,a,s,o=!1,r=""){s.progress("update app icons...");const{icons:l={}}=n,p=(o||a)&&!!t;s.progress("genAssetCar: "+p);const d=glob_1.default.sync("AppIcon*.+(png|jpg|jpeg|webp)",{nodir:!0,cwd:i}).map(e=>path_1.default.join(i,e)),c="AppIcon-"+uuidv4().slice(0,8),u=this.updateBundleIcons(e,i,l,c,s);if(!u)throw new Error("updateBundleIcons failed");const{iphoneBundleIconFiles:f=[],ipadBundleIconFiles:_=[],addFiles:h=[]}=u,y={};for(const e in iconInfoMap){if(!iconInfoMap[e].required||l[e])continue;const i=iconInfoMap[e].size[0]*iconInfoMap[e].scale,t=iconInfoMap[e].size[1]*iconInfoMap[e].scale;if(y[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(y[e]))throw new Error(`required ${e} but not default or set`)}const g=this.updateBundleIcons(e,i,y,c,s);if(!g)throw new Error("updateBundleIcons WithDefaultIcon failed");const{iphoneBundleIconFiles:m,ipadBundleIconFiles:S,addFiles:I}=g;if(f.push(...m),_.push(...S),h.push(...I),!f.length&&!_.length)return;d.forEach(e=>{fs_extra_1.default.existsSync(e)&&fs_extra_1.default.removeSync(e)});const v=path_1.default.join(t,"__assetCarOperateDir/assetsCar/"),x=path_1.default.join(v,`Assets.xcassets/${c}.appiconset/`);p&&(fs_extra_1.default.ensureDirSync(x),fs_extra_1.default.emptyDirSync(x));const b=[];let F=!1;if(h.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),p&&(fs_extra_1.default.copySync(e.from,path_1.default.join(x,e.filename)),"ios-marketing-other"===e.idiom&&(F=!0),b.push({filename:e.filename,size:e.size,scale:e.scale,idiom:e.idiom}))}),p&&fs_extra_1.default.writeJsonSync(path_1.default.join(x,"Contents.json"),{images:b,info:{author:"xcode",version:1}},{spaces:"\t"}),p){const e=path_1.default.join(__dirname,"../../../static/scripts/assetsCar/"),t=path_1.default.join(v,"createAssetsCar");fs_extra_1.default.copySync(e,v);try{await(0,codesign_1.checkXcodeEnv)(s),child_process.execSync(`"${t}" ${c}`,{env:(0,env_1.getProcessEnv)()})}catch(e){throw new Error("createAssetsCar failed "+(e.message||""))}const n=path_1.default.join(v,"build/Assets.car"),a=path_1.default.join(i,"Assets.car");fs_extra_1.default.copyFileSync(n,a)}else if(r&&fs_extra_1.default.existsSync(r))s.message("success","命中缓存,正在使用缓存的 AssetCar"),fs_extra_1.default.copyFileSync(r,path_1.default.join(i,"Assets.car"));else{const e=path_1.default.join(i,"Assets.car");fs_extra_1.default.removeSync(e),s.message("warn","更新 App 图标可能不生效,可使用远程构建验证图标设置;工具将会缓存图标构建结果")}const P=path_1.default.join(i,"Info.plist"),j=plist.readFileSync(P);if(!j.CFBundleIcons){const e={CFBundlePrimaryIcon:{}};j.CFBundleIcons=e}F&&(j.CFBundleIcons.CFBundleAlternateIcons={OtherAppStoreIcon:{CFBundleIconFiles:[c+"Other"],CFBundleIconName:"OtherAppStoreIcon"}}),j.CFBundleIcons.CFBundlePrimaryIcon.CFBundleIconName=c,j.CFBundleIcons.CFBundlePrimaryIcon.CFBundleIconFiles=f,j["CFBundleIcons~ipad"]||(j["CFBundleIcons~ipad"]={CFBundlePrimaryIcon:{}}),j["CFBundleIcons~ipad"].CFBundlePrimaryIcon.CFBundleIconName=c,j["CFBundleIcons~ipad"].CFBundlePrimaryIcon.CFBundleIconFiles=_,j.NSAppTransportSecurity={NSAllowsArbitraryLoads:!0},plist.writeFileSync(P,j)}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),p=t+".png",d="LaunchScreen-"+uuidv4().slice(0,12),c=d+".png",u=path_1.default.join(s,c);fs_extra_1.default.copyFileSync(l,u);const f=Buffer.from(p,"utf-8").toString("hex"),_=Buffer.from(c,"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")),d}replaceLaunchScreenVideo(e,i,t,n){const a=path_1.default.extname(e);if([".mp4",".mov"].indexOf(a)<0)return void i.message("error","IOS 启动页视频配置格式错误,必须为 mp4 mov 格式, 错误配置:"+e);const s=this.getMaterialFilePath(t,e),o=`${"LaunchScreen-"+uuidv4().slice(0,12)}${a}`,r=path_1.default.join(n,o);return fs_extra_1.default.copyFileSync(s,r),o}async updateSplashScreen(e,i,t,n,a="Dark",s){var o,r,l;let p;n.progress("update splashscreen image..."),allowTheme.includes(a)&&(p=path_1.default.join(i,`/Base.lproj/LaunchScreen${a}.storyboardc`)),p&&fs_extra_1.default.existsSync(p)&&fs_extra_1.default.copySync(p,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 d=null===(o=null==t?void 0:t.splashscreen)||void 0===o?void 0:o.customImage;if(!d)return;const c=path_1.default.join(i,"Info.plist"),u=plist.readFileSync(c),f=u.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)}),d.startsWith("%")&&(null==d?void 0:d.endsWith("%"))){const t=d.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},请检查,启动页国际化配置失败`);d=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,d),f,n,e,i);n.progress("update base splashscreen image success"),_&&(u.UISplashScreenImageName=_,u.UILaunchStoryboardName="LaunchScreen",plist.writeFileSync(c,u))}async updateSplashScreenVideo(e,i,t,n,a){var s,o,r;n.progress("update splashscreen video...");let l=null===(s=null==t?void 0:t.splashscreen)||void 0===s?void 0:s.customVideo;if(!l)return;const p=path_1.default.join(i,"Info.plist"),d=plist.readFileSync(p);if(l.startsWith("%")&&(null==l?void 0:l.endsWith("%"))){const t=l.slice(1,-1),s=(null===(r=null===(o=null==a?void 0:a.base)||void 0===o?void 0:o.ios)||void 0===r?void 0:r[t])||"";if(!s)return void n.message("error",`未在国际化配置 base.json 中找到字段 ${t},请检查,启动页视频国际化配置失败`);l=s,Object.keys(a).forEach(s=>{var o,r;if("base"===s)return;const l=null===(r=null===(o=a[s])||void 0===o?void 0:o.ios)||void 0===r?void 0:r[t];if(l){const t=this.replaceLaunchScreenVideo(this.getMaterialFilePath(e,l),n,e,i);n.progress(`update ${s} splashscreen video...`);const a=fs_extra_1.default.readFileSync(path_1.default.join(i,s+".lproj/InfoPlist.strings"),"utf8");let o="";o=t?a.replace("__UISplashScreenVideoName__",`UISplashScreenVideoName = "${t}";\n`):a.replace("__UISplashScreenVideoName__",""),fs_extra_1.default.writeFileSync(path_1.default.join(i,s+".lproj/InfoPlist.strings"),o),n.progress(`update ${s} splashscreen video success`)}})}n.progress("update base splashscreen video...");const c=this.replaceLaunchScreenVideo(this.getMaterialFilePath(e,l),n,e,i);n.progress("update base splashscreen video success"),c&&(d.UISplashScreenVideoName=c,plist.writeFileSync(p,d))}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"),p=fs_extra_1.default.readFileSync(l,"utf-8"),d=this.genUseExtendedSdk(a,s);o.progress("useExtendedSdks: "+JSON.stringify(d));const{mobileapp_info:c={}}=e,u=this.getBundleIdentifier(c);if(d.WeAppOpenFuns&&d.WeAppOpenFuns_HasPay)throw new Error("OpenFuncs SDK 只可勾选使用一个,请按需勾选使用");const f={},_=["WeAppUSB"];for(const e in d){if(!d[e])continue;const i=getDepReg(e),a=p.match(i);if(!(null==a?void 0:a[1])){if(_.includes(e))continue;throw new Error(`拓展模块 ${e} 不存在或已被移除,请检查 project.miniapp.json -> 对应平台 -> useExtendedSdk 删除配置 ${e},版本配置差异请参考更新日志或 https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/miniapp/changelog/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)){if(_.includes(e+".framework"))return;throw new Error(`拓展模块 ${e} 不存在或已被移除,请检查 project.miniapp.json -> 对应平台 -> useExtendedSdk 删除配置 ${e},版本配置差异请参考更新日志或 https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/miniapp/changelog/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,u,e)}}),s.length){f[s.shift()]=s}}const h=path_1.default.join(i,"DyFrameworks.plist");fs_extra_1.default.existsSync(h)&&fs_extra_1.default.removeSync(h),plist.writeFileSync(h,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){const l={},p={},d=[];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&&(l[e.pluginId]=e.resourcePath),"object"==typeof e.resourceObjects&&Object.keys(e.resourceObjects).length>0&&(p[e.pluginId]=e.resourceObjects)):d.push(e.pluginId)})}if(d.length>0&&r.message("warn","下列插件未启用,请确认project.miniapp.json中的配置:"+d.join(", ")),!i.length)return;const c=path_1.default.join(e,"Frameworks"),u=path_1.default.join(e,"PlugIns");fs_extra_1.default.ensureDirSync(c),r.progress("update plugin...");const f=this.prepareAppexProfileConfig(i,n,t,a,s,o,n.version,r);if(!f)throw new Error("依赖的多端插件需要配置对应的profile");i.forEach(i=>{const{pluginId:n}=i,a=i.dir,s=n+".framework",o=path_1.default.join(c,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 d=path_1.default.join(a,s);if(fs_extra_1.default.existsSync(d)){fs_extra_1.default.copySync(d,o),this.copyResourcesToMainBundle(d,e),this.copyUserResourcePathIntoPlugins(n,t,l[n],p[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=f[s],d=path_1.default.join(u,i);if(!o||!0!==o.enable)return;r.progress(`${n} 插件使用 appex 中 : ${i}`),fs_extra_1.default.existsSync(d)&&fs_extra_1.default.removeSync(d),fs_extra_1.default.ensureDirSync(d);const c=path_1.default.join(a,i);fs_extra_1.default.copySync(c,d),(null==o?void 0:o.profilePath)&&fs_extra_1.default.copySync(o.profilePath,path_1.default.join(d,"embedded.mobileprovision")),this.copyResourcesToMainBundle(c,e),this.copyUserResourcePathIntoPlugins(n,t,l[n],p[n],path_1.default.join(d,"MiniPlugin.bundle"),r)}else if(i.endsWith("framework")&&i!==s){const e=path_1.default.join(c,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,l[n],p[n],path_1.default.join(o,"MiniPlugin.bundle"),r)})}copyUserResourcePathIntoPlugins(e,i,t,n,a,s){const o=a;if(t){const n=path_1.default.basename(t),a=this.getMaterialFilePath(i,t);if(a){s.progress(`${e}.framework 正在拷贝配置的资源:${t}`);const i=fs_extra_1.default.lstatSync(a);fs_extra_1.default.ensureDirSync(o),i.isDirectory()?fs_extra_1.default.copySync(a,o):i.isFile()&&fs_extra_1.default.copyFileSync(a,path_1.default.join(o,n))}}if(n){s.progress(e+".framework 正在写入配置的资源"),fs_extra_1.default.ensureDirSync(o);for(const e in n){const i=n[e],t=path_1.default.join(o,e);fs_extra_1.default.ensureDirSync(o),fs_extra_1.default.ensureFileSync(t),fs_extra_1.default.writeFileSync(t,i)}}}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 p={};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}`;p[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)?(p[s].bundleID=n.bundleID,p[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=p[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)(p)){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 p)i[e]={bundleID:p[e].bundleID,profilePath:p[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(p).map(e=>{const i=p[e];return`pluginAppexName:${e};_;_;bundleID:${i.bundleID};_;_;profile:${i.profilePath}\n\n`}).join("");fs_extra_1.default.writeFileSync(t,a)}return p}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;s=this.polyfillUniversalLink(s);let o=[];t.universalLink&&(o=t.universalLink.split(","),o=o.filter(e=>"string"==typeof e&&e.length>0).map(e=>this.polyfillUniversalLink(e)));let r=[];if(Array.isArray(t.__customAssociatedDomains)){r=(t.__customAssociatedDomains||[]).filter(e=>"string"==typeof e&&e.length>0).map(e=>this.polyfillUniversalLink(e))}return{"com.apple.developer.associated-domains":[s,...o,...r].join("_$_ULinK_$_")}}polyfillUniversalLink(e){let i=e;return(i.startsWith("https://")||i.startsWith("http://"))&&(i=i.replace(/^http(s)?:\/\//g,"applinks:")),i}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:p,pluginDirList:d,inLandun:c,theme:u,i18nInfo:f,debugInfo:_,CILocalBuild:h,cacheAssetCarPath:y}=e,g=this.generateTempDemoIpaPath(n),{selfCertificate:m={}}=r,S=(null==m?void 0:m.isPublish)||!1,I=(0,miniappJson_1.tryGetIOSMiniappJson)(t),v=this.useTpush(I);if((0,lodash_1.isEmpty)(I))throw new Error("获取project.miniapp.json失败");if(errorIOSSdkVersions.includes(I.sdkVersion))throw new Error("当前 mini-ios.sdkVersion 存在缺陷,请参考更新日志进行修改");let x=o;if(r.signType===miniapp_builder_1.miniappSinTypes.appleId.type){const{mobileapp_info:e={}}=x;x=Object.assign(Object.assign({},x),{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 this.updateIOSInfoPlistInfo(t,x,g,I,i,f);await this.updateIOSAppConfigPlistInfo(t,x,g,I,a,!1,i,u,f),await this.updateIOSAppexInfoPlistInfo(x,g,I,b,i),await this.updateIOSIcons(t,g,p,I,S,i,!0===c,y),await this.updateSplashScreen(t,g,I,i,u,f),await this.updateSplashScreenVideo(t,g,I,i,f),await this.updateExtendedSdk(x,g,a,s,I,_,i),await this.updatePlugin(g,d,t,I,p,S,b,i),await this.updatePrivacyInfo(g,I,i),await this.updateIOSAppResource(t,g,I,i);const F=await this.getEntitlements(x,g,I,i),{mobileapp_info:P={}}=x;let j;j=r.signType===miniapp_builder_1.miniappSinTypes.appleId.type?miniapp_builder_1.DEFAULT_BUNDLE_ID:P.ios_flag&&P.bundle_id||P.debug_ios_bundle_id;const B={bundleId:j,output:l,entitlements:F,isPublish:m.isPublish};if(I.buildCloud&&(I.buildCloud.certificate&&"string"==typeof I.buildCloud.certificate&&(B.certificate=I.buildCloud.certificate),I.buildCloud.profile&&"string"==typeof I.buildCloud.profile&&(B.profile=path_1.default.join(t,I.buildCloud.profile)),v&&I.buildCloud.tpnsProfile&&"string"==typeof I.buildCloud.tpnsProfile&&(B.tpnsProfile=path_1.default.join(t,I.buildCloud.tpnsProfile))),h&&(B.profile=m.profilePath,B.certificate=m.certificateName),m.isPublish||h){const e=await(0,codesign_1.codesignAndExport)(t,g,p||"",B,i,v,!0===c);if(!0!==e.success)throw new Error("Build ipa failed:"+(e.errMsg||"codesignAndExport failed"))}return{projectPath:t,demoIpaPath:g,opts:B,iosMiniappJson:I,isPublish:S}}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?"UISplashScreenVideoName"!==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+="__UISplashScreenVideoName__\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:""}updateIOSAppResource(e,i,t,n){const a=t.resourcePath;if(!a)return;const s=this.getMaterialFilePath(e,a);if(s){n.progress("正在拷贝资源至主包:"+s);const e=fs_extra_1.default.lstatSync(s);if(e.isDirectory())this.copyDirectory(s,i,!1);else if(e.isFile()){const e=path_1.default.basename(a),t=path_1.default.join(i,e);if(fs_extra_1.default.existsSync(t))throw new Error(`fail to copy ${s}, overwrite is not allowed`);fs_extra_1.default.copyFileSync(s,t)}}}copyDirectory(e,i,t=!0){if(fs_extra_1.default.ensureDirSync(i),t)fs_extra_1.default.copySync(e,i);else{fs_extra_1.default.readdirSync(e).forEach(n=>{const a=path_1.default.join(e,n),s=path_1.default.join(i,n);if(fs_extra_1.default.statSync(a).isDirectory())this.copyDirectory(a,s,t);else{if(fs_extra_1.default.existsSync(s))throw new Error(`fail to copy ${a}, overwrite is not allowed`);fs_extra_1.default.copyFileSync(a,s)}})}}}exports.default=new buildCloudManager;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.uploadToCosInCI=exports.uploadToCosCore=void 0;const COS=require("cos-js-sdk-v5"),COSForNode=require("cos-nodejs-sdk-v5"),fs=require("fs");function compareCache(e,o){const t=Object.keys(o);for(const r of Object.keys(e)){if(!t.includes(r))return!1;if(o[r]!=e[r])return!1}return!0}async function uploadToCosCore({uploadBuf:e,region:o,getUploadInfoFunc:t,getAuthFunc:r,onProgress:n}){return new Promise((i,s)=>{t().then(t=>{let u=null;const l="undefined"==typeof Blob||"undefined"==typeof XMLHttpRequest,a=new(l?COSForNode:COS)({getAuthorization(e,o){var n;if(1!=e.Scope.length)return void o("");const i=Object.assign({},t,{action:e.Scope[0].action});(null===(n=e.Query)||void 0===n?void 0:n.uploadId)&&(i.uploadId=e.Query.uploadId),null!==u&&compareCache(i,u)&&u.AuthExpireTime>Math.round(Date.now()/1e3)?o({Authorization:u.Authorization,SecurityToken:u.SecurityToken,SignFrom:"client"}):r(i).then(e=>{u=Object.assign({},i,{Authorization:e.Authorization,SecurityToken:e.SecurityToken,SignFrom:"client",AuthExpireTime:e.AuthExpireTime}),o({Authorization:e.Authorization,SecurityToken:e.SecurityToken,SignFrom:"client"})},()=>{o("")})}});let c=void 0,d={};if(l)if("string"==typeof e){if(!fs.existsSync(e)||fs.statSync(e).isDirectory())throw new Error(`[upload Cos failed] file path$ ${e} is not a file or not exists`);d.name=e}else try{const o=require("tmp");o.setGracefulCleanup(),d=o.fileSync({mode:420,prefix:"",postfix:""}),fs.writeSync(d.fd,e,0,e.length,null),fs.closeSync(d.fd)}catch(e){throw console.error("Error:",e),new Error("[upload Cos failed] write compileresult to tmp file failed: "+e.message)}else{if("string"==typeof e)throw new Error("[upload Cos failed] uploadBuf must be typeof Buffer when is not in node");c=new Blob([e],{type:"application/octet-stream"})}a.sliceUploadFile({Bucket:t.bucket,Region:o,Key:t.object,Body:c,FilePath:d.name,SliceSize:5242880,onProgress(e){null==n||n(e)},AsyncLimit:1},(e,o)=>{e?s({err:e,data:o}):i({err:e,data:o})})},e=>{s({err:e})})})}function uploadToCosInCI(){}exports.uploadToCosCore=uploadToCosCore,exports.uploadToCosInCI=uploadToCosInCI;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.uploadToCosInCI=exports.uploadToCosCore=void 0;const COSForNode=require("cos-nodejs-sdk-v5"),fs=require("fs");function compareCache(e,o){const t=Object.keys(o);for(const r of Object.keys(e)){if(!t.includes(r))return!1;if(o[r]!=e[r])return!1}return!0}async function uploadToCosCore({uploadBuf:e,region:o,getUploadInfoFunc:t,getAuthFunc:r,onProgress:i}){return new Promise((n,s)=>{t().then(t=>{let u=null;const c=new COSForNode({getAuthorization(e,o){var i;if(1!=e.Scope.length)return void o("");const n=Object.assign({},t,{action:e.Scope[0].action});(null===(i=e.Query)||void 0===i?void 0:i.uploadId)&&(n.uploadId=e.Query.uploadId),null!==u&&compareCache(n,u)&&u.AuthExpireTime>Math.round(Date.now()/1e3)?o({Authorization:u.Authorization,SecurityToken:u.SecurityToken,SignFrom:"client"}):r(n).then(e=>{u=Object.assign({},n,{Authorization:e.Authorization,SecurityToken:e.SecurityToken,SignFrom:"client",AuthExpireTime:e.AuthExpireTime}),o({Authorization:e.Authorization,SecurityToken:e.SecurityToken,SignFrom:"client"})},()=>{o("")})}});let l=void 0,a={};if("string"==typeof e){if(!fs.existsSync(e)||fs.statSync(e).isDirectory())throw new Error(`[upload Cos failed] file path$ ${e} is not a file or not exists`);a.name=e}else try{const o=require("tmp");o.setGracefulCleanup(),a=o.fileSync({mode:420,prefix:"",postfix:""}),fs.writeSync(a.fd,e,0,e.length,null),fs.closeSync(a.fd)}catch(e){throw console.error("Error:",e),new Error("[upload Cos failed] write compileresult to tmp file failed: "+e.message)}c.sliceUploadFile({Bucket:t.bucket,Region:o,Key:t.object,Body:l,FilePath:a.name,SliceSize:5242880,onProgress(e){null==i||i(e)},AsyncLimit:1},(e,o)=>{e?s({err:e,data:o}):n({err:e,data:o})})},e=>{s({err:e})})})}function uploadToCosInCI(){}exports.uploadToCosCore=uploadToCosCore,exports.uploadToCosInCI=uploadToCosInCI;
package/dist/utils/env.js CHANGED
@@ -1 +1 @@
1
- "use strict";function getProcessEnv(){var e,s;return null!==(s=null!==(e=null===global||void 0===global?void 0:global.fullEnv)&&void 0!==e?e:null===process||void 0===process?void 0:process.env)&&void 0!==s?s:{}}Object.defineProperty(exports,"__esModule",{value:!0}),exports.isWin=exports.getProcessEnv=exports.isWebIDE=exports.isDevtools=void 0,exports.isDevtools=(null===process||void 0===process?void 0:process.__nwjs)&&window.nw&&"wechatwebdevtools"===nw.App.manifest.appname,exports.isWebIDE="undefined"!=typeof WEBIDE_WEBPECK_DEFINE_PLUGIN,exports.getProcessEnv=getProcessEnv;let isWebWin=!1;exports.isWin=exports.isWebIDE?isWebWin:"win32"===process.platform;
1
+ "use strict";function getProcessEnv(){var o,e;return null!==(e=null!==(o=null===global||void 0===global?void 0:global.fullEnv)&&void 0!==o?o:null===process||void 0===process?void 0:process.env)&&void 0!==e?e:{}}Object.defineProperty(exports,"__esModule",{value:!0}),exports.isElectron=exports.isWin=exports.getProcessEnv=exports.isWebIDE=exports.isDevtools=void 0,exports.isDevtools=(null===process||void 0===process?void 0:process.__nwjs)&&window.nw&&"wechatwebdevtools"===nw.App.manifest.appname,exports.isWebIDE="undefined"!=typeof WEBIDE_WEBPECK_DEFINE_PLUGIN,exports.getProcessEnv=getProcessEnv;let isWebWin=!1;function isElectron(){var o;return"1"===(null===(o=null===process||void 0===process?void 0:process.env)||void 0===o?void 0:o.ELECTRON_RUN_AS_NODE)||!0===(null===global||void 0===global?void 0:global.BACKEND)}exports.isWin=exports.isWebIDE?isWebWin:"win32"===process.platform,exports.isElectron=isElectron;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const tslib_1=require("tslib"),path=tslib_1.__importStar(require("path")),filerules_1=tslib_1.__importDefault(require("../utils/filerules")),tools_1=require("./tools"),config_1=require("../config/config");class PackOptionsHelper{constructor(){this.packOptionIgnores=[],this.packOptionIncludes=[],this.ignoreUploadUnusedFiles=!1,this.ignoreDevUnusedFiles=!1,this.unusedFiles=new Set,this.projectRoot="",this.extOpts={include:[],ignore:[]}}setExtOpts(e={}){this.extOpts.include=e.include||[],this.extOpts.ignore=e.ignore||[]}updateState(e){var s,i;this.packOptionIgnores=(null===(s=e.packOptions)||void 0===s?void 0:s.ignore)||[],this.packOptionIncludes=(null===(i=e.packOptions)||void 0===i?void 0:i.include)||[],this.projectRoot=e.miniprogramRoot||"",this.ignoreUploadUnusedFiles=!1,this.ignoreDevUnusedFiles=!1,e.type===config_1.COMPILE_TYPE.miniProgram&&(this.ignoreUploadUnusedFiles=Boolean(e.setting.ignoreUploadUnusedFiles),this.ignoreDevUnusedFiles=Boolean(e.setting.ignoreDevUnusedFiles)),(0,tools_1.isPluginType)(e)&&(this.projectRoot=e.pluginRoot||"")}isUnuserFilesEnable(e=!1){return e?!1!==this.ignoreUploadUnusedFiles:!0===this.ignoreDevUnusedFiles||!1!==this.ignoreDevUnusedFiles}filter(e,s=!1){return e.filter(e=>this.isNotIgnored(e,s))}isIgnored(e,s=!1){return this.isIgnoredByRules(e)||this.isIgnoreByUnusedFiles(e,s)}isNotIgnored(e,s=!1){return!this.isIgnored(e,s)}isIgnoredByRules(e,s={}){return!this.isFileIncluded(e,s.include)&&this.isFileIgnored(e,s.ignore)}relativePath(e){return path.posix.relative(this.projectRoot,e)}isFileIgnored(e,s){return s||(s=[...this.packOptionIgnores,...this.extOpts.ignore]),filerules_1.default.isFileIgnored(e,s)}isFileIncluded(e,s){return s||(s=[...this.packOptionIncludes,...this.extOpts.include]),filerules_1.default.isFileIncluded(e,s)}isIgnoreByUnusedFiles(e,s=!1){return!!this.isUnuserFilesEnable(s)&&(!this.isFileIncluded(e)&&this.unusedFiles.has((0,tools_1.sourcePathToTargetPath)(e)))}getUnusedFiles(){return this.unusedFiles}isScssOnlyImportedByFile(e){const s=path.extname(e.path);if("Wxss"===e.type&&[".scss",".sass",".less"].includes(s)&&e.parentDeps){let s=!0;return e.parentDeps.forEach(e=>{"file"!==e.from&&(s=!1)}),s}return!1}async initUnusedFiles(e,s,i=!1){if(this.updateState(e),this.isUnuserFilesEnable(i)&&s)try{await s.analyse();const i=s.fileHelper.getFileList("").filter(e=>(0,tools_1.isCodeFile)(path.posix.extname(e))),t=new Set;s.graph.modules.forEach(e=>{const s=i.find(s=>s===e.path);if(s){if(this.isScssOnlyImportedByFile(e))return;t.add((0,tools_1.sourcePathToTargetPath)(s))}});const n=new Set;i.forEach(s=>{const i=(0,tools_1.sourcePathToTargetPath)(s);t.has(i)||n.add(path.posix.join(e.miniprogramRoot,i))}),this.unusedFiles=n,console.error(this.unusedFiles)}catch(e){console.error("initUnusedFiles error",e)}}}exports.default=new PackOptionsHelper;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const tslib_1=require("tslib"),path=tslib_1.__importStar(require("path")),filerules_1=tslib_1.__importDefault(require("../utils/filerules")),tools_1=require("./tools"),config_1=require("../config/config");class PackOptionsHelper{constructor(){this.packOptionIgnores=[],this.packOptionIncludes=[],this.ignoreUploadUnusedFiles=!1,this.ignoreDevUnusedFiles=!1,this.unusedFiles=new Set,this.projectRoot="",this.extOpts={include:[],ignore:[]}}setExtOpts(e={}){this.extOpts.include=e.include||[],this.extOpts.ignore=e.ignore||[]}updateState(e){var s,i;this.packOptionIgnores=(null===(s=e.packOptions)||void 0===s?void 0:s.ignore)||[],this.packOptionIncludes=(null===(i=e.packOptions)||void 0===i?void 0:i.include)||[],this.projectRoot=e.miniprogramRoot||"",this.ignoreUploadUnusedFiles=!1,this.ignoreDevUnusedFiles=!1,e.type===config_1.COMPILE_TYPE.miniProgram&&(this.ignoreUploadUnusedFiles=Boolean(e.setting.ignoreUploadUnusedFiles),this.ignoreDevUnusedFiles=Boolean(e.setting.ignoreDevUnusedFiles)),(0,tools_1.isPluginType)(e)&&(this.projectRoot=e.pluginRoot||"")}isUnuserFilesEnable(e=!1){return e?!1!==this.ignoreUploadUnusedFiles:!0===this.ignoreDevUnusedFiles||!1!==this.ignoreDevUnusedFiles}filter(e,s=!1){return e.filter(e=>this.isNotIgnored(e,s))}isIgnored(e,s=!1){return this.isIgnoredByRules(e)||this.isIgnoreByUnusedFiles(e,s)}isNotIgnored(e,s=!1){return!this.isIgnored(e,s)}isIgnoredByRules(e,s={}){return!this.isFileIncluded(e,s.include)&&this.isFileIgnored(e,s.ignore)}relativePath(e){return path.posix.relative(this.projectRoot,e)}isFileIgnored(e,s){return s||(s=[...this.packOptionIgnores,...this.extOpts.ignore]),filerules_1.default.isFileIgnored(e,s)}isFileIncluded(e,s){return s||(s=[...this.packOptionIncludes,...this.extOpts.include]),filerules_1.default.isFileIncluded(e,s)}isIgnoreByUnusedFiles(e,s=!1){return!!this.isUnuserFilesEnable(s)&&(!this.isFileIncluded(e)&&this.unusedFiles.has((0,tools_1.sourcePathToTargetPath)(e)))}getUnusedFiles(){return this.unusedFiles}isScssOnlyImportedByFile(e){const s=path.extname(e.path);if("Wxss"===e.type&&[".scss",".sass",".less"].includes(s)&&e.parentDeps){let s=!0;return e.parentDeps.forEach(e=>{"file"!==e.from&&(s=!1)}),s}return!1}clearUnusedFiles(){this.unusedFiles.clear()}async initUnusedFiles(e,s,i=!1){if(!(this.unusedFiles.size>0)&&(this.updateState(e),this.isUnuserFilesEnable(i)&&s))try{await s.analyse();const i=s.fileHelper.getFileList("").filter(e=>(0,tools_1.isCodeFile)(path.posix.extname(e))),t=new Set;s.graph.modules.forEach(e=>{const s=i.find(s=>s===e.path);if(s){if(this.isScssOnlyImportedByFile(e))return;t.add((0,tools_1.sourcePathToTargetPath)(s))}});const n=new Set;i.forEach(s=>{const i=(0,tools_1.sourcePathToTargetPath)(s);t.has(i)||n.add(path.posix.join(e.miniprogramRoot,i))}),this.unusedFiles=n}catch(e){console.error("initUnusedFiles error",e)}}}exports.default=new PackOptionsHelper;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.SubProcessProxy=void 0;const processService_1=require("./processService"),customError_1=require("../customError"),singletontask_1=require("../singletontask"),debug_1=require("../debug");class SubProcessProxy{constructor(s,e,t,r,o=8891,i){this.project=s,this.entryPath=e,this.passData=t,this.initOptions=r,this.inspectPort=o,this.progressUpdate=i,this.taskMap=new Map,this.taskId=0,this.init=async()=>{this.process=await this.forkProcess()},this.onMessage=s=>{var e,t;if(this._cpPromise&&("ready"===s.type&&(clearTimeout(this._cpPromise.timer),null===(e=this._cpPromise)||void 0===e||e.resolve()),"noReady"===s.type&&this._cpPromise.reject(new Error(s.error.message))),"progress"===s.type){const e=this.taskMap.get(s.taskId);(null==e?void 0:e.progressUpdate)&&e.progressUpdate(s.id,s.status,s.message)}if("log"===s.type&&(null===(t=this.progressUpdate)||void 0===t||t.call(this,s.id||"",s.status,s.text)),"response"===s.type){const{id:e,data:t,error:r}=s;r?this.onResponse(e,void 0,r):this.onResponse(e,t,void 0)}}}async ready(){var s;return this._checkReadyTask||(this._checkReadyTask=new singletontask_1.SingletonTask(this.init)),await(null===(s=this._checkReadyTask)||void 0===s?void 0:s.getResult(!0))}async sendProcessMessage(s){await this.ready(),this.process.send(s)}destroy(){var s;null===(s=this.process)||void 0===s||s.kill("SIGTERM"),this.process=void 0,this._checkReadyTask=void 0}async forkProcess(){const s=await this.project.serialize(),e={type:"init",data:{passData:this.passData,projectInfo:s,options:this.initOptions}},t=await(0,debug_1.shouldRunInMainProcess)();if(t){const s=require("../../modules/corecompiler/processHandler");return await s.initHandler(e),s.onMessage(this.onMessage),{send:e=>{t&&s.messageHandler(e)},kill:e=>(s.destroy(),!0)}}return await(0,processService_1.forkProcess)(this,this.entryPath,this.project.projectPath,e,this.inspectPort)}onResponse(s,e,t){const r=this.taskMap.get(s);this.taskMap.delete(s),r?t?(t=new customError_1.CustomError(t),r.reject(t)):r.resolve(e):console.error(`child process task: ${s} not found`)}async sendEvent(s,e){this.sendProcessMessage({type:"event",name:s,data:e})}async runTask(s,e,t){return new Promise((r,o)=>{const i={name:s,data:e,resolve:r,reject:o,progressUpdate:t};this.taskId+=1,this.taskMap.set(this.taskId,i);this.sendProcessMessage({type:"request",id:this.taskId,name:s,data:e}).catch(s=>{o(s)})})}}exports.SubProcessProxy=SubProcessProxy;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.SubProcessProxy=void 0;const processService_1=require("./processService"),customError_1=require("../customError"),singletontask_1=require("../singletontask"),debug_1=require("../debug"),progressRecorder_1=require("../../utils/progressRecorder");class SubProcessProxy{constructor(s,e,r,t,o=8891,i){this.project=s,this.entryPath=e,this.passData=r,this.initOptions=t,this.inspectPort=o,this.progressUpdate=i,this.taskMap=new Map,this.taskId=0,this.init=async()=>{this.process=await this.forkProcess()},this.onMessage=s=>{var e,r;if(this._cpPromise&&("ready"===s.type&&(clearTimeout(this._cpPromise.timer),null===(e=this._cpPromise)||void 0===e||e.resolve()),"noReady"===s.type&&this._cpPromise.reject(new Error(s.error.message))),"progress"===s.type){const e=this.taskMap.get(s.taskId);(null==e?void 0:e.progressUpdate)&&e.progressUpdate(s.id,s.status,s.message)}if("log"===s.type&&(null===(r=this.progressUpdate)||void 0===r||r.call(this,s.id||"",s.status,s.text)),"response"===s.type){const{id:e,data:r,error:t}=s;t?this.onResponse(e,void 0,t):this.onResponse(e,r,void 0)}}}async ready(){var s;return this._checkReadyTask||(this._checkReadyTask=new singletontask_1.SingletonTask(this.init)),await(null===(s=this._checkReadyTask)||void 0===s?void 0:s.getResult(!0))}async sendProcessMessage(s){await this.ready(),this.process.send(s)}destroy(){var s;null===(s=this.process)||void 0===s||s.kill("SIGTERM"),this.process=void 0,this._checkReadyTask=void 0}async forkProcess(){console.warn(`[summer-compiler] forkProcess [${(0,progressRecorder_1.getPrintTime)()}]`);const s=await this.project.serialize();console.warn(`[summer-compiler] forkProcess serialize [${(0,progressRecorder_1.getPrintTime)()}]`);const e={type:"init",data:{passData:this.passData,projectInfo:s,options:this.initOptions}},r=await(0,debug_1.shouldRunInMainProcess)();if(r){const s=require("../../modules/corecompiler/processHandler");return await s.initHandler(e),s.onMessage(this.onMessage),{send:e=>{r&&s.messageHandler(e)},kill:e=>(s.destroy(),!0)}}console.warn(`[summer-compiler] forkProcess start [${(0,progressRecorder_1.getPrintTime)()}]`);const t=await(0,processService_1.forkProcess)(this,this.entryPath,this.project.projectPath,e,this.inspectPort);return console.warn(`[summer-compiler] forkProcess done [${(0,progressRecorder_1.getPrintTime)()}]`),t}onResponse(s,e,r){const t=this.taskMap.get(s);this.taskMap.delete(s),t?r?(r=new customError_1.CustomError(r),t.reject(r)):t.resolve(e):console.error(`child process task: ${s} not found`)}async sendEvent(s,e){this.sendProcessMessage({type:"event",name:s,data:e})}async runTask(s,e,r){return new Promise((t,o)=>{const i={name:s,data:e,resolve:t,reject:o,progressUpdate:r};this.taskId+=1,this.taskMap.set(this.taskId,i);this.sendProcessMessage({type:"request",id:this.taskId,name:s,data:e}).catch(s=>{o(s)})})}}exports.SubProcessProxy=SubProcessProxy;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.forkProcess=void 0;const tslib_1=require("tslib"),child_process_1=require("child_process"),debug_1=require("../debug"),path_1=tslib_1.__importDefault(require("path")),env_1=require("../env"),PROCESS_READY_TIMEOUT=2e4;async function forkProcess(e,s,o,r,t=8891){const c=s,i={stdio:["pipe","pipe","pipe","ipc"],cwd:o,env:Object.assign(Object.assign({},process.env),{cpprocessEnv:"childprocess",nativeProcess:"1",timeout:global.TEST_COMPILER_PROCESS_TIMEOUT})};if(await(0,debug_1.shouldInspectCompiler)()&&(i.execArgv=["--inspect-brk="+t],i.env.__MINIPROGRAM_CI_TEST__="true"),i.env.isDevtools=env_1.isDevtools,env_1.isDevtools){let e=path_1.default.join(path_1.default.dirname(process.execPath),"node");"darwin"!==process.platform&&(e+=".exe"),i.execPath=e}return new Promise((s,o)=>{const t=(0,child_process_1.fork)(c,["--expose-gc"],i),n=setTimeout(()=>{e.destroy(),o(new Error("fork process timeout"))},2e4);return e._cpPromise={timer:n,resolve:()=>{s(t)},reject:o},t.stdout.setEncoding("utf8"),t.stdout.on("data",e=>{console.log("child process stdout: "+e)}),t.stderr.on("data",e=>{console.error("child process stderr: "+e)}),t.on("exit",(s,r)=>{e.process=void 0,e._checkReadyTask=void 0,env_1.isDevtools&&console.error(`child process exit: code(${s}), signal(${r})`),0!==s&&o(new Error(`native child process exit: code(${s}), signal(${r})`))}),t.on("message",e.onMessage),t.unref(),e.taskId+=1,t.send(r),t})}exports.forkProcess=forkProcess;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.forkProcess=void 0;const tslib_1=require("tslib"),child_process_1=require("child_process"),debug_1=require("../debug"),path_1=tslib_1.__importDefault(require("path")),env_1=require("../env"),PROCESS_READY_TIMEOUT=2e4;async function forkProcess(e,s,o,r,t=8891){const c=s,i={stdio:["pipe","pipe","pipe","ipc"],cwd:o,env:Object.assign(Object.assign({},process.env),{cpprocessEnv:"childprocess",nativeProcess:"1",timeout:global.TEST_COMPILER_PROCESS_TIMEOUT})};if(await(0,debug_1.shouldInspectCompiler)()&&(i.execArgv=["--inspect="+t],(0,env_1.isElectron)()&&i.execArgv.push("--expose-gc"),i.env.__MINIPROGRAM_CI_TEST__="true"),i.env.isDevtools=env_1.isDevtools,env_1.isDevtools){let e=path_1.default.join(path_1.default.dirname(process.execPath),"node");"darwin"!==process.platform&&(e+=".exe"),i.execPath=e}return new Promise((s,o)=>{const t=(0,child_process_1.fork)(c,["--expose-gc"],i),n=setTimeout(()=>{e.destroy(),o(new Error("fork process timeout"))},2e4);return e._cpPromise={timer:n,resolve:()=>{s(t)},reject:o},t.stdout.setEncoding("utf8"),t.stdout.on("data",e=>{console.log("child process stdout: "+e)}),t.stderr.on("data",e=>{console.error("child process stderr: "+e)}),t.on("exit",(s,r)=>{e.process=void 0,e._checkReadyTask=void 0,env_1.isDevtools&&console.error(`child process exit: code(${s}), signal(${r})`),0!==s&&o(new Error(`native child process exit: code(${s}), signal(${r})`))}),t.on("message",e.onMessage),t.unref(),e.taskId+=1,t.send(r),t})}exports.forkProcess=forkProcess;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "miniprogram-ci",
3
- "version": "2.1.29",
3
+ "version": "2.1.30",
4
4
  "description": "Module that build miniprogram project for web or app extracted from WeChatDevtools.",
5
5
  "homepage": "https://developers.weixin.qq.com/community/homepage",
6
6
  "main": "dist/index.js",