UNPKG

@sap/generator-fiori

Version:

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

4 lines (3 loc) 18.3 kB
const __esmImportMetaUrl = require('node:url').pathToFileURL(__filename).href; var Et=Object.create;var b=Object.defineProperty;var vt=Object.getOwnPropertyDescriptor;var It=Object.getOwnPropertyNames;var Rt=Object.getPrototypeOf,St=Object.prototype.hasOwnProperty;var s=(e,t)=>b(e,"name",{value:t,configurable:!0});var Dt=(e,t)=>()=>{try{return t||e((t={exports:{}}).exports,t),t.exports}catch(i){throw t=0,i}},j=(e,t)=>{for(var i in t)b(e,i,{get:t[i],enumerable:!0})},X=(e,t,i,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of It(t))!St.call(e,o)&&o!==i&&b(e,o,{get:()=>t[o],enumerable:!(a=vt(t,o))||a.enumerable});return e};var U=(e,t,i)=>(i=e!=null?Et(Rt(e)):{},X(t||!e||!e.__esModule?b(i,"default",{value:e,enumerable:!0}):i,e)),Mt=e=>X(b({},"__esModule",{value:!0}),e);var z=Dt((qt,Z)=>{"use strict";var I=require("../commonlibs/async/index.js"),J=require("fs"),Y=require("path");Z.exports=r;r.async=r;r.sync=Ft;r.all=xt;r.all.sync=Ot;r.some=Gt;r.some.sync=Bt;r.first=Ht;r.first.sync=jt;r.every=r.all;r.any=r.some;function r(e,t){I.some(K(e),Ut,t)}s(r,"hasbin");function Ft(e){return K(e).some(Yt)}s(Ft,"hasbinSync");function xt(e,t){I.every(e,r.async,t)}s(xt,"hasbinAll");function Ot(e){return e.every(r.sync)}s(Ot,"hasbinAllSync");function Gt(e,t){I.some(e,r.async,t)}s(Gt,"hasbinSome");function Bt(e){return e.some(r.sync)}s(Bt,"hasbinSomeSync");function Ht(e,t){I.detect(e,r.async,function(i){t(i||!1)})}s(Ht,"hasbinFirst");function jt(e){var t=e.filter(r.sync);return t.length?t[0]:!1}s(jt,"hasbinFirstSync");function K(e){var t=process.env.PATH||"",i=process.env.PATHEXT||"";return t.replace(/["]+/g,"").split(Y.delimiter).map(function(a){return i.split(Y.delimiter).map(function(o){return Y.join(a,e+o)})}).reduce(function(a,o){return a.concat(o)})}s(K,"getPaths");function Ut(e,t){J.stat(e,function(i,a){if(i)return t(!1);t(a.isFile())})}s(Ut,"fileExists");function Yt(e){try{return J.statSync(e).isFile()}catch{return!1}}s(Yt,"fileExistsSync")});var Vt={};j(Vt,{API_BUSINESS_HUB_ENTERPRISE_PREFIX:()=>R,ApiHubType:()=>Q.ApiHubType,DESTINATION_AUTHTYPE_NOTFOUND:()=>S,__entries:()=>Lt,__entry_generators_app:()=>Pt,__entry_generators_app_router:()=>bt,getCFQuestions:()=>x,loadManifest:()=>D});module.exports=Mt(Vt);var G={};j(G,{API_BUSINESS_HUB_ENTERPRISE_PREFIX:()=>R,ApiHubType:()=>Q.ApiHubType,DESTINATION_AUTHTYPE_NOTFOUND:()=>S,default:()=>C,getCFQuestions:()=>x,loadManifest:()=>D});var A=require("node:path"),ut=require("node:os"),V=U(z(),1),O=require("../commonlibs/yeoman-ui-types/index.js"),l=require("../fiori-generator-shared/dist/index.js"),mt=require("../open-ux-shared/feature-toggle/index.js"),dt=require("../open-ux-shared/btp-utils/index.js"),d=require("../cf-deploy-config-writer/dist/index.js"),n=require("../open-ux-shared/deploy-config-generator-shared/index.js");var R="ABHE",$="fiori-default-srv-api",S="NotAvailable",W="NONE",k="DIRECT_SERVICE_BINDING";var et=U(require("../commonlibs/i18next/index.js"),1);var tt={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: {{- 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 it=require("../open-ux-shared/inquirer-common/index.js");var nt="cf-deploy-config-generator",L=et.default.createInstance();async function N(){await L.init({lng:"en",fallbackLng:"en",showSupportNotice:!1}),L.addResourceBundle("en",nt,tt),(0,it.addi18nResourceBundle)()}s(N,"initI18n");function p(e,t){return t?.ns||(t=Object.assign(t??{},{ns:nt})),L.t(e,t)}s(p,"t");N().catch(()=>{});var at=require("../open-ux-shared/btp-utils/index.js"),w=require("../open-ux-shared/project-access/index.js"),m=require("../open-ux-shared/deploy-config-generator-shared/index.js"),T=require("../cf-deploy-config-writer/dist/index.js"),st=require("node:path");async function ot({projectRoot:e,isAbapDirectServiceBinding:t,cfDestination:i,isCap:a,apiHubConfigType:o}){let h=[],u=[{name:p("cfGen.prompts.abapBinding.name"),value:k}];if(o===T.ApiHubType.apiHubEnterprise)h=[{name:i,value:i}];else{let P=!t&&(0,at.isAppStudio)()?await Wt(e,a,i):[];h=t?u:P}return h}s(ot,"getCFChoices");async function Wt(e,t,i){let a=[];try{let o=[];if(t){let h=await T.MtaConfig.newInstance(e);o=h.getExposedDestinations(),h.hasResource("destination")&&a.push({name:p("cfGen.prompts.capInstanceBasedDest.name"),value:$})}else{let u=(await(0,w.getMtaPath)(e))?.mtaPath?.split(w.FileName.MtaYaml)[0];u&&(o=(await T.MtaConfig.newInstance(u)).getExposedDestinations(!0))}o?.length&&o.forEach(h=>{a.push({name:p("cfGen.prompts.instanceBasedDest.name",{destination:h}),value:h})})}catch(o){m.DeploymentGenerator.logger?.debug(p("cfGen.error.mtaDestinations",{error:o}))}return i||a.splice(0,0,{name:p("cfGen.prompts.none.name"),value:W}),a}s(Wt,"getCFSystemChoices");function rt(e,t,i){let a="";return t?i?a=i:e?a=k:t&&(a=W):a=i??"",a}s(rt,"destinationQuestionDefaultOption");async function D(e,t){let i=(0,st.join)(await(0,w.getWebappPath)(t),w.FileName.Manifest),a=e.readJSON(i);return a||(0,m.bail)(m.ErrorHandler.getErrorMsgFromType(m.ERROR_TYPE.NO_MANIFEST)),a["sap.app"]?.id||(0,m.bail)(m.ErrorHandler.getErrorMsgFromType(m.ERROR_TYPE.NO_APP_NAME)),a}s(D,"loadManifest");var y=require("../open-ux-shared/project-access/index.js");var M;(function(e){e.DEPLOY_CONFIG="DEPLOY_CONFIG"})(M||(M={}));var pt=require("../open-ux-shared/btp-utils/index.js"),E=require("../open-ux-shared/deploy-config-generator-shared/index.js"),ct=require("../open-ux-shared/project-access/index.js"),c=require("../open-ux-shared/cf-deploy-config-inquirer/index.js"),F=require("../fiori-generator-shared/dist/index.js");var ht=require("../open-ux-shared/inquirer-common/index.js");async function x({projectRoot:e,isAbapDirectServiceBinding:t,cfDestination:i,isCap:a,addOverwrite:o,apiHubConfig:h,promptOptions:u}){let P=(0,pt.isAppStudio)(),Nt=!!await(0,ct.getMtaPath)(e),Tt=await ot({projectRoot:e,isCap:a,cfDestination:i,isAbapDirectServiceBinding:t,apiHubConfigType:h?.apiHubType}),q={[c.promptNames.destinationName]:{defaultValue:rt(t,P,i),hint:!!t,useAutocomplete:(0,F.getHostEnvironment)()===F.hostEnvironment.cli,addBTPDestinationList:P?!t:!1,additionalChoiceList:Tt,...u?.destinationName},[c.promptNames.addManagedAppRouter]:{hide:!0,...u?.addManagedAppRouter},[c.promptNames.routerType]:{hide:Nt||a,...u?.routerType},[c.promptNames.overwriteCfConfig]:{hide:!o,...u?.overwriteCfConfig}};return E.DeploymentGenerator.logger?.debug(p("cfGen.debug.promptOptions",{options:JSON.stringify({...q,isCap:a,addOverwrite:o,cfDestination:i,isAbapDirectServiceBinding:t})})),(0,c.getPrompts)(q,E.DeploymentGenerator.logger)}s(x,"getCFQuestions");async function kt({projectRoot:e}){let t={[c.appRouterPromptNames.mtaPath]:e,[c.appRouterPromptNames.mtaId]:!1,[c.appRouterPromptNames.mtaDescription]:!1,[c.appRouterPromptNames.mtaVersion]:!1,[c.appRouterPromptNames.routerType]:!0,[c.appRouterPromptNames.addConnectivityService]:!0,[c.appRouterPromptNames.addABAPServiceBinding]:!1};return(0,c.getAppRouterPrompts)(t)}s(kt,"getCFApprouterQuestionsForCap");async function lt({projectRoot:e}){let t=await kt({projectRoot:e});return t=(0,ht.withCondition)(t,i=>i.addCapMtaContinue===!0),t.unshift(...(0,E.getConfirmMtaContinuePrompt)()),t}s(lt,"getCAPMTAQuestions");var v=require("../open-ux-shared/cf-deploy-config-inquirer/index.js"),Q=require("../cf-deploy-config-writer/dist/index.js");var C=class extends n.DeploymentGenerator{static{s(this,"default")}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,t){super(e,t),this.launchDeployConfigAsSubGenerator=t.launchDeployConfigAsSubGenerator??!1,this.launchStandaloneFromYui=t.launchStandaloneFromYui,this.appWizard=t.appWizard??O.AppWizard.create(t),this.vscode=t.vscode,this.options=t,this.destinationName=t.destinationName??"",this.addMtaDestination=t.addMTADestination??!1,this.lcapModeOnly=t.lcapModeOnly??!1,this.cloudServiceName=t.cloudServiceName||void 0,this.apiHubConfig=t.apiHubConfig,this.servicePath=t.appGenServicePath,this.serviceBase=t.appGenServiceHost,this.appPath=t.appRootPath??this.destinationRoot(),this.projectRoot=t.projectRoot??this.destinationRoot()}async initializing(){await super.initializing(),await N(),n.DeploymentGenerator.logger?.debug(p("cfGen.debug.initTelemetry")),(0,l.setYeomanEnvConflicterForce)(this.env,this.options.force),await l.TelemetryHelper.initTelemetrySettings({consumerModule:{name:"@sap-ux/cf-deploy-config-sub-generator",version:this.rootGeneratorVersion()},internalFeature:(0,mt.isInternalFeaturesSettingEnabled)(),watchTelemetrySettingStore:!1}),this.launchDeployConfigAsSubGenerator||await this._init()}async _init(){V.sync(n.mtaExecutable)||(this.abort=!0,(0,n.handleErrorMessage)(this.appWizard,{errorType:n.ERROR_TYPE.NO_MTA_BIN})),await this._processProjectPaths(),await this._processProjectConfigs(),this.isAbapDirectServiceBinding=await(0,d.useAbapDirectServiceBinding)(this.appPath,!1,this.mtaPath),this.isCap||(this.lcapModeOnly=!1)}async _processProjectPaths(){let e=await(0,y.getMtaPath)(this.appPath);this.mtaPath=e?.mtaPath;let t=await(0,y.findCapProjectRoot)(this.appPath,!0,this.fs);if(t){V.sync(n.cdsExecutable)||(0,n.bail)(n.ErrorHandler.getErrorMsgFromType(n.ERROR_TYPE.NO_CDS_BIN)),this.isCap=!0,this.projectRoot=t;try{this.packageName=this.fs.readJSON((0,A.join)(this.projectRoot,y.FileName.Package))?.name??""}catch{}}else this.mtaPath&&(this.projectRoot=(0,A.dirname)(this.mtaPath))}async _processProjectConfigs(){let e=this.options.base??y.FileName.Ui5Yaml;this.fs.exists((0,A.join)(this.appPath,e))||(0,n.bail)(n.ErrorHandler.noBaseConfig(e)),this.deployConfigExists=this.fs.exists((0,A.join)(this.appPath,this.options.config??y.FileName.Ui5Yaml))}async prompting(){this.abort||(this.launchDeployConfigAsSubGenerator||await this._prompting(),await this._reconcileAnswersWithOptions())}async _prompting(){if(this.isCap&&this.projectRoot&&!this.mtaPath){if(n.DeploymentGenerator.logger?.debug(p("cfGen.debug.capMissingMTA")),this.appRouterAnswers=await this.prompt(await lt({projectRoot:this.projectRoot??process.cwd()})),this.appRouterAnswers.addCapMtaContinue!==!0){this.abort=!0;return}this.appRouterAnswers.mtaId=this.packageName,this.destinationName=d.DefaultMTADestination,this.options.overwrite=!0,this.answers={},this.answers.destinationName=this.destinationName,this.answers.addManagedAppRouter=!1}else{await this._handleApiHubConfig();let t=await this._getCFQuestions();this.answers=await this.prompt(t)}}async _handleApiHubConfig(){if(this.apiHubConfig?.apiHubType===d.ApiHubType.apiHubEnterprise){if(!this.servicePath){let e=await D(this.fs,this.appPath);this.servicePath=e?.["sap.app"]?.dataSources?.mainService?.uri}this.destinationName=(0,n.generateDestinationName)(R,this.servicePath)}}async _getCFQuestions(){return x({projectRoot:this.projectRoot,isAbapDirectServiceBinding:this.isAbapDirectServiceBinding,cfDestination:this.destinationName,isCap:this.isCap,addOverwrite:(0,n.showOverwriteQuestion)(this.deployConfigExists,this.launchDeployConfigAsSubGenerator,this.launchStandaloneFromYui,this.options.overwrite),apiHubConfig:this.apiHubConfig})}async _reconcileAnswersWithOptions(){let e=this.destinationName||this.answers.destinationName,t=await(0,n.getDestination)(e),i=this.options.isFullUrlDest??(t&&(0,dt.isFullUrlDestination)(t))??!1;i&&n.DeploymentGenerator.logger?.warn(p("cfGen.warn.fullUrlDestination"));let a=this.options.addManagedAppRouter??(this.options.routerType===v.RouterModuleType.Managed||this.answers.routerType===v.RouterModuleType.Managed),o=this.options.addAppFrontendRouter??(this.options.routerType===v.RouterModuleType.AppFront||this.answers.routerType===v.RouterModuleType.AppFront),h=this.options.destinationAuthType??t?.Authentication??S,u=this.options.overwrite??this.answers.overwrite;this.answers={destinationName:e,addManagedAppRouter:a,isDestinationFullUrl:i,destinationAuthentication:h,overwrite:u,addAppFrontendRouter:o}}async writing(){this.abort||this.options.overwrite===!1||(this.launchDeployConfigAsSubGenerator?(await this._init(),await this._writing()):await this._writing())}async _writing(){try{this.appRouterAnswers&&await(0,d.generateCAPConfig)(this.appRouterAnswers,this.fs,n.DeploymentGenerator.logger),await(0,d.generateAppConfig)(this._getAppConfig(),this.fs,n.DeploymentGenerator.logger)}catch(e){this.abort=!0,(0,n.handleErrorMessage)(this.appWizard,{errorMsg:p("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(){this.options.overwrite!==!1&&!this.abort&&await this._install()}async _install(){if(this.options.skipInstall)n.DeploymentGenerator.logger?.info(p("cfGen.info.skippedInstallation"));else try{await this._runNpmInstall(this.projectRoot),this.projectRoot!==this.appPath&&await this._runNpmInstall(this.appPath)}catch(e){(0,n.handleErrorMessage)(this.appWizard,{errorMsg:p("cfGen.error.install",{error:e.message})})}}async _runNpmInstall(e){let t=(0,ut.platform)()==="win32"?"npm.cmd":"npm";await this.spawnCommand(t,["install","--no-audit","--no-fund","--silent","--prefer-offline","--no-progress"],{cwd:e})}async end(){try{if(this.abort||this.answers.overwrite===!1)return;(this.options.launchStandaloneFromYui||!this.launchDeployConfigAsSubGenerator)&&(0,l.isExtensionInstalled)(this.vscode,l.YUI_EXTENSION_ID,l.YUI_MIN_VER_FILES_GENERATED_MSG)&&this.appWizard?.showInformation(p("cfGen.info.filesGenerated"),O.MessageType.notification),await this._sendTelemetry()}catch(e){n.DeploymentGenerator.logger?.error(p("cfGen.error.end",{error:e}))}}async _sendTelemetry(){let e=l.TelemetryHelper.createTelemetryData({DeployTarget:"CF",ManagedApprouter:this.answers.addManagedAppRouter,AppFrontendRouter:this.answers.addAppFrontendRouter,MTA:this.mtaPath?"true":"false",...this.options.telemetryData})??{};await(0,l.sendTelemetry)(M.DEPLOY_CONFIG,e,this.appPath)}};var H={};j(H,{default:()=>_});var wt=require("node:path"),At=U(z(),1),Ct=require("node:os"),B=require("../commonlibs/yeoman-ui-types/index.js"),g=require("../open-ux-shared/deploy-config-generator-shared/index.js"),f=require("../open-ux-shared/cf-deploy-config-inquirer/index.js"),_t=require("../cf-deploy-config-writer/dist/index.js");var ft="Application Router Generator",gt=[{name:"Application Router Configuration",description:"Configure the Cloud Foundry application router"}],yt="0.0.1";var _=class extends g.DeploymentGenerator{static{s(this,"default")}appWizard;prompts;answers;abort=!1;setPromptsCallback;constructor(e,t){super(e,t),this.appWizard=t.appWizard??B.AppWizard.create(t),this.options=t,this.appWizard.setHeaderTitle(ft),this.prompts=new B.Prompts(gt),this.setPromptsCallback=i=>{this.prompts&&this.prompts.setCallback(i)}}async initializing(){await super.initializing(),await N(),this._initFromProjectConfig()}_initFromProjectConfig(){At.sync(g.mtaExecutable)||((0,g.handleErrorMessage)(this.appWizard,{errorType:g.ERROR_TYPE.NO_MTA_BIN}),this.abort=!0)}async prompting(){if(this.abort)return;let e={[f.appRouterPromptNames.mtaPath]:this.destinationRoot()??process.cwd(),[f.appRouterPromptNames.mtaId]:!0,[f.appRouterPromptNames.mtaDescription]:!0,[f.appRouterPromptNames.mtaVersion]:!1,[f.appRouterPromptNames.routerType]:!0,[f.appRouterPromptNames.addConnectivityService]:!0,[f.appRouterPromptNames.addABAPServiceBinding]:!0},t=await(0,f.getAppRouterPrompts)(e);this.answers=await this.prompt(t)}async writing(){if(this.abort)return;this.destinationRoot((0,wt.join)(this.answers.mtaPath,this.answers.mtaId)),g.DeploymentGenerator.logger?.debug(p("appRouterGen.debug.projectPath",{destinationPath:this.destinationRoot()}));let e;this.answers.addABAPServiceBinding&&(e={abapServiceName:this.answers.abapServiceProvider?.label,abapService:this.answers.abapServiceProvider?.service});let t={routerType:this.answers.routerType,addConnectivityService:this.answers.addConnectivityService??!1,abapServiceProvider:e,mtaId:this.answers.mtaId,mtaPath:this.destinationRoot(),mtaDescription:this.answers.mtaDescription,mtaVersion:yt};await(0,_t.generateBaseConfig)(t,this.fs,g.DeploymentGenerator.logger)}install(){this._install()}_install(){if(!this.abort&&!this.options.skipInstall){let e=(0,Ct.platform)()==="win32"?"npm.cmd":"npm";this.spawnCommand(e,["install","--no-audit","--no-fund","--silent","--prefer-offline","--no-progress"],{cwd:this.destinationRoot()})}}};var Pt=G&&C?C:G,bt=H&&_?_:H,Lt={"generators/app":Pt,"generators/app-router":bt};0&&(module.exports={API_BUSINESS_HUB_ENTERPRISE_PREFIX,ApiHubType,DESTINATION_AUTHTYPE_NOTFOUND,__entries,__entry_generators_app,__entry_generators_app_router,getCFQuestions,loadManifest});