@sap/generator-fiori
Version:
Create an SAPUI5 application using SAP Fiori elements or a freestyle approach
1 lines • 13.7 kB
JavaScript
"use strict";exports.id=3997,exports.ids=[3997],exports.modules={70937(e,i,o){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(i,"__esModule",{value:!0});const n=r(o(91170)),s=o(76760),a=o(60987),p=o(85393),c=o(76277),d=o(63064),l=o(1484),h=o(73667),g=o(58012),u=o(98434),f=o(20787),m=o(91211),C=o(12450),b=o(75199),y=o(5313);class AdpFlpConfigGenerator extends n.default{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??h.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,(0,y.initAppWizardCache)(this.logger,this.appWizard),this._setupFLPConfigPrompts(),this._setupLogging()}async initializing(){await(0,m.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,u.isInternalFeaturesSettingEnabled)(),watchTelemetrySettingStore:!1})}async prompting(){const e=(0,y.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?.[l.tilePromptNames.tileHandlingAction]===l.tileActions.REPLACE&&this._setupReplacePage();const i=await(0,l.getPrompts)(this.inbounds,(0,l.getAdpFlpConfigPromptOptions)(this.tileSettingsAnswers,this.inbounds,this.variant));this.answers=await this.prompt(i)}async writing(){if(!this.abort)try{const e=(0,l.getAdpFlpInboundsWriterConfig)(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((0,m.t)("error.updatingApp"))}}end(){if((0,y.deleteCache)(this.appWizard,this.logger),this.abort)return;this.launchAsSubGen||this.appWizard?.showInformation((0,m.t)("info.flpConfigAdded"),h.MessageType.notification);const e=g.TelemetryHelper.createTelemetryData({appType:"adp-flp-config",...this.options.telemetryData})??{};e&&(0,g.sendTelemetry)(d.EventName.ADP_FLP_CONFIG_ADDED,e,this.projectRootPath).catch(e=>{this.logger.error((0,m.t)("error.telemetry",{error:e}))})}async _promptAuthentication(){const e=await(0,C.getCredentialsPrompts)(async e=>{this.credentials=e;try{this.provider=await(0,m.getAbapServiceProvider)(this.ui5Yaml,this.toolsLogger,this.credentials),this.inbounds=await(0,p.getBaseAppInbounds)(this.appId,this.provider),(0,y.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((0,m.t)("error.baseAppInboundsFetching"));return this.authenticationRequired=this._checkAuthRequired(e),this.authenticationRequired?(0,m.t)("error.authenticationFailed"):this._getErrorHandlerMessage(e)??!1}return!0}),i=await this._findSystemName(this.ui5Yaml.target);i&&(this.prompts.splice(0,0,[{name:(0,m.t)("yuiNavSteps.flpCredentialsName"),description:(0,m.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((0,m.t)("error.baseAppInboundsFetching"))}_setupFLPConfigPage(){this.launchAsSubGen||this.prompts.splice(0,0,[{name:(0,m.t)("yuiNavSteps.flpConfigName"),description:""}])}_setupReplacePage(){const e=this.inbounds?Object.values(this.inbounds).map(e=>{const i=e.title??"",o=`${e.semanticObject}-${e.action}`;return(0,m.t)("yuiNavSteps.flpConfigReplaceTile",{navigationIntent:o,title:i})}):[],i=this.prompts.items.findIndex(e=>e.name===(0,m.t)("yuiNavSteps.flpConfigName"));this.prompts.splice(i,1,[{name:(0,m.t)("yuiNavSteps.flpConfigName"),description:(0,m.t)("yuiNavSteps.flpConfigReplaceCurrentTiles",{currentTiles:e.join("\n")})}])}_setupFLPConfigPrompts(){if(!this.launchAsSubGen)return this.prompts=new h.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===(0,m.t)("yuiNavSteps.flpCredentialsName"));this.prompts.splice(e+1,0,[{name:(0,m.t)("yuiNavSteps.tileSettingsName"),description:(0,m.t)("yuiNavSteps.tileSettingsDescr",{projectName:(0,s.basename)(this.projectRootPath)})}])}async _findSystemName(e){const i=new p.SystemLookup(this.toolsLogger),o=(0,b.isAppStudio)(),r=await i.getSystemByName(o?e.destination:e.url);if(!r?.Name){const e=o?(0,m.t)("error.destinationNotFound"):(0,m.t)("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(0,m.t)("error.projectNotCloudReady");return new C.ErrorHandler(void 0,void 0,"@sap-ux/adp-flp-config").getValidationErrorHelp(e)}_checkAuthRequired(e){return!(!(0,a.isAxiosError)(e)||401!==e.response?.status)}_setupLogging(){m.AdpFlpConfigLogger.configureLogging(this.options.logger,this.rootGeneratorName(),this.log,this.options.vscode,this.options.logLevel,this.options.logWrapper),this.logger=m.AdpFlpConfigLogger.logger}async _promptTileActions(){if(!this.inbounds)return;this._setTileSettingsPrompts();const e={existingFlpConfigInfo:{hide:!(!this.launchAsSubGen&&(0,p.flpConfigurationExists)(this.variant))}},i=(0,l.getTileSettingsQuestions)(e);return this.prompt(i)}async _validateProjectType(){"Fiori Adaptation"===await(0,f.getAppType)(this.projectRootPath)?this.isCfProject=await(0,p.isCFEnvironment)(this.projectRootPath):this._abortExecution((0,m.t)("error.projectNotSupported"))}async _validateCloudProject(){await(0,p.getExistingAdpProjectType)(this.projectRootPath)!==a.AdaptationProjectType.CLOUD_READY&&this._abortExecution((0,m.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,f.FileName.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((0,m.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((0,m.t)("error.cfInboundsFetchFailed",{error:e.message}))}else this._abortExecution((0,m.t)("error.cfAppHostIdMissing"))}async _initAbapServiceProvider(){const e=(0,y.getFromCache)(this.appWizard,"provider",this.logger);e?this.provider=e:(this.provider=await(0,m.getAbapServiceProvider)(this.ui5Yaml,this.toolsLogger),(0,y.addToCache)(this.appWizard,{provider:this.provider},this.logger))}}i.default=AdpFlpConfigGenerator},63064(e,i){var o;Object.defineProperty(i,"__esModule",{value:!0}),i.EventName=void 0,function(e){e.ADP_FLP_CONFIG_ADDED="ADP_FLP_CONFIG_ADDED"}(o||(i.EventName=o={}))},5313(e,i,o){Object.defineProperty(i,"__esModule",{value:!0}),i.initAppWizardCache=function initAppWizardCache(e,i){i&&!i[s]&&(i[s]={credentialsPrompted:!1},e.debug("AppWizard based cache initialized."))},i.addToCache=function addToCache(e,i,o){logIfCacheMissing(e,o),e?.[s]&&Object.assign(e[s],i)},i.getFromCache=function getFromCache(e,i,o){return logIfCacheMissing(e,o),e?.[s]?.[i]},i.deleteCache=function deleteCache(e,i){logIfCacheMissing(e,i),e?.[s]&&delete e[s]};const r=o(58012),n=o(52251),s="$adp-flp-config-cache",a=(0,r.getHostEnvironment)();function logIfCacheMissing(e,i){a!==r.hostEnvironment.vscode||e?.[s]||i.info((0,n.t)("logMessages.warningCachingNotSupported"))}},52251(e,i,o){var r=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,o){o?.ns||(o=Object.assign(o??{},{ns:c}));return i.i18n.t(e,o)};const n=r(o(68801)),s=r(o(12345)),a=o(12450),p=o(1484),c="adp-flp-config-sub-generator";async function initI18n(){await i.i18n.init({lng:"en",fallbackLng:"en",showSupportNotice:!1}),i.i18n.addResourceBundle("en",c,s.default),(0,a.addi18nResourceBundle)(),(0,p.addi18nResourceBundle)()}i.i18n=n.default.createInstance(),initI18n().catch(()=>{})},91211(e,i,o){var r=this&&this.__createBinding||(Object.create?function(e,i,o,r){void 0===r&&(r=o);var n=Object.getOwnPropertyDescriptor(i,o);n&&!("get"in n?!i.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return i[o]}}),Object.defineProperty(e,r,n)}:function(e,i,o,r){void 0===r&&(r=o),e[r]=i[o]}),n=this&&this.__exportStar||function(e,i){for(var o in e)"default"===o||Object.prototype.hasOwnProperty.call(i,o)||r(i,e,o)};Object.defineProperty(i,"__esModule",{value:!0}),n(o(16102),i),n(o(82059),i),n(o(5313),i),n(o(52251),i)},82059(e,i,o){Object.defineProperty(i,"__esModule",{value:!0}),i.AdpFlpConfigLogger=void 0;const r=o(58012);class AdpFlpConfigLogger{static _logger=r.DefaultLogger;static get logger(){return AdpFlpConfigLogger._logger}static set logger(e){AdpFlpConfigLogger._logger=e}static configureLogging(e,i,o,n,s,a){const p=a??new r.LogWrapper(i,o,s,e,n);AdpFlpConfigLogger.logger=p}}i.AdpFlpConfigLogger=AdpFlpConfigLogger},16102(e,i,o){Object.defineProperty(i,"__esModule",{value:!0}),i.getAbapServiceProvider=async function getAbapServiceProvider(e,i,o){const{target:n,ignoreCertErrors:s=!1}=e,a={ignoreCertErrors:s};o&&(a.auth={username:o.username,password:o.password});return(0,r.createAbapServiceProvider)(n,a,!1,i)};const r=o(84823)},12345(e){e.exports=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"}}')}};