UNPKG

@sap/generator-fiori

Version:

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

1 lines 16.9 kB
"use strict";exports.id=5134,exports.ids=[5134],exports.modules={57829(e,i){Object.defineProperty(i,"__esModule",{value:!0}),i.defaultMtaVersion=i.prompts=i.generatorTitle=void 0,i.generatorTitle="Application Router Generator",i.prompts=[{name:"Application Router Configuration",description:"Configure the Cloud Foundry application router"}],i.defaultMtaVersion="0.0.1"},37648(e,i,a){Object.defineProperty(i,"__esModule",{value:!0});const n=a(76760),o=a(44425),s=a(48161),r=a(73667),p=a(4591),c=a(45048),d=a(13149),l=a(95644),h=a(57829);class default_1 extends p.DeploymentGenerator{appWizard;prompts;answers;abort=!1;setPromptsCallback;constructor(e,i){super(e,i),this.appWizard=i.appWizard??r.AppWizard.create(i),this.options=i,this.appWizard.setHeaderTitle(h.generatorTitle),this.prompts=new r.Prompts(h.prompts),this.setPromptsCallback=e=>{this.prompts&&this.prompts.setCallback(e)}}async initializing(){await super.initializing(),await(0,l.initI18n)(),this._initFromProjectConfig()}_initFromProjectConfig(){o.sync(p.mtaExecutable)||((0,p.handleErrorMessage)(this.appWizard,{errorType:p.ERROR_TYPE.NO_MTA_BIN}),this.abort=!0)}async prompting(){if(this.abort)return;const e={[c.appRouterPromptNames.mtaPath]:this.destinationRoot()??process.cwd(),[c.appRouterPromptNames.mtaId]:!0,[c.appRouterPromptNames.mtaDescription]:!0,[c.appRouterPromptNames.mtaVersion]:!1,[c.appRouterPromptNames.routerType]:!0,[c.appRouterPromptNames.addConnectivityService]:!0,[c.appRouterPromptNames.addABAPServiceBinding]:!0},i=await(0,c.getAppRouterPrompts)(e);this.answers=await this.prompt(i)}async writing(){if(this.abort)return;let e;this.destinationRoot((0,n.join)(this.answers.mtaPath,this.answers.mtaId)),p.DeploymentGenerator.logger?.debug((0,l.t)("appRouterGen.debug.projectPath",{destinationPath:this.destinationRoot()})),this.answers.addABAPServiceBinding&&(e={abapServiceName:this.answers.abapServiceProvider?.label,abapService:this.answers.abapServiceProvider?.service});const i={routerType:this.answers.routerType,addConnectivityService:this.answers.addConnectivityService??!1,abapServiceProvider:e,mtaId:this.answers.mtaId,mtaPath:this.destinationRoot(),mtaDescription:this.answers.mtaDescription,mtaVersion:h.defaultMtaVersion};await(0,d.generateBaseConfig)(i,this.fs,p.DeploymentGenerator.logger)}install(){this._install()}_install(){if(!this.abort&&!this.options.skipInstall){const e="win32"===(0,s.platform)()?"npm.cmd":"npm";this.spawnCommand(e,["install","--no-audit","--no-fund","--silent","--prefer-offline","--no-progress"],{cwd:this.destinationRoot()})}}}i.default=default_1},12754(e,i,a){Object.defineProperty(i,"__esModule",{value:!0}),i.DESTINATION_AUTHTYPE_NOTFOUND=i.API_BUSINESS_HUB_ENTERPRISE_PREFIX=i.loadManifest=i.getCFQuestions=void 0;const n=a(76760),o=a(48161),s=a(44425),r=a(73667),p=a(58012),c=a(98434),d=a(75199),l=a(13149),h=a(4591),u=a(95644);Object.defineProperty(i,"DESTINATION_AUTHTYPE_NOTFOUND",{enumerable:!0,get:function(){return u.DESTINATION_AUTHTYPE_NOTFOUND}}),Object.defineProperty(i,"API_BUSINESS_HUB_ENTERPRISE_PREFIX",{enumerable:!0,get:function(){return u.API_BUSINESS_HUB_ENTERPRISE_PREFIX}});const m=a(55379);Object.defineProperty(i,"loadManifest",{enumerable:!0,get:function(){return m.loadManifest}});const g=a(20787),f=a(60711),N=a(32864);Object.defineProperty(i,"getCFQuestions",{enumerable:!0,get:function(){return N.getCFQuestions}});const _=a(45048);class default_1 extends h.DeploymentGenerator{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(e,i){super(e,i),this.launchDeployConfigAsSubGenerator=i.launchDeployConfigAsSubGenerator??!1,this.launchStandaloneFromYui=i.launchStandaloneFromYui,this.appWizard=i.appWizard??r.AppWizard.create(i),this.vscode=i.vscode,this.options=i,this.destinationName=i.destinationName??"",this.addMtaDestination=i.addMTADestination??!1,this.lcapModeOnly=i.lcapModeOnly??!1,this.cloudServiceName=i.cloudServiceName||void 0,this.apiHubConfig=i.apiHubConfig,this.servicePath=i.appGenServicePath,this.serviceBase=i.appGenServiceHost,this.appPath=i.appRootPath??this.destinationRoot(),this.projectRoot=i.projectRoot??this.destinationRoot()}async initializing(){await super.initializing(),await(0,u.initI18n)(),h.DeploymentGenerator.logger?.debug((0,u.t)("cfGen.debug.initTelemetry")),(0,p.setYeomanEnvConflicterForce)(this.env,this.options.force),await p.TelemetryHelper.initTelemetrySettings({consumerModule:{name:"@sap-ux/cf-deploy-config-sub-generator",version:this.rootGeneratorVersion()},internalFeature:(0,c.isInternalFeaturesSettingEnabled)(),watchTelemetrySettingStore:!1}),this.launchDeployConfigAsSubGenerator||await this._init()}async _init(){s.sync(h.mtaExecutable)||(this.abort=!0,(0,h.handleErrorMessage)(this.appWizard,{errorType:h.ERROR_TYPE.NO_MTA_BIN})),await this._processProjectPaths(),await this._processProjectConfigs(),this.isAbapDirectServiceBinding=await(0,l.useAbapDirectServiceBinding)(this.appPath,!1,this.mtaPath),this.isCap||(this.lcapModeOnly=!1)}async _processProjectPaths(){const e=await(0,g.getMtaPath)(this.appPath);this.mtaPath=e?.mtaPath;const i=await(0,g.findCapProjectRoot)(this.appPath,!0,this.fs);if(i){s.sync(h.cdsExecutable)||(0,h.bail)(h.ErrorHandler.getErrorMsgFromType(h.ERROR_TYPE.NO_CDS_BIN)),this.isCap=!0,this.projectRoot=i;try{this.packageName=this.fs.readJSON((0,n.join)(this.projectRoot,g.FileName.Package))?.name??""}catch{}}else this.mtaPath&&(this.projectRoot=(0,n.dirname)(this.mtaPath))}async _processProjectConfigs(){const e=this.options.base??g.FileName.Ui5Yaml;this.fs.exists((0,n.join)(this.appPath,e))||(0,h.bail)(h.ErrorHandler.noBaseConfig(e)),this.deployConfigExists=this.fs.exists((0,n.join)(this.appPath,this.options.config??g.FileName.Ui5Yaml))}async prompting(){this.abort||(this.launchDeployConfigAsSubGenerator||await this._prompting(),await this._reconcileAnswersWithOptions())}async _prompting(){if(this.isCap&&this.projectRoot&&!this.mtaPath){if(h.DeploymentGenerator.logger?.debug((0,u.t)("cfGen.debug.capMissingMTA")),this.appRouterAnswers=await this.prompt(await(0,N.getCAPMTAQuestions)({projectRoot:this.projectRoot??process.cwd()})),!0!==this.appRouterAnswers.addCapMtaContinue)return void(this.abort=!0);this.appRouterAnswers.mtaId=this.packageName,this.destinationName=l.DefaultMTADestination,this.options.overwrite=!0,this.answers={},this.answers.destinationName=this.destinationName,this.answers.addManagedAppRouter=!1}else{await this._handleApiHubConfig();const e=await this._getCFQuestions();this.answers=await this.prompt(e)}}async _handleApiHubConfig(){if("API_HUB_ENTERPRISE"===this.apiHubConfig?.apiHubType){if(!this.servicePath){const e=await(0,m.loadManifest)(this.fs,this.appPath);this.servicePath=e?.["sap.app"]?.dataSources?.mainService?.uri}this.destinationName=(0,h.generateDestinationName)(u.API_BUSINESS_HUB_ENTERPRISE_PREFIX,this.servicePath)}}async _getCFQuestions(){return(0,N.getCFQuestions)({projectRoot:this.projectRoot,isAbapDirectServiceBinding:this.isAbapDirectServiceBinding,cfDestination:this.destinationName,isCap:this.isCap,addOverwrite:(0,h.showOverwriteQuestion)(this.deployConfigExists,this.launchDeployConfigAsSubGenerator,this.launchStandaloneFromYui,this.options.overwrite),apiHubConfig:this.apiHubConfig})}async _reconcileAnswersWithOptions(){const e=this.destinationName||this.answers.destinationName,i=await(0,h.getDestination)(e),a=this.options.isFullUrlDest??(i&&(0,d.isFullUrlDestination)(i))??!1,n=this.options.addManagedAppRouter??(this.options.routerType===_.RouterModuleType.Managed||this.answers.routerType===_.RouterModuleType.Managed),o=this.options.addAppFrontendRouter??(this.options.routerType===_.RouterModuleType.AppFront||this.answers.routerType===_.RouterModuleType.AppFront),s=this.options.destinationAuthType??i?.Authentication??u.DESTINATION_AUTHTYPE_NOTFOUND,r=this.options.overwrite??this.answers.overwrite;this.answers={destinationName:e,addManagedAppRouter:n,isDestinationFullUrl:a,destinationAuthentication:s,overwrite:r,addAppFrontendRouter:o}}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.generateCAPConfig)(this.appRouterAnswers,this.fs,h.DeploymentGenerator.logger),await(0,l.generateAppConfig)(this._getAppConfig(),this.fs,h.DeploymentGenerator.logger)}catch(e){this.abort=!0,(0,h.handleErrorMessage)(this.appWizard,{errorMsg:(0,u.t)("cfGen.error.writing",{error:e})})}}_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)h.DeploymentGenerator.logger?.info((0,u.t)("cfGen.info.skippedInstallation"));else try{await this._runNpmInstall(this.projectRoot),this.projectRoot!==this.appPath&&await this._runNpmInstall(this.appPath)}catch(e){(0,h.handleErrorMessage)(this.appWizard,{errorMsg:(0,u.t)("cfGen.error.install",{error:e.message})})}}async _runNpmInstall(e){const i="win32"===(0,o.platform)()?"npm.cmd":"npm";await this.spawnCommand(i,["install","--no-audit","--no-fund","--silent","--prefer-offline","--no-progress"],{cwd:e})}async end(){try{if(this.abort||!1===this.answers.overwrite)return;!this.options.launchStandaloneFromYui&&this.launchDeployConfigAsSubGenerator||!(0,p.isExtensionInstalled)(this.vscode,p.YUI_EXTENSION_ID,p.YUI_MIN_VER_FILES_GENERATED_MSG)||this.appWizard?.showInformation((0,u.t)("cfGen.info.filesGenerated"),r.MessageType.notification),await this._sendTelemetry()}catch(e){h.DeploymentGenerator.logger?.error((0,u.t)("cfGen.error.end",{error:e}))}}async _sendTelemetry(){const e=p.TelemetryHelper.createTelemetryData({DeployTarget:"CF",ManagedApprouter:this.answers.addManagedAppRouter,AppFrontendRouter:this.answers.addAppFrontendRouter,MTA:this.mtaPath?"true":"false",...this.options.telemetryData})??{};await(0,p.sendTelemetry)(f.EventName.DEPLOY_CONFIG,e,this.appPath)}}i.default=default_1},32864(e,i,a){Object.defineProperty(i,"__esModule",{value:!0}),i.getCFQuestions=async function getCFQuestions({projectRoot:e,isAbapDirectServiceBinding:i,cfDestination:a,isCap:l,addOverwrite:h,apiHubConfig:u,promptOptions:m}){const g=(0,n.isAppStudio)(),f=!!await(0,s.getMtaPath)(e),N=await(0,c.getCFChoices)({projectRoot:e,isCap:l,cfDestination:a,isAbapDirectServiceBinding:i,apiHubConfigType:u?.apiHubType}),_={[r.promptNames.destinationName]:{defaultValue:(0,c.destinationQuestionDefaultOption)(i,g,a),hint:!!i,useAutocomplete:(0,p.getHostEnvironment)()===p.hostEnvironment.cli,addBTPDestinationList:!!g&&!i,additionalChoiceList:N,...m?.destinationName},[r.promptNames.addManagedAppRouter]:{hide:!0,...m?.addManagedAppRouter},[r.promptNames.routerType]:{hide:f||l,...m?.routerType},[r.promptNames.overwriteCfConfig]:{hide:!h,...m?.overwriteCfConfig}};return o.DeploymentGenerator.logger?.debug((0,d.t)("cfGen.debug.promptOptions",{options:JSON.stringify(_)})),(0,r.getPrompts)(_,o.DeploymentGenerator.logger)},i.getCAPMTAQuestions=async function getCAPMTAQuestions({projectRoot:e}){let i=await async function getCFApprouterQuestionsForCap({projectRoot:e}){const i={[r.appRouterPromptNames.mtaPath]:e,[r.appRouterPromptNames.mtaId]:!1,[r.appRouterPromptNames.mtaDescription]:!1,[r.appRouterPromptNames.mtaVersion]:!1,[r.appRouterPromptNames.routerType]:!0,[r.appRouterPromptNames.addConnectivityService]:!0,[r.appRouterPromptNames.addABAPServiceBinding]:!1};return(0,r.getAppRouterPrompts)(i)}({projectRoot:e});return i=(0,l.withCondition)(i,e=>!0===e.addCapMtaContinue),i.unshift(...(0,o.getConfirmMtaContinuePrompt)()),i};const n=a(75199),o=a(4591),s=a(20787),r=a(45048),p=a(58012),c=a(55379),d=a(95644),l=a(12450)},55379(e,i,a){Object.defineProperty(i,"__esModule",{value:!0}),i.getCFChoices=async function getCFChoices({projectRoot:e,isAbapDirectServiceBinding:i,cfDestination:a,isCap:p,apiHubConfigType:d}){let l=[];const h=[{name:(0,c.t)("cfGen.prompts.abapBinding.name"),value:c.DESTINATION_CHOICE_DIRECT_SERVICE_BINDING}];if("API_HUB_ENTERPRISE"===d)l=[{name:a,value:a}];else{const d=!i&&(0,n.isAppStudio)()?await async function getCFSystemChoices(e,i,a){const n=[];try{let a=[];if(i){a=(await r.MtaConfig.newInstance(e)).getExposedDestinations(),a?.length&&n.push({name:(0,c.t)("cfGen.prompts.capInstanceBasedDest.name"),value:c.DEFAULT_MTA_DESTINATION})}else{const i=await(0,o.getMtaPath)(e),n=i?.mtaPath?.split(o.FileName.MtaYaml)[0];if(n){a=(await r.MtaConfig.newInstance(n)).getExposedDestinations(!0)}}a?.length&&a.forEach(e=>{n.push({name:(0,c.t)("cfGen.prompts.instanceBasedDest.name",{destination:e}),value:e})})}catch(e){s.DeploymentGenerator.logger?.debug((0,c.t)("cfGen.error.mtaDestinations",{error:e}))}a||n.splice(0,0,{name:(0,c.t)("cfGen.prompts.none.name"),value:c.DESTINATION_CHOICE_NONE});return n}(e,p,a):[];l=i?h:d}return l},i.destinationQuestionDefaultOption=function destinationQuestionDefaultOption(e,i,a){let n="";i?a?n=a:e?n=c.DESTINATION_CHOICE_DIRECT_SERVICE_BINDING:i&&(n=c.DESTINATION_CHOICE_NONE):n=a??"";return n},i.loadManifest=async function loadManifest(e,i){const a=(0,p.join)(await(0,o.getWebappPath)(i),o.FileName.Manifest),n=e.readJSON(a);n||(0,s.bail)(s.ErrorHandler.getErrorMsgFromType(s.ERROR_TYPE.NO_MANIFEST));n["sap.app"]?.id||(0,s.bail)(s.ErrorHandler.getErrorMsgFromType(s.ERROR_TYPE.NO_APP_NAME));return n};const n=a(75199),o=a(20787),s=a(4591),r=a(13149),p=a(76760),c=a(95644)},60711(e,i){var a;Object.defineProperty(i,"__esModule",{value:!0}),i.EventName=void 0,function(e){e.DEPLOY_CONFIG="DEPLOY_CONFIG"}(a||(i.EventName=a={}))},40737(e,i){Object.defineProperty(i,"__esModule",{value:!0}),i.DESTINATION_CHOICE_DIRECT_SERVICE_BINDING=i.DESTINATION_CHOICE_NONE=i.DESTINATION_AUTHTYPE_NOTFOUND=i.DEFAULT_MTA_DESTINATION=i.API_BUSINESS_HUB_ENTERPRISE_PREFIX=void 0,i.API_BUSINESS_HUB_ENTERPRISE_PREFIX="ABHE",i.DEFAULT_MTA_DESTINATION="fiori-default-srv-api",i.DESTINATION_AUTHTYPE_NOTFOUND="NotAvailable",i.DESTINATION_CHOICE_NONE="NONE",i.DESTINATION_CHOICE_DIRECT_SERVICE_BINDING="DIRECT_SERVICE_BINDING"},96758(e,i,a){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(i,"__esModule",{value:!0}),i.i18n=void 0,i.initI18n=initI18n,i.t=function t(e,a){a?.ns||(a=Object.assign(a??{},{ns:p}));return i.i18n.t(e,a)};const o=n(a(68801)),s=n(a(66211)),r=a(12450),p="cf-deploy-config-generator";async function initI18n(){await i.i18n.init({lng:"en",fallbackLng:"en",showSupportNotice:!1}),i.i18n.addResourceBundle("en",p,s.default),(0,r.addi18nResourceBundle)()}i.i18n=o.default.createInstance(),initI18n().catch(()=>{})},95644(e,i,a){var n=this&&this.__createBinding||(Object.create?function(e,i,a,n){void 0===n&&(n=a);var o=Object.getOwnPropertyDescriptor(i,a);o&&!("get"in o?!i.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return i[a]}}),Object.defineProperty(e,n,o)}:function(e,i,a,n){void 0===n&&(n=a),e[n]=i[a]}),o=this&&this.__exportStar||function(e,i){for(var a in e)"default"===a||Object.prototype.hasOwnProperty.call(i,a)||n(i,e,a)};Object.defineProperty(i,"__esModule",{value:!0}),o(a(40737),i),o(a(96758),i)},66211(e){e.exports=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}}"},"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}}."}}}')}};