"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.checkIsUseCompilerPlugins=exports.CompileSettingsKeysInProjectConfig=void 0,exports.isGameApp=isGameApp,exports.isUndefined=isUndefined,exports.formatCISetting=formatCISetting,exports.getMiniappCacheDir=getMiniappCacheDir,exports.getMiniappIOSCacheDir=getMiniappIOSCacheDir,exports.clearIOSCacheDir=clearIOSCacheDir,exports.clearAndroidCacheDir=clearAndroidCacheDir;const types_1=require("../../types"),projectconfig_1=require("../../modules/corecompiler/original/json/projectconfig"),path=require("path"),os=require("os"),fse=require("fs-extra");function isGameApp(i){return i.type===types_1.EProjectType.miniGame||i.type===types_1.EProjectType.miniGamePlugin}exports.CompileSettingsKeysInProjectConfig=["es6","es7","enhance","minified","minify","codeProtect","uglifyFileName","postcss","minifyJS","minifyWXML","minifyWXSS","autoPrefixWXSS","disableUseStrict","compileWorklet"];const checkIsUseCompilerPlugins=i=>{var e,n,t;return!isGameApp(i)||(null===(e=i.setting)||void 0===e?void 0:e.condition)||((null===(n=i.setting)||void 0===n?void 0:n.useCompilerPlugins)||[]).length>0||(null===(t=i.setting)||void 0===t?void 0:t.swc)};function isUndefined(i){return void 0===i}function formatCISetting(i,e){var n,t,s,o,r,c,f,d,l;const p=(0,projectconfig_1.getProjectConfigJSON)(i);if(e.useProjectConfig)return Object.assign(Object.assign({},p.setting),{minifyWXSS:!1!==e.minifyWXSS&&(!!e.minify||(isUndefined(e.minifyWXSS)?null===(n=p.setting)||void 0===n?void 0:n.minifyWXSS:!!e.minifyWXSS)),minifyWXML:!1!==e.minifyWXML&&(!!e.minify||(isUndefined(e.minifyWXML)?null===(t=p.setting)||void 0===t?void 0:t.minifyWXML:!!e.minifyWXML)),minified:!1!==e.minifyJS&&(!!e.minify||(isUndefined(e.minifyJS)?null===(s=p.setting)||void 0===s?void 0:s.minified:!!e.minifyJS)),postcss:isUndefined(e.autoPrefixWXSS)?null===(o=p.setting)||void 0===o?void 0:o.postcss:!!e.autoPrefixWXSS,disableUseStrict:isUndefined(e.disableUseStrict)?null===(r=p.setting)||void 0===r?void 0:r.disableUseStrict:!!e.disableUseStrict,compileWorklet:isUndefined(e.compileWorklet)?null===(c=p.setting)||void 0===c?void 0:c.compileWorklet:!!e.compileWorklet,uglifyFileName:isUndefined(e.codeProtect)?null===(f=p.setting)||void 0===f?void 0:f.uglifyFileName:!!e.codeProtect,es6:isUndefined(e.es6)&&isUndefined(e.es7)?null===(d=p.setting)||void 0===d?void 0:d.es6:!!e.es6||!!e.es7,enhance:isUndefined(e.es6)&&isUndefined(e.es7)?null===(l=p.setting)||void 0===l?void 0:l.enhance:!!e.es6||!!e.es7});const a=Object.assign({},p.setting);for(const i in a)exports.CompileSettingsKeysInProjectConfig.indexOf(i)>-1&&delete a[i];return Object.assign(Object.assign({},a),{minifyWXSS:!1!==e.minifyWXSS&&(e.minify||!!e.minifyWXSS),minifyWXML:!1!==e.minifyWXML&&(e.minify||!!e.minifyWXML),minified:!1!==e.minifyJS&&(e.minify||!!e.minifyJS),postcss:!!e.autoPrefixWXSS,disableUseStrict:!!e.disableUseStrict,compileWorklet:!!e.compileWorklet,uglifyFileName:!!e.codeProtect,es6:!!e.es6||!!e.es7,enhance:!!e.es6||!!e.es7})}function getMiniappCacheDir(){return path.join(os.tmpdir(),"miniapp")}function getMiniappIOSCacheDir(){return path.join(getMiniappCacheDir(),"ios")}function clearIOSCacheDir(){["ios","iOSCloudBuild","miniapp-plugin"].forEach(i=>{const e=path.join(getMiniappCacheDir(),i);fse.existsSync(e)&&fse.removeSync(e)})}function clearAndroidCacheDir(){["android"].forEach(i=>{const e=path.join(getMiniappCacheDir(),i);fse.existsSync(e)&&fse.removeSync(e)})}exports.checkIsUseCompilerPlugins=checkIsUseCompilerPlugins;