@sap/generator-fiori
Version:
Create an SAPUI5 application using SAP Fiori elements or a freestyle approach
7 lines (5 loc) • 13.3 kB
JavaScript
const __esmImportMetaUrl = require('node:url').pathToFileURL(__filename).href;
var V=Object.create;var f=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames;var K=Object.getPrototypeOf,X=Object.prototype.hasOwnProperty;var a=(i,t)=>f(i,"name",{value:t,configurable:!0});var E=(i,t)=>{for(var e in t)f(i,e,{get:t[e],enumerable:!0})},x=(i,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of J(t))!X.call(i,n)&&n!==e&&f(i,n,{get:()=>t[n],enumerable:!(s=Q(t,n))||s.enumerable});return i};var L=(i,t,e)=>(e=i!=null?V(K(i)):{},x(t||!i||!i.__esModule?f(e,"default",{value:i,enumerable:!0}):e,i)),Z=i=>x(f({},"__esModule",{value:!0}),i);var ot={};E(ot,{__entries:()=>it,__entry_generators_app:()=>Y});module.exports=Z(ot);var w={};E(w,{default:()=>d});var B=L(require("../commonlibs/yeoman-generator/index.js"),1),A=require("node:path"),u=require("../open-ux-shared/axios-extension/index.js"),r=require("../open-ux-shared/adp-tooling/index.js"),O=require("../open-ux-shared/logger/index.js");var y;(function(i){i.ADP_FLP_CONFIG_ADDED="ADP_FLP_CONFIG_ADDED"})(y||(y={}));var p=require("../open-ux-shared/flp-config-inquirer/index.js"),g=require("../commonlibs/yeoman-ui-types/index.js"),c=require("../fiori-generator-shared/dist/index.js"),W=require("../open-ux-shared/feature-toggle/index.js"),P=require("../open-ux-shared/project-access/index.js");var T=require("../open-ux-shared/system-access/index.js");async function v(i,t,e){let{target:s,ignoreCertErrors:n=!1}=i,h={ignoreCertErrors:n};return e&&(h.auth={username:e.username,password:e.password}),(0,T.createAbapServiceProvider)(s,h,!1,t)}a(v,"getAbapServiceProvider");var C=require("../fiori-generator-shared/dist/index.js");var m=class i{static{a(this,"AdpFlpConfigLogger")}static _logger=C.DefaultLogger;static get logger(){return i._logger}static set logger(t){i._logger=t}static configureLogging(t,e,s,n,h,S){let U=S??new C.LogWrapper(e,s,h,t,n);i.logger=U}};var b=require("../fiori-generator-shared/dist/index.js");var G=L(require("../commonlibs/i18next/index.js"),1);var D={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.
Project: {{projectName}}`,flpConfigReplaceCurrentTiles:`Existing Tiles (Title \u244A Navigation Intent):
{{- currentTiles}}`,flpConfigReplaceTile:" \u2022 {{- title}} \u244A {{- 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 q=require("../open-ux-shared/inquirer-common/index.js"),H=require("../open-ux-shared/flp-config-inquirer/index.js");var z="adp-flp-config-sub-generator",F=G.default.createInstance();async function N(){await F.init({lng:"en",fallbackLng:"en",showSupportNotice:!1}),F.addResourceBundle("en",z,D),(0,q.addi18nResourceBundle)(),(0,H.addi18nResourceBundle)()}a(N,"initI18n");function o(i,t){return t?.ns||(t=Object.assign(t??{},{ns:z})),F.t(i,t)}a(o,"t");N().catch(()=>{});var l="$adp-flp-config-cache",et=(0,b.getHostEnvironment)();function M(i,t){t&&!t[l]&&(t[l]={credentialsPrompted:!1},i.debug("AppWizard based cache initialized."))}a(M,"initAppWizardCache");function j(i,t,e){R(i,e),i?.[l]&&Object.assign(i[l],t)}a(j,"addToCache");function I(i,t,e){return R(i,e),i?.[l]?.[t]}a(I,"getFromCache");function $(i,t){R(i,t),i?.[l]&&delete i[l]}a($,"deleteCache");function R(i,t){et===b.hostEnvironment.vscode&&!i?.[l]&&t.info(o("logMessages.warningCachingNotSupported"))}a(R,"logIfCacheMissing");var _=require("../open-ux-shared/inquirer-common/index.js"),k=require("../open-ux-shared/btp-utils/index.js");var d=class extends B.default{static{a(this,"AdpFlpConfigGenerator")}setPromptsCallback;prompts;launchAsSubGen;appWizard;vscode;toolsLogger;projectRootPath="";answers;logger;authenticationRequired=!1;abort=!1;ui5Yaml;credentials;inbounds;layer;appId;variant;tileSettingsAnswers;provider;isCfProject=!1;constructor(t,e){super(t,e),this.appWizard=e.appWizard??g.AppWizard.create(e),this.launchAsSubGen=!!e.launchAsSubGen,this.toolsLogger=new O.ToolsLogger,this.logger=e.logger??c.DefaultLogger,this.projectRootPath=e.data?.projectRootPath??this.destinationRoot(),this.options=e,this.vscode=e.vscode,this.inbounds=e.inbounds,this.layer=e.layer,this.isCfProject=!!e.isCfProject,M(this.logger,this.appWizard),this._setupFLPConfigPrompts(),this._setupLogging()}async initializing(){await N(),(0,c.setYeomanEnvConflicterForce)(this.env,this.options.force),this._setupFLPConfigPage(),!(!this.launchAsSubGen&&(await this._initializeStandAloneGenerator(),this.abort||this.authenticationRequired))&&await c.TelemetryHelper.initTelemetrySettings({consumerModule:{name:"@sap/generator-fiori-deployment:adp-flp-config",version:this.rootGeneratorVersion()},internalFeature:(0,W.isInternalFeaturesSettingEnabled)(),watchTelemetrySettingStore:!1})}async prompting(){let t=I(this.appWizard,"credentialsPrompted",this.logger);if((this.authenticationRequired||t)&&await this._promptAuthentication(),this.abort||!this.launchAsSubGen&&!this.isCfProject&&(await this._validateCloudProject(),this.abort))return;this.tileSettingsAnswers=await this._promptTileActions(),this.tileSettingsAnswers?.[p.tilePromptNames.tileHandlingAction]===p.tileActions.REPLACE&&this._setupReplacePage();let e=await(0,p.getPrompts)(this.inbounds,(0,p.getAdpFlpConfigPromptOptions)(this.tileSettingsAnswers,this.inbounds,this.variant,this.isCfProject));this.answers=await this.prompt(e)}async writing(){if(!this.abort)try{let t=(0,p.getAdpFlpInboundsWriterConfig)(this.answers,this.layer,this.tileSettingsAnswers,this.inbounds);await(0,r.generateInboundConfig)(this.projectRootPath,t,this.fs)}catch(t){throw this.logger.error(`Writing phase failed: ${t}`),new Error(o("error.updatingApp"))}}end(){if($(this.appWizard,this.logger),this.abort)return;this.launchAsSubGen||this.appWizard?.showInformation(o("info.flpConfigAdded"),g.MessageType.notification);let t=c.TelemetryHelper.createTelemetryData({appType:"adp-flp-config",...this.options.telemetryData})??{};t&&(0,c.sendTelemetry)(y.ADP_FLP_CONFIG_ADDED,t,this.projectRootPath).catch(e=>{this.logger.error(o("error.telemetry",{error:e}))})}async _promptAuthentication(){let t=await(0,_.getCredentialsPrompts)(async s=>{this.credentials=s;try{this.provider=await v(this.ui5Yaml,this.toolsLogger,this.credentials),this.inbounds=await(0,r.getBaseAppInbounds)(this.appId,this.provider),j(this.appWizard,{provider:this.provider,credentialsPrompted:!0},this.logger)}catch(n){if(!(0,u.isAxiosError)(n))throw this.logger.error(`Base application inbounds fetching failed: ${n}`),new Error(o("error.baseAppInboundsFetching"));return this.authenticationRequired=this._checkAuthRequired(n),this.authenticationRequired?o("error.authenticationFailed"):this._getErrorHandlerMessage(n)??!1}return!0}),e=await this._findSystemName(this.ui5Yaml.target);e&&(this.prompts.splice(0,0,[{name:o("yuiNavSteps.flpCredentialsName"),description:o("yuiNavSteps.flpCredentialsDesc",{system:e})}]),await this.prompt(t))}_handleFetchingError(t){if((0,u.isAxiosError)(t)){this.logger.error(`Base application inbounds fetching failed: ${t}. Status: ${t.response?.status}. URI: ${t.request?.path}`);let e=this._getErrorHandlerMessage(t);e&&this._abortExecution(typeof e=="string"?e:`${e?.message} ([${e.link.text}](${e.link.url}))`);return}throw this.logger.error(`Base application inbounds fetching failed: ${t}`),new Error(o("error.baseAppInboundsFetching"))}_setupFLPConfigPage(){this.launchAsSubGen||this.prompts.splice(0,0,[{name:o("yuiNavSteps.flpConfigName"),description:""}])}_setupReplacePage(){let t=this.inbounds?Object.values(this.inbounds).map(n=>{let h=n.title??"",S=`${n.semanticObject}-${n.action}`;return o("yuiNavSteps.flpConfigReplaceTile",{navigationIntent:S,title:h})}):[],s=this.prompts.items.findIndex(n=>n.name===o("yuiNavSteps.flpConfigName"));this.prompts.splice(s,1,[{name:o("yuiNavSteps.flpConfigName"),description:o("yuiNavSteps.flpConfigReplaceCurrentTiles",{currentTiles:t.join(`
`)})}])}_setupFLPConfigPrompts(){if(!this.launchAsSubGen){this.prompts=new g.Prompts([]),this.setPromptsCallback=t=>{this.prompts&&this.prompts.setCallback(t)};return}this.prompts=this.options.prompts}_setTileSettingsPrompts(){if(this.launchAsSubGen)return;let e=this.prompts.items.findIndex(s=>s.name===o("yuiNavSteps.flpCredentialsName"));this.prompts.splice(e+1,0,[{name:o("yuiNavSteps.tileSettingsName"),description:o("yuiNavSteps.tileSettingsDescr",{projectName:(0,A.basename)(this.projectRootPath)})}])}async _findSystemName(t){let e=new r.SystemLookup(this.toolsLogger),s=(0,k.isAppStudio)(),n=await e.getSystemByName(s?t.destination:t.url);if(!n?.Name){let h=s?o("error.destinationNotFound"):o("error.systemNotFoundInStore");this._abortExecution(h);return}return n.Name}_abortExecution(t){(0,c.isCli)()?this.toolsLogger.error(t):this.vscode.window.showErrorMessage(t),this.abort=!0}_getErrorHandlerMessage(t){return t.status===404?o("error.projectNotCloudReady"):new _.ErrorHandler(void 0,void 0,"@sap-ux/adp-flp-config").getValidationErrorHelp(t)}_checkAuthRequired(t){return!!((0,u.isAxiosError)(t)&&t.response?.status===401)}_setupLogging(){m.configureLogging(this.options.logger,this.rootGeneratorName(),this.log,this.options.vscode,this.options.logLevel,this.options.logWrapper),this.logger=m.logger}async _promptTileActions(){if(!this.inbounds)return;this._setTileSettingsPrompts();let e={existingFlpConfigInfo:{hide:!(!this.launchAsSubGen&&(0,r.flpConfigurationExists)(this.variant))}},s=(0,p.getTileSettingsQuestions)(e);return this.prompt(s)}async _validateProjectType(){if(!(await(0,P.getAppType)(this.projectRootPath)==="Fiori Adaptation")){this._abortExecution(o("error.projectNotSupported"));return}this.isCfProject=await(0,r.isCFEnvironment)(this.projectRootPath)}async _validateCloudProject(){await(0,r.getExistingAdpProjectType)(this.projectRootPath)!==u.AdaptationProjectType.CLOUD_READY&&this._abortExecution(o("error.projectNotCloudReady"))}async _initializeStandAloneGenerator(){await this._validateProjectType(),!this.abort&&(this.variant=await(0,r.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,r.getAdpConfig)(this.projectRootPath,(0,A.join)(this.projectRootPath,P.FileName.Ui5Yaml)),await this._initAbapServiceProvider();try{this.inbounds=this.inbounds??await(0,r.getBaseAppInbounds)(this.appId,this.provider)}catch(t){if(this.authenticationRequired=this._checkAuthRequired(t),this.authenticationRequired)return;this._handleFetchingError(t)}}async _initializeCfGenerator(){let t=(0,r.loadCfConfig)(this.toolsLogger);if(!await(0,r.isLoggedInCf)(t,this.toolsLogger)){this._abortExecution(o("error.cfLoginRequired"));return}let e=(0,r.getAppParamsFromUI5Yaml)(this.projectRootPath);if(!e.appHostId){this._abortExecution(o("error.cfAppHostIdMissing"));return}try{this.inbounds=this.inbounds??await(0,r.getCfBaseAppInbounds)(this.appId,e.appHostId,t,this.toolsLogger)}catch(s){this.toolsLogger.error(`CF inbounds fetching failed: ${s}`),this._abortExecution(o("error.cfInboundsFetchFailed",{error:s.message}))}}async _initAbapServiceProvider(){let t=I(this.appWizard,"provider",this.logger);if(t){this.provider=t;return}this.provider=await v(this.ui5Yaml,this.toolsLogger),j(this.appWizard,{provider:this.provider},this.logger)}};var Y=w&&d?d:w,it={"generators/app":Y};0&&(module.exports={__entries,__entry_generators_app});