@sap/generator-fiori
Version:
Create an SAPUI5 application using SAP Fiori elements or a freestyle approach
1 lines • 11.9 kB
JavaScript
"use strict";exports.id=703,exports.ids=[703],exports.modules={70987(e,i,s){s.r(i),s.d(i,{DeployProjectType:()=>b,default:()=>v,getAbapQuestions:()=>getAbapQuestions,indexHtmlExists:()=>indexHtmlExists});var n=s(73667),a=s(58808),o=s(94443),r=s(94619),p=s(61820),c=s(2307),l=s(7083),d=s(70025),h=s(76760),g=s(68801);const u=JSON.parse('{"error":{"telemetry":"Failed to send telemetry data after deployment configuration has been added: {{- error}}"},"info":{"filesGenerated":"The files have been generated.","skippedInstallation":"Option: `--skipInstall` was specified. Installation of dependencies will be skipped."},"debug":{"configExists":"Existing deployment configuration file found at {{- configPath}}.","configNotFound":"No existing deployment configuration file found. Create a deployment configuration file.","indexExists":"The `webapp/index.html` file already exists and will not be overwritten.","initFailed":"Initializing failed. Unable to process the project configuration: {{- error}}","initTelemetry":"Initializing telemetry in ABAP deployment configuration generator...","appRootPath":"Application loaded from: {{- appRootPath}}.","lrepNamespaceNotFound":"Failed to get the `lrep` namespace: {{- error}}"}}'),w="abap-deploy-config-sub-generator",f=g.createInstance();async function initI18n(){await f.init({lng:"en",fallbackLng:"en",showSupportNotice:!1}),f.addResourceBundle("en",w,u)}function t(e,i){return i?.ns||(i=Object.assign(i??{},{ns:w})),f.t(e,i)}async function indexHtmlExists(e,i){const s=await(0,l.vv)(i),n=(0,h.join)(s,"index.html");return e.exists(n)}initI18n().catch(()=>{});var y=s(76178);let m={},A=[];function isSameSystem(e,i){return e.url.trim().replace(/\/$/,"")===i.url?.trim().replace(/\/$/,"")&&(e.client??"")===(i?.client??"")}async function getDestinations(){if(0===Object.keys(m)?.length)try{m=await(0,y.listDestinations)({stripS4HCApiHosts:!0})}catch(e){a.z4.logger.error(`Failed to fetch destinations. Error: ${e.message}`)}return m}async function getBackendSystems(){if(0===A?.length)try{const e=await(0,d.cQ)({logger:a.z4.logger,entityName:"system"});A=await(e?.getAll())}catch(e){a.z4.logger.error(`Failed to fetch systems list. Error: ${e.message}`)}return A}var b,P;async function getAbapQuestions({appRootPath:e,connectedSystem:i,backendConfig:s,configFile:n=l.o3.UI5DeployYaml,indexGenerationAllowed:a=!1,showOverwriteQuestion:p=!1,projectType:c=b.Application,promptOptions:d={},logger:h}){const{backendSystem:g,serviceProvider:u,destination:w}=i||{};let f;try{const i=await(0,l.Pd)(e,n);f=i.findCustomTask("deploy-to-abap")?.configuration}catch{}const m=function getAbapTarget(e,i,s,n){let a,o,r,p,c,l;if((0,y.isAppStudio)()&&e)p=e.Name;else if(i){try{const e=new URL(i.url);a=e.origin,l="/"===e.pathname?void 0:e.pathname}catch{a=i.url}r=i.client,o=!!i.serviceKeys,c=i.authenticationType}else s?.target?(a=s.target.url,r=s.target.client,o=s.target.scp,c=s.target.authenticationType,p=s.target.destination):n&&(a=n.url,l=n.connectPath,o=n.scp,r=n.client,c=n.authenticationType,p=n?.destination);return{url:a,scp:o,client:r||"",destination:p,authenticationType:c,connectPath:l}}(w,g,f,s),A=f?.app;return h?.debug(`Retrieve ABAP prompts using: \n App path: ${e}, \n ABAPTarget: ${JSON.stringify(m)}, SystemName: ${g?.name}, \n ServiceProvider: ${!!u}, showOverwriteQuestion ${p}, indexGenerationAllowed ${a}`),(0,r.oO)({backendTarget:{abapTarget:m,systemName:g?.name,serviceProvider:u,type:c},adpProjectType:d.adpProjectType,ui5AbapRepo:{default:A?.name,...d?.ui5AbapRepo},description:{default:A?.description},packageManual:{default:A?.package??d?.packageManual?.default,...d?.packageManual},transportManual:{default:A?.transport},index:{indexGenerationAllowed:a},packageAutocomplete:{useAutocomplete:!0,...d?.packageAutocomplete},overwriteAbapConfig:{hide:!p},transportInputChoice:{hideIfOnPremise:d?.transportInputChoice?.hideIfOnPremise??!1}},h,(0,o.getHostEnvironment)()!==o.hostEnvironment.cli)}!function(e){e.Application="application",e.Library="library"}(b||(b={})),function(e){e.DEPLOY_CONFIG="DEPLOY_CONFIG"}(P||(P={}));var T=s(40511),x=s(95652),S=s(43107);const v=class extends a.z4{appWizard;vscode;launchDeployConfigAsSubGenerator;launchStandaloneFromYui;abort=!1;backendConfig;indexGenerationAllowed;configExists;answers;projectType;adpProjectType;isAdp;constructor(e,i){super(e,i),this.launchDeployConfigAsSubGenerator=i.launchDeployConfigAsSubGenerator??!1,this.launchStandaloneFromYui=i.launchStandaloneFromYui,this.adpProjectType=i.adpProjectType,this.appWizard=i.appWizard||n.AppWizard.create(i),this.vscode=i.vscode,this.options=i}async initializing(){await super.initializing(),await initI18n(),a.z4.logger?.debug(t("debug.initTelemetry")),await o.TelemetryHelper.initTelemetrySettings({consumerModule:{name:"@sap-ux/abap-deploy-config-sub-generator",version:this.rootGeneratorVersion()},internalFeature:(0,T.isInternalFeaturesSettingEnabled)(),watchTelemetrySettingStore:!1}),(0,o.setYeomanEnvConflicterForce)(this.env,this.options.force),this.launchDeployConfigAsSubGenerator||(await this._initializing(),this.adpProjectType=await(0,x.getExistingAdpProjectType)(this.destinationRoot()))}_initDestinationRoot(){this.options.appRootPath&&(this.destinationRoot(this.options.appRootPath),a.z4.logger?.debug(t("debug.appRootPath",{appRootPath:this.options.appRootPath})))}_processProjectConfig(){this.options.base=this.options.base||l.o3.Ui5Yaml,this.options.config=this.options.config||l.o3.UI5DeployYaml;this.fs.exists(this.destinationPath(this.options.base))||(this.abort=!0,function handleProjectDoesNotExist(e,i){const s=a.zc.fileDoesNotExist(i);throw(0,a.sw)(e,{errorMsg:s}),a.Sd.ABORT_SIGNAL}(this.appWizard,this.destinationPath(this.options.base))),this.configExists=this.fs.exists(this.destinationPath(this.options.config)),this.configExists&&a.z4.logger?.debug(t("debug.configExists",{configPath:this.destinationPath(this.options.config)}))}async _processIndexHtmlConfig(){if(this.projectType===b.Library)this.indexGenerationAllowed=!1;else{await indexHtmlExists(this.fs,this.destinationPath())?(this.indexGenerationAllowed=!1,this.options.index&&a.z4.logger?.debug(t("debug.indexExists")),delete this.options.index):this.indexGenerationAllowed=!0}}async _initBackendConfig(){const e=await c.io.newInstance(this.fs.read(this.destinationPath(this.options.base??l.o3.Ui5Yaml)));this.projectType="library"===e.getType()?b.Library:b.Application,this.backendConfig=e.getBackendConfigsFromFioriToolsProxyMiddleware()[0]}async _initializing(){this._initDestinationRoot();try{this._processProjectConfig(),await this._initBackendConfig(),await this._processIndexHtmlConfig()}catch(e){if(e!==a.Sd.ABORT_SIGNAL)throw e;a.z4.logger?.debug(t("debug.initFailed",{error:a.zc.getErrorMsgFromType(a.Sd.ABORT_SIGNAL)}))}}async prompting(){if(this.answers={},!this.abort){if(!this.launchDeployConfigAsSubGenerator){const e=await(0,l.Ov)(this.destinationPath());this.isAdp="Fiori Adaptation"===e;const i={shouldValidatePackageForStartingPrefix:this.isAdp,shouldValidatePackageType:this.isAdp,shouldValidateFormatAndSpecialCharacters:this.isAdp},s=this.adpProjectType===S.AdaptationProjectType.ON_PREMISE,n={ui5AbapRepo:{hideIfOnPremise:s},transportInputChoice:{hideIfOnPremise:s},packageAutocomplete:{additionalValidation:i},packageManual:{additionalValidation:i},adpProjectType:this.adpProjectType},o=this.indexGenerationAllowed&&!this.isAdp,{prompts:p,answers:c={}}=await getAbapQuestions({appRootPath:this.destinationRoot(),connectedSystem:this.options.connectedSystem,backendConfig:this.backendConfig,configFile:this.options.config,indexGenerationAllowed:o,showOverwriteQuestion:(0,a.dO)(this.launchDeployConfigAsSubGenerator,this.launchStandaloneFromYui,this.options.overwrite,this.configExists),projectType:this.projectType,logger:a.z4.logger,promptOptions:n}),d=await this.prompt(p);this.answers=(0,r.Uo)(d,c)}await this._reconcileAnswersWithOptions()}}async _processAbapTargetAnswers(){this.answers.destination=this.options.destination||this.answers.destination,this.answers.url=this.options.url||this.answers.url||await async function determineUrlFromDestination(e){let i;if((0,y.isAppStudio)()&&e){const s=await getDestinations();i=s?.[e]?.Host}return i}(this.answers.destination),this.answers.connectPath=this.options.connectPath||this.answers.connectPath,this.answers.client=this.options.client||this.answers.client,this.answers.scp=this.options.scp||this.answers.scp||await async function determineScpFromTarget(e){let i=!1;if((0,y.isAppStudio)()&&e.destination){const s=await getDestinations();s?.[e.destination]&&(i=(0,y.isAbapEnvironmentOnBtp)(s?.[e.destination]))}else if(e.url){const s=await getBackendSystems(),n=s?.find(i=>isSameSystem(i,e));i=!!n?.serviceKeys}return i}({url:this.answers.url,client:this.answers.client,destination:this.answers.destination}),this.answers.isAbapCloud=this.options.isAbapCloud||this.answers.isAbapCloud||await async function determineS4HCFromTarget(e){let i=!1;if((0,y.isAppStudio)()&&e.destination){const s=await getDestinations();s?.[e.destination]&&(i=(0,y.isS4HC)(s?.[e.destination]))}else if(e.url){const s=await getBackendSystems(),n=s?.find(i=>isSameSystem(i,e));i=n?.authenticationType===d.h_.ReentranceTicket}return i}({url:this.answers.url,client:this.answers.client,destination:this.answers.destination}),!(0,y.isAppStudio)()&&this.answers.scp&&delete this.answers.client}_processBspAppAnswers(){this.answers.ui5AbapRepo=(this.options.ui5AbapRepo||this.answers.ui5AbapRepo)?.toUpperCase(),this.answers.description=this.options.description||this.answers.description,this.answers.package||(this.answers.package=(0,r.fW)(this.options,this.options.package)||(0,r.fW)(this.answers)||(this.answers.scp?"":r.cX)),this.answers.transport||(this.answers.transport=this.options.transport??((0,r.O3)(this.options)||(0,r.O3)(this.answers)))}async _reconcileAnswersWithOptions(){await this._processAbapTargetAnswers(),this._processBspAppAnswers(),this.answers.index=this.options.index??this.answers.index,this.answers.overwrite=this.options.overwrite??this.answers.overwrite}async writing(){this.launchDeployConfigAsSubGenerator?(await this._initializing(),await this._writing()):await this._writing()}async _writing(){if(this.abort||!1===this.answers.overwrite)return;const e=this.adpProjectType===S.AdaptationProjectType.CLOUD_READY,i=await async function getVariantNamespace(e,i,s){if(!i)try{const i=(0,h.join)(await(0,l.vv)(e,s),l.o3.ManifestAppDescrVar);if(s.exists(i))return s.readJSON(i).namespace}catch(e){a.z4.logger?.debug(t("debug.lrepNamespaceNotFound",{error:e.message}))}}(this.destinationPath(),e,this.fs);await(0,p.c)(this.destinationPath(),{target:{url:this.answers.url,connectPath:this.answers.connectPath,client:this.answers.client,scp:this.answers.scp,destination:this.answers.destination,authenticationType:this.answers.isAbapCloud?d.h_.ReentranceTicket:void 0},app:{name:this.answers.ui5AbapRepo,description:this.answers.description,package:this.answers.package,transport:this.answers.transport},index:this.answers.index,lrep:i},{baseFile:this.options.base,deployFile:this.options.config,addBuildToUndeployScript:!this.isAdp},this.fs)}install(){!1!==this.answers.overwrite&&this._install()}_install(){this.options.skipInstall?a.z4.logger?.info(t("info.skippedInstallation")):this.spawnCommand("npm",["install","--no-audit","--no-fund","--silent","--prefer-offline","--no-progress"])}async end(){this.abort||!1===this.answers.overwrite||(this.launchStandaloneFromYui&&(0,o.isExtensionInstalled)(this.vscode,o.YUI_EXTENSION_ID,o.YUI_MIN_VER_FILES_GENERATED_MSG)&&this.appWizard?.showInformation(t("info.filesGenerated"),n.MessageType.notification),(0,o.sendTelemetry)(P.DEPLOY_CONFIG,o.TelemetryHelper.createTelemetryData({DeployTarget:"ABAP",...this.options.telemetryData})??{},this.destinationRoot())?.catch(e=>{a.z4.logger.error(t("error.telemetry",{error:e}))}))}}}};