"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,i,o){void 0===o&&(o=i);var r=Object.getOwnPropertyDescriptor(t,i);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,o,r)}:function(e,t,i,o){void 0===o&&(o=i),e[o]=t[i]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var i in e)"default"!==i&&Object.prototype.hasOwnProperty.call(e,i)&&__createBinding(t,e,i);return __setModuleDefault(t,e),t},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});const fs_1=__importDefault(require("fs")),path_1=__importDefault(require("path")),Runner_1=__importDefault(require("../Runner")),mobileUtils_1=require("../help/mobileUtils"),utils_1=require("../../../utils/utils"),utils_2=require("../../../modules/storage/help/utils"),Error_1=__importStar(require("../../Error")),simulator_1=require("../../../types/simulator"),commonData_1=require("../../../types/commonData"),i18n_1=__importDefault(require("../../../i18n"));function initProject(e,t,i,o){const r=Runner_1.default.run("gadget","getStorageKey","root"),a=Runner_1.default.run("gadget","getStorageKey","config"),n=i[r][e],{sdkVersion:l}=i.ideConfig[a];let s;switch((0,mobileUtils_1.getAppType)(e)){case simulator_1.CompilePathType.sourceCode:s=Promise.resolve(JSON.parse(fs_1.default.readFileSync(path_1.default.join(e,"project.config.json")).toString()));break;case simulator_1.CompilePathType.compiledCode:s=Promise.resolve(JSON.parse(fs_1.default.readFileSync(path_1.default.join(e,"app-config.json")).toString())).then(e=>({appid:e.appId}));break;case simulator_1.CompilePathType.pkgFile:s=Promise.resolve(JSON.parse(fs_1.default.readFileSync(path_1.default.join((0,utils_1.unpackPKGPath)(e),"app-config.json")).toString())).then(e=>({appid:e.appId}));break;default:s=Promise.reject(new Error_1.default({code:Error_1.CoreErrorCode.ENTRY_ERROR,message:i18n_1.default.t("ENTRY_ERROR_RESOLVE_FAIL"),advise:i18n_1.default.t("ENTRY_ERROR_RESOLVE_FAIL_ADVISE")}))}return s.then(i=>{let o,r={},a={urlCheck:i.setting&&i.setting.urlCheck||!0,autoRefresh:!0,onUserCaptureScreen:!1,toolBox:commonData_1.emptyToolBox,compileModeConfig:{list:[]},lastPreview:{},lastUpload:{time:0,version:"0.0.0"},lastMobilePreview:{},lastPCPreview:{},sdkVersion:l,customDevice:{name:"自定义",value:{name:"自定义",width:0,height:0,dpr:0,system:"",platform:""}},mockPanel:commonData_1.emptyMockPanel,darkMode:"light",useNPM:!1,enableWebviewSafeDomain:!0,needSubPackage:!1};const s=(0,utils_2.getPathId)(e);if(n){if(n.appId===i.appid&&(r=n.appData),Object.keys(a).forEach(e=>{void 0!==n.simulatorConfig[e]&&null!==n.simulatorConfig[e]&&(a[e]=n.simulatorConfig[e])}),a=Object.assign(Object.assign({},n.simulatorConfig),a),n.tmpConfig)o=n.tmpConfig;else{const e=path_1.default.join(t,"builds",s);o=(0,utils_2.getTmpConfig)(e)}const e={fileStack:[],deleteFileWithoutConfirm:!1};n.editorConfig||(n.editorConfig=e),n.panelConfig||(n.panelConfig={showDevtools:!0,showEditor:!0,showExplorer:!0,showSimulator:!0})}else{const e=path_1.default.join(t,"builds",s);o=(0,utils_2.getTmpConfig)(e)}return Object.assign(Object.assign({},n),{appId:i.appid,compileId:s,compilePath:e,tmpConfig:o,appData:r,simulatorConfig:a,lastOpen:Date.now()})}).catch(()=>{throw new Error_1.default({code:Error_1.CoreErrorCode.ENTRY_ERROR,message:i18n_1.default.t("ENTRY_ERROR_RESOLVE_FAIL"),advise:i18n_1.default.t("ENTRY_ERROR_RESOLVE_FAIL_ADVISE")})})}exports.default=initProject;