UNPKG

@sap/generator-fiori

Version:

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

1 lines 11.8 kB
"use strict";exports.id=3997,exports.ids=[3997],exports.modules={56749(e,i,o){o.r(i),o.d(i,{default:()=>AdpFlpConfigGenerator});var r,n=o(91170),s=o(76760),a=o(43107),p=o(95652),c=o(19563);!function(e){e.ADP_FLP_CONFIG_ADDED="ADP_FLP_CONFIG_ADDED"}(r||(r={}));var h=o(99416),d=o(73667),g=o(94443),l=o(40511),u=o(7083),f=o(21038);async function getAbapServiceProvider(e,i,o){const{target:r,ignoreCertErrors:n=!1}=e,s={ignoreCertErrors:n};return o&&(s.auth={username:o.username,password:o.password}),(0,f.createAbapServiceProvider)(r,s,!1,i)}class AdpFlpConfigLogger{static _logger=g.DefaultLogger;static get logger(){return AdpFlpConfigLogger._logger}static set logger(e){AdpFlpConfigLogger._logger=e}static configureLogging(e,i,o,r,n,s){const a=s??new g.LogWrapper(i,o,n,e,r);AdpFlpConfigLogger.logger=a}}var m=o(68801);const C=JSON.parse('{"yuiNavSteps":{"flpCredentialsName":"SAP Fiori Launchpad Configuration - Credentials","flpCredentialsDesc":"Enter credentials for your adaptation project\'s system: ({{- system}}).","sysConfirmDesc":"Validates connection to the configured system.","flpConfigName":"SAP Fiori Launchpad Configuration: Tile Settings","tileSettingsName":"SAP Fiori Launchpad Configuration: Tile Handling","tileSettingsDescr":"Add a new tile or replace existing tiles of the base application.\\nProject: {{projectName}}","flpConfigReplaceCurrentTiles":"Existing Tiles (Title ⑊ Navigation Intent):\\n\\n{{- currentTiles}}","flpConfigReplaceTile":" • {{- title}} ⑊ {{- navigationIntent}}"},"info":{"flpConfigAdded":"SAP Fiori launchpad configuration added."},"error":{"projectNotSupported":"Unable to find a supported adaptation project.","fetchingManifest":"An error occurred when fetching the merged `manifest.json` file for the base application.","destinationNotFound":"Missing destination configuration in the `ui5.yaml` file.","destinationNotInSubaccount":"Destination not found in the subaccount: {{- destination}}.","systemNotFound":"Missing system configuration in the `ui5.yaml` file.","systemNotFoundInStore":"System not found in the system store: {{- systemUrl}}.","writingPhase":"An error occurred in the writing phase of the adaptation project\'s SAP Fiori launchpad configuration.","telemetry":"An error occurred when sending telemetry data. Error: {{- error}}.","updatingApp":"An error occurred updating the application with the SAP Fiori launchpad configuration. For more information, view the logs.","authenticationFailed":"Authentication failed.","projectNotCloudReady":"FLP Configuration is supported for Cloud Ready adaptation projects only","baseAppInboundsFetching":"Error while fetching base application inbounds","cfConfigRequired":"Cloud Foundry configuration is required for Cloud Foundry adaptation projects.","cfLoginRequired":"Cloud Foundry login required. Please run `cf login` and try again.","cfAppHostIdMissing":"Could not determine the `appHostId` from the project\'s `ui5.yaml` configuration.","cfInboundsFetchFailed":"Failed to fetch inbounds for the Cloud Foundry application: {{error}}","warningCachingNotSupported":"Warning: caching is not supported"}}');var y=o(67566);const b="adp-flp-config-sub-generator",A=m.createInstance();async function initI18n(){await A.init({lng:"en",fallbackLng:"en",showSupportNotice:!1}),A.addResourceBundle("en",b,C),(0,y.addi18nResourceBundle)(),(0,h.yg)()}function t(e,i){return i?.ns||(i=Object.assign(i??{},{ns:b})),A.t(e,i)}initI18n().catch(()=>{});const v="$adp-flp-config-cache",P=(0,g.getHostEnvironment)();function addToCache(e,i,o){logIfCacheMissing(e,o),e?.[v]&&Object.assign(e[v],i)}function getFromCache(e,i,o){return logIfCacheMissing(e,o),e?.[v]?.[i]}function logIfCacheMissing(e,i){P!==g.hostEnvironment.vscode||e?.[v]||i.info(t("logMessages.warningCachingNotSupported"))}var w=o(76178);class AdpFlpConfigGenerator extends n{setPromptsCallback;prompts;launchAsSubGen;appWizard;vscode;toolsLogger;projectRootPath="";answers;logger;authenticationRequired=!1;abort=!1;ui5Yaml;credentials;inbounds;layer;appId;variant;tileSettingsAnswers;provider;isCfProject=!1;constructor(e,i){super(e,i),this.appWizard=i.appWizard??d.AppWizard.create(i),this.launchAsSubGen=!!i.launchAsSubGen,this.toolsLogger=new c.ToolsLogger,this.logger=i.logger??g.DefaultLogger,this.projectRootPath=i.data?.projectRootPath??this.destinationRoot(),this.options=i,this.vscode=i.vscode,this.inbounds=i.inbounds,this.layer=i.layer,this.isCfProject=!!i.isCfProject,function initAppWizardCache(e,i){i&&!i[v]&&(i[v]={credentialsPrompted:!1},e.debug("AppWizard based cache initialized."))}(this.logger,this.appWizard),this._setupFLPConfigPrompts(),this._setupLogging()}async initializing(){await initI18n(),(0,g.setYeomanEnvConflicterForce)(this.env,this.options.force),this._setupFLPConfigPage(),!this.launchAsSubGen&&(await this._initializeStandAloneGenerator(),this.abort||this.authenticationRequired)||await g.TelemetryHelper.initTelemetrySettings({consumerModule:{name:"@sap/generator-fiori-deployment:adp-flp-config",version:this.rootGeneratorVersion()},internalFeature:(0,l.isInternalFeaturesSettingEnabled)(),watchTelemetrySettingStore:!1})}async prompting(){const e=getFromCache(this.appWizard,"credentialsPrompted",this.logger);if((this.authenticationRequired||e)&&await this._promptAuthentication(),this.abort)return;if(!this.launchAsSubGen&&!this.isCfProject&&(await this._validateCloudProject(),this.abort))return;this.tileSettingsAnswers=await this._promptTileActions(),this.tileSettingsAnswers?.[h.lw.tileHandlingAction]===h.iG.REPLACE&&this._setupReplacePage();const i=await(0,h.oO)(this.inbounds,(0,h.I)(this.tileSettingsAnswers,this.inbounds,this.variant,this.isCfProject));this.answers=await this.prompt(i)}async writing(){if(!this.abort)try{const e=(0,h.P)(this.answers,this.layer,this.tileSettingsAnswers,this.inbounds);await(0,p.generateInboundConfig)(this.projectRootPath,e,this.fs)}catch(e){throw this.logger.error(`Writing phase failed: ${e}`),new Error(t("error.updatingApp"))}}end(){if(function deleteCache(e,i){logIfCacheMissing(e,i),e?.[v]&&delete e[v]}(this.appWizard,this.logger),this.abort)return;this.launchAsSubGen||this.appWizard?.showInformation(t("info.flpConfigAdded"),d.MessageType.notification);const e=g.TelemetryHelper.createTelemetryData({appType:"adp-flp-config",...this.options.telemetryData})??{};e&&(0,g.sendTelemetry)(r.ADP_FLP_CONFIG_ADDED,e,this.projectRootPath).catch(e=>{this.logger.error(t("error.telemetry",{error:e}))})}async _promptAuthentication(){const e=await(0,y.getCredentialsPrompts)(async e=>{this.credentials=e;try{this.provider=await getAbapServiceProvider(this.ui5Yaml,this.toolsLogger,this.credentials),this.inbounds=await(0,p.getBaseAppInbounds)(this.appId,this.provider),addToCache(this.appWizard,{provider:this.provider,credentialsPrompted:!0},this.logger)}catch(e){if(!(0,a.isAxiosError)(e))throw this.logger.error(`Base application inbounds fetching failed: ${e}`),new Error(t("error.baseAppInboundsFetching"));return this.authenticationRequired=this._checkAuthRequired(e),this.authenticationRequired?t("error.authenticationFailed"):this._getErrorHandlerMessage(e)??!1}return!0}),i=await this._findSystemName(this.ui5Yaml.target);i&&(this.prompts.splice(0,0,[{name:t("yuiNavSteps.flpCredentialsName"),description:t("yuiNavSteps.flpCredentialsDesc",{system:i})}]),await this.prompt(e))}_handleFetchingError(e){if((0,a.isAxiosError)(e)){this.logger.error(`Base application inbounds fetching failed: ${e}. Status: ${e.response?.status}. URI: ${e.request?.path}`);const i=this._getErrorHandlerMessage(e);return void(i&&this._abortExecution("string"==typeof i?i:`${i?.message} ([${i.link.text}](${i.link.url}))`))}throw this.logger.error(`Base application inbounds fetching failed: ${e}`),new Error(t("error.baseAppInboundsFetching"))}_setupFLPConfigPage(){this.launchAsSubGen||this.prompts.splice(0,0,[{name:t("yuiNavSteps.flpConfigName"),description:""}])}_setupReplacePage(){const e=this.inbounds?Object.values(this.inbounds).map(e=>{const i=e.title??"";return t("yuiNavSteps.flpConfigReplaceTile",{navigationIntent:`${e.semanticObject}-${e.action}`,title:i})}):[],i=this.prompts.items.findIndex(e=>e.name===t("yuiNavSteps.flpConfigName"));this.prompts.splice(i,1,[{name:t("yuiNavSteps.flpConfigName"),description:t("yuiNavSteps.flpConfigReplaceCurrentTiles",{currentTiles:e.join("\n")})}])}_setupFLPConfigPrompts(){if(!this.launchAsSubGen)return this.prompts=new d.Prompts([]),void(this.setPromptsCallback=e=>{this.prompts&&this.prompts.setCallback(e)});this.prompts=this.options.prompts}_setTileSettingsPrompts(){if(this.launchAsSubGen)return;const e=this.prompts.items.findIndex(e=>e.name===t("yuiNavSteps.flpCredentialsName"));this.prompts.splice(e+1,0,[{name:t("yuiNavSteps.tileSettingsName"),description:t("yuiNavSteps.tileSettingsDescr",{projectName:(0,s.basename)(this.projectRootPath)})}])}async _findSystemName(e){const i=new p.SystemLookup(this.toolsLogger),o=(0,w.isAppStudio)(),r=await i.getSystemByName(o?e.destination:e.url);if(!r?.Name){const e=t(o?"error.destinationNotFound":"error.systemNotFoundInStore");return void this._abortExecution(e)}return r.Name}_abortExecution(e){(0,g.isCli)()?this.toolsLogger.error(e):this.vscode.window.showErrorMessage(e),this.abort=!0}_getErrorHandlerMessage(e){if(404===e.status)return t("error.projectNotCloudReady");return new y.ErrorHandler(void 0,void 0,"@sap-ux/adp-flp-config").getValidationErrorHelp(e)}_checkAuthRequired(e){return!(!(0,a.isAxiosError)(e)||401!==e.response?.status)}_setupLogging(){AdpFlpConfigLogger.configureLogging(this.options.logger,this.rootGeneratorName(),this.log,this.options.vscode,this.options.logLevel,this.options.logWrapper),this.logger=AdpFlpConfigLogger.logger}async _promptTileActions(){if(!this.inbounds)return;this._setTileSettingsPrompts();const e={existingFlpConfigInfo:{hide:!(!this.launchAsSubGen&&(0,p.flpConfigurationExists)(this.variant))}},i=(0,h.fi)(e);return this.prompt(i)}async _validateProjectType(){"Fiori Adaptation"===await(0,u.Ov)(this.projectRootPath)?this.isCfProject=await(0,p.isCFEnvironment)(this.projectRootPath):this._abortExecution(t("error.projectNotSupported"))}async _validateCloudProject(){await(0,p.getExistingAdpProjectType)(this.projectRootPath)!==a.AdaptationProjectType.CLOUD_READY&&this._abortExecution(t("error.projectNotCloudReady"))}async _initializeStandAloneGenerator(){await this._validateProjectType(),this.abort||(this.variant=await(0,p.getVariant)(this.projectRootPath,this.fs),this.appId=this.variant.reference,this.layer=this.variant.layer,this.isCfProject?await this._initializeCfGenerator():await this._initializeAbapGenerator())}async _initializeAbapGenerator(){this.ui5Yaml=await(0,p.getAdpConfig)(this.projectRootPath,(0,s.join)(this.projectRootPath,u.o3.Ui5Yaml)),await this._initAbapServiceProvider();try{this.inbounds=this.inbounds??await(0,p.getBaseAppInbounds)(this.appId,this.provider)}catch(e){if(this.authenticationRequired=this._checkAuthRequired(e),this.authenticationRequired)return;this._handleFetchingError(e)}}async _initializeCfGenerator(){const e=(0,p.loadCfConfig)(this.toolsLogger);if(!await(0,p.isLoggedInCf)(e,this.toolsLogger))return void this._abortExecution(t("error.cfLoginRequired"));const i=(0,p.getAppParamsFromUI5Yaml)(this.projectRootPath);if(i.appHostId)try{this.inbounds=this.inbounds??await(0,p.getCfBaseAppInbounds)(this.appId,i.appHostId,e,this.toolsLogger)}catch(e){this.toolsLogger.error(`CF inbounds fetching failed: ${e}`),this._abortExecution(t("error.cfInboundsFetchFailed",{error:e.message}))}else this._abortExecution(t("error.cfAppHostIdMissing"))}async _initAbapServiceProvider(){const e=getFromCache(this.appWizard,"provider",this.logger);e?this.provider=e:(this.provider=await getAbapServiceProvider(this.ui5Yaml,this.toolsLogger),addToCache(this.appWizard,{provider:this.provider},this.logger))}}}};