UNPKG

@sap/generator-fiori

Version:

Create an SAPUI5 application using SAP Fiori elements or a freestyle approach

1 lines 13.9 kB
"use strict";exports.id=5134,exports.ids=[5134],exports.modules={45611(i,e,a){a.r(e),a.d(e,{default:()=>u});var n=a(76760),s=a(44425),o=a(48161),r=a(73667),p=a(58808),c=a(45780),d=a(15034),h=a(23331);const l=[{name:"Application Router Configuration",description:"Configure the Cloud Foundry application router"}],u=class extends p.z4{appWizard;prompts;answers;abort=!1;setPromptsCallback;constructor(i,e){super(i,e),this.appWizard=e.appWizard??r.AppWizard.create(e),this.options=e,this.appWizard.setHeaderTitle("Application Router Generator"),this.prompts=new r.Prompts(l),this.setPromptsCallback=i=>{this.prompts&&this.prompts.setCallback(i)}}async initializing(){await super.initializing(),await(0,h.LE)(),this._initFromProjectConfig()}_initFromProjectConfig(){s.sync(p.rs)||((0,p.sw)(this.appWizard,{errorType:p.Sd.NO_MTA_BIN}),this.abort=!0)}async prompting(){if(this.abort)return;const i={[c.tI.mtaPath]:this.destinationRoot()??process.cwd(),[c.tI.mtaId]:!0,[c.tI.mtaDescription]:!0,[c.tI.mtaVersion]:!1,[c.tI.routerType]:!0,[c.tI.addConnectivityService]:!0,[c.tI.addABAPServiceBinding]:!0},e=await(0,c.k0)(i);this.answers=await this.prompt(e)}async writing(){if(this.abort)return;let i;this.destinationRoot((0,n.join)(this.answers.mtaPath,this.answers.mtaId)),p.z4.logger?.debug((0,h.t)("appRouterGen.debug.projectPath",{destinationPath:this.destinationRoot()})),this.answers.addABAPServiceBinding&&(i={abapServiceName:this.answers.abapServiceProvider?.label,abapService:this.answers.abapServiceProvider?.service});const e={routerType:this.answers.routerType,addConnectivityService:this.answers.addConnectivityService??!1,abapServiceProvider:i,mtaId:this.answers.mtaId,mtaPath:this.destinationRoot(),mtaDescription:this.answers.mtaDescription,mtaVersion:"0.0.1"};await(0,d.vJ)(e,this.fs,p.z4.logger)}install(){this._install()}_install(){if(!this.abort&&!this.options.skipInstall){const i="win32"===(0,o.platform)()?"npm.cmd":"npm";this.spawnCommand(i,["install","--no-audit","--no-fund","--silent","--prefer-offline","--no-progress"],{cwd:this.destinationRoot()})}}}},29448(i,e,a){a.r(e),a.d(e,{API_BUSINESS_HUB_ENTERPRISE_PREFIX:()=>g.TX,ApiHubType:()=>l.sm,DESTINATION_AUTHTYPE_NOTFOUND:()=>g.ms,default:()=>y,getCFQuestions:()=>getCFQuestions,loadManifest:()=>loadManifest});var n,s=a(76760),o=a(48161),r=a(44425),p=a(73667),c=a(94443),d=a(40511),h=a(76178),l=a(15034),u=a(58808),g=a(23331),m=a(7083);async function getCFChoices({projectRoot:i,isAbapDirectServiceBinding:e,cfDestination:a,isCap:n,apiHubConfigType:s}){let o=[];const r=[{name:(0,g.t)("cfGen.prompts.abapBinding.name"),value:g.Lg}];if(s===l.sm.apiHubEnterprise)o=[{name:a,value:a}];else{const s=!e&&(0,h.isAppStudio)()?await async function getCFSystemChoices(i,e,a){const n=[];try{let a=[];if(e){const e=await l.jn.newInstance(i);a=e.getExposedDestinations(),e.hasResource("destination")&&n.push({name:(0,g.t)("cfGen.prompts.capInstanceBasedDest.name"),value:g.YS})}else{const e=await(0,m.ez)(i),n=e?.mtaPath?.split(m.o3.MtaYaml)[0];if(n){a=(await l.jn.newInstance(n)).getExposedDestinations(!0)}}a?.length&&a.forEach(i=>{n.push({name:(0,g.t)("cfGen.prompts.instanceBasedDest.name",{destination:i}),value:i})})}catch(i){u.z4.logger?.debug((0,g.t)("cfGen.error.mtaDestinations",{error:i}))}a||n.splice(0,0,{name:(0,g.t)("cfGen.prompts.none.name"),value:g.qp});return n}(i,n,a):[];o=e?r:s}return o}function destinationQuestionDefaultOption(i,e,a){let n="";return e?a?n=a:i?n=g.Lg:e&&(n=g.qp):n=a??"",n}async function loadManifest(i,e){const a=(0,s.join)(await(0,m.vv)(e),m.o3.Manifest),n=i.readJSON(a);return n||(0,u.VI)(u.zc.getErrorMsgFromType(u.Sd.NO_MANIFEST)),n["sap.app"]?.id||(0,u.VI)(u.zc.getErrorMsgFromType(u.Sd.NO_APP_NAME)),n}!function(i){i.DEPLOY_CONFIG="DEPLOY_CONFIG"}(n||(n={}));var f=a(45780),w=a(67566);async function getCFQuestions({projectRoot:i,isAbapDirectServiceBinding:e,cfDestination:a,isCap:n,addOverwrite:s,apiHubConfig:o,promptOptions:r}){const p=(0,h.isAppStudio)(),d=!!await(0,m.ez)(i),l=await getCFChoices({projectRoot:i,isCap:n,cfDestination:a,isAbapDirectServiceBinding:e,apiHubConfigType:o?.apiHubType}),w={[f.rp.destinationName]:{defaultValue:destinationQuestionDefaultOption(e,p,a),hint:!!e,useAutocomplete:(0,c.getHostEnvironment)()===c.hostEnvironment.cli,addBTPDestinationList:!!p&&!e,additionalChoiceList:l,...r?.destinationName},[f.rp.addManagedAppRouter]:{hide:!0,...r?.addManagedAppRouter},[f.rp.routerType]:{hide:d||n,...r?.routerType},[f.rp.overwriteCfConfig]:{hide:!s,...r?.overwriteCfConfig}};return u.z4.logger?.debug((0,g.t)("cfGen.debug.promptOptions",{options:JSON.stringify({...w,isCap:n,addOverwrite:s,cfDestination:a,isAbapDirectServiceBinding:e})})),(0,f.oO)(w,u.z4.logger)}async function getCAPMTAQuestions({projectRoot:i}){let e=await async function getCFApprouterQuestionsForCap({projectRoot:i}){const e={[f.tI.mtaPath]:i,[f.tI.mtaId]:!1,[f.tI.mtaDescription]:!1,[f.tI.mtaVersion]:!1,[f.tI.routerType]:!0,[f.tI.addConnectivityService]:!0,[f.tI.addABAPServiceBinding]:!1};return(0,f.k0)(e)}({projectRoot:i});return e=(0,w.withCondition)(e,i=>!0===i.addCapMtaContinue),e.unshift(...(0,u.Oy)()),e}const y=class extends u.z4{appWizard;vscode;launchDeployConfigAsSubGenerator;launchStandaloneFromYui;appPath;addMtaDestination;apiHubConfig;cloudServiceName;serviceBase;answers={};appRouterAnswers;projectRoot;mtaPath;isCap=!1;isAbapDirectServiceBinding=!1;lcapModeOnly=!1;servicePath;destinationName;abort=!1;deployConfigExists=!1;packageName;constructor(i,e){super(i,e),this.launchDeployConfigAsSubGenerator=e.launchDeployConfigAsSubGenerator??!1,this.launchStandaloneFromYui=e.launchStandaloneFromYui,this.appWizard=e.appWizard??p.AppWizard.create(e),this.vscode=e.vscode,this.options=e,this.destinationName=e.destinationName??"",this.addMtaDestination=e.addMTADestination??!1,this.lcapModeOnly=e.lcapModeOnly??!1,this.cloudServiceName=e.cloudServiceName||void 0,this.apiHubConfig=e.apiHubConfig,this.servicePath=e.appGenServicePath,this.serviceBase=e.appGenServiceHost,this.appPath=e.appRootPath??this.destinationRoot(),this.projectRoot=e.projectRoot??this.destinationRoot()}async initializing(){await super.initializing(),await(0,g.LE)(),u.z4.logger?.debug((0,g.t)("cfGen.debug.initTelemetry")),(0,c.setYeomanEnvConflicterForce)(this.env,this.options.force),await c.TelemetryHelper.initTelemetrySettings({consumerModule:{name:"@sap-ux/cf-deploy-config-sub-generator",version:this.rootGeneratorVersion()},internalFeature:(0,d.isInternalFeaturesSettingEnabled)(),watchTelemetrySettingStore:!1}),this.launchDeployConfigAsSubGenerator||await this._init()}async _init(){r.sync(u.rs)||(this.abort=!0,(0,u.sw)(this.appWizard,{errorType:u.Sd.NO_MTA_BIN})),await this._processProjectPaths(),await this._processProjectConfigs(),this.isAbapDirectServiceBinding=await(0,l.dF)(this.appPath,!1,this.mtaPath),this.isCap||(this.lcapModeOnly=!1)}async _processProjectPaths(){const i=await(0,m.ez)(this.appPath);this.mtaPath=i?.mtaPath;const e=await(0,m.JR)(this.appPath,!0,this.fs);if(e){r.sync(u.nk)||(0,u.VI)(u.zc.getErrorMsgFromType(u.Sd.NO_CDS_BIN)),this.isCap=!0,this.projectRoot=e;try{this.packageName=this.fs.readJSON((0,s.join)(this.projectRoot,m.o3.Package))?.name??""}catch{}}else this.mtaPath&&(this.projectRoot=(0,s.dirname)(this.mtaPath))}async _processProjectConfigs(){const i=this.options.base??m.o3.Ui5Yaml;this.fs.exists((0,s.join)(this.appPath,i))||(0,u.VI)(u.zc.noBaseConfig(i)),this.deployConfigExists=this.fs.exists((0,s.join)(this.appPath,this.options.config??m.o3.Ui5Yaml))}async prompting(){this.abort||(this.launchDeployConfigAsSubGenerator||await this._prompting(),await this._reconcileAnswersWithOptions())}async _prompting(){if(this.isCap&&this.projectRoot&&!this.mtaPath){if(u.z4.logger?.debug((0,g.t)("cfGen.debug.capMissingMTA")),this.appRouterAnswers=await this.prompt(await getCAPMTAQuestions({projectRoot:this.projectRoot??process.cwd()})),!0!==this.appRouterAnswers.addCapMtaContinue)return void(this.abort=!0);this.appRouterAnswers.mtaId=this.packageName,this.destinationName=l.WJ,this.options.overwrite=!0,this.answers={},this.answers.destinationName=this.destinationName,this.answers.addManagedAppRouter=!1}else{await this._handleApiHubConfig();const i=await this._getCFQuestions();this.answers=await this.prompt(i)}}async _handleApiHubConfig(){if(this.apiHubConfig?.apiHubType===l.sm.apiHubEnterprise){if(!this.servicePath){const i=await loadManifest(this.fs,this.appPath);this.servicePath=i?.["sap.app"]?.dataSources?.mainService?.uri}this.destinationName=(0,u.rv)(g.TX,this.servicePath)}}async _getCFQuestions(){return getCFQuestions({projectRoot:this.projectRoot,isAbapDirectServiceBinding:this.isAbapDirectServiceBinding,cfDestination:this.destinationName,isCap:this.isCap,addOverwrite:(0,u.dO)(this.deployConfigExists,this.launchDeployConfigAsSubGenerator,this.launchStandaloneFromYui,this.options.overwrite),apiHubConfig:this.apiHubConfig})}async _reconcileAnswersWithOptions(){const i=this.destinationName||this.answers.destinationName,e=await(0,u.x4)(i),a=this.options.isFullUrlDest??(e&&(0,h.isFullUrlDestination)(e))??!1;a&&u.z4.logger?.warn((0,g.t)("cfGen.warn.fullUrlDestination"));const n=this.options.addManagedAppRouter??(this.options.routerType===f.Ql.Managed||this.answers.routerType===f.Ql.Managed),s=this.options.addAppFrontendRouter??(this.options.routerType===f.Ql.AppFront||this.answers.routerType===f.Ql.AppFront),o=this.options.destinationAuthType??e?.Authentication??g.ms,r=this.options.overwrite??this.answers.overwrite;this.answers={destinationName:i,addManagedAppRouter:n,isDestinationFullUrl:a,destinationAuthentication:o,overwrite:r,addAppFrontendRouter:s}}async writing(){this.abort||!1===this.options.overwrite||(this.launchDeployConfigAsSubGenerator?(await this._init(),await this._writing()):await this._writing())}async _writing(){try{this.appRouterAnswers&&await(0,l.m8)(this.appRouterAnswers,this.fs,u.z4.logger),await(0,l.ns)(this._getAppConfig(),this.fs,u.z4.logger)}catch(i){this.abort=!0,(0,u.sw)(this.appWizard,{errorMsg:(0,g.t)("cfGen.error.writing",{error:i})})}}_getAppConfig(){return{appPath:this.appPath,addManagedAppRouter:this.answers.addManagedAppRouter,addAppFrontendRouter:this.answers.addAppFrontendRouter,destinationName:this.answers.destinationName,destinationAuthentication:this.answers.destinationAuthentication,isDestinationFullUrl:this.answers.isDestinationFullUrl,apiHubConfig:this.apiHubConfig,serviceHost:this.serviceBase,lcapMode:this.lcapModeOnly,addMtaDestination:this.addMtaDestination,cloudServiceName:this.cloudServiceName}}async install(){!1===this.options.overwrite||this.abort||await this._install()}async _install(){if(this.options.skipInstall)u.z4.logger?.info((0,g.t)("cfGen.info.skippedInstallation"));else try{await this._runNpmInstall(this.projectRoot),this.projectRoot!==this.appPath&&await this._runNpmInstall(this.appPath)}catch(i){(0,u.sw)(this.appWizard,{errorMsg:(0,g.t)("cfGen.error.install",{error:i.message})})}}async _runNpmInstall(i){const e="win32"===(0,o.platform)()?"npm.cmd":"npm";await this.spawnCommand(e,["install","--no-audit","--no-fund","--silent","--prefer-offline","--no-progress"],{cwd:i})}async end(){try{if(this.abort||!1===this.answers.overwrite)return;!this.options.launchStandaloneFromYui&&this.launchDeployConfigAsSubGenerator||!(0,c.isExtensionInstalled)(this.vscode,c.YUI_EXTENSION_ID,c.YUI_MIN_VER_FILES_GENERATED_MSG)||this.appWizard?.showInformation((0,g.t)("cfGen.info.filesGenerated"),p.MessageType.notification),await this._sendTelemetry()}catch(i){u.z4.logger?.error((0,g.t)("cfGen.error.end",{error:i}))}}async _sendTelemetry(){const i=c.TelemetryHelper.createTelemetryData({DeployTarget:"CF",ManagedApprouter:this.answers.addManagedAppRouter,AppFrontendRouter:this.answers.addAppFrontendRouter,MTA:this.mtaPath?"true":"false",...this.options.telemetryData})??{};await(0,c.sendTelemetry)(n.DEPLOY_CONFIG,i,this.appPath)}}},25888(i,e,a){a.d(e,{Lg:()=>p,TX:()=>n,YS:()=>s,ms:()=>o,qp:()=>r});const n="ABHE",s="fiori-default-srv-api",o="NotAvailable",r="NONE",p="DIRECT_SERVICE_BINDING"},23331(i,e,a){if(a.d(e,{TX:()=>n.TX,YS:()=>n.YS,ms:()=>n.ms,Lg:()=>n.Lg,qp:()=>n.qp,LE:()=>initI18n,t:()=>t}),!/^(5750|6338)$/.test(a.j))var n=a(25888);var s=a(68801);const o=JSON.parse('{"cfGen":{"prompts":{"abapBinding":{"name":"Direct Service Binding"},"capInstanceBasedDest":{"name":"Local CAP Project API (Instance Based Destination)"},"instanceBasedDest":{"name":"{{- destination}} (Instance Based Destination)"},"none":{"name":"None"}},"info":{"filesGenerated":"The files have been generated.","skippedInstallation":"Option: `--skipInstall` was specified. Installation of dependencies will be skipped."},"error":{"mtaDestinations":"No destinations loaded from the `mta.yaml` file. {{- error}}","writing":"An error occurred in the writing phase: {{- error}}","install":"An error occurred in the install phase: {{- error}}","end":"An error occurred in the end phase: {{- error}}"},"warn":{"fullUrlDestination":"The deployment destination is configured as a full URL destination. The deployed app may not render correctly. See SAP Guided Answers for migration instructions: https://ga.support.sap.com/index.html#/tree/3046/actions/45995:52881:52892:68172"},"debug":{"promptOptions":"Retrieving CF prompts using: \\n {{- options}}","initTelemetry":"Initializing telemetry in CF deployment configuration generator...","capMissingMTA":"CAP project detected with no MTA configuration. Add an MTA configuration."}},"appRouterGen":{"debug":{"projectPath":"Project loaded from {{- destinationPath}}."}}}');var r=a(67566);const p="cf-deploy-config-generator",c=s.createInstance();async function initI18n(){await c.init({lng:"en",fallbackLng:"en",showSupportNotice:!1}),c.addResourceBundle("en",p,o),(0,r.addi18nResourceBundle)()}function t(i,e){return e?.ns||(e=Object.assign(e??{},{ns:p})),c.t(i,e)}initI18n().catch(()=>{})}};