UNPKG

@sap/generator-fiori

Version:

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

6 lines (5 loc) 14.5 kB
const __esmImportMetaUrl = require('node:url').pathToFileURL(__filename).href; var ht=Object.create;var P=Object.defineProperty;var mt=Object.getOwnPropertyDescriptor;var ft=Object.getOwnPropertyNames;var ut=Object.getPrototypeOf,gt=Object.prototype.hasOwnProperty;var o=(t,e)=>P(t,"name",{value:e,configurable:!0});var W=(t,e)=>{for(var i in e)P(t,i,{get:e[i],enumerable:!0})},$=(t,e,i,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of ft(e))!gt.call(t,n)&&n!==i&&P(t,n,{get:()=>e[n],enumerable:!(s=mt(e,n))||s.enumerable});return t};var wt=(t,e,i)=>(i=t!=null?ht(ut(t)):{},$(e||!t||!t.__esModule?P(i,"default",{value:t,enumerable:!0}):i,t)),yt=t=>$(P({},"__esModule",{value:!0}),t);var Pt={};W(Pt,{DeployProjectType:()=>l,__entries:()=>xt,__entry_generators_app:()=>lt,getAbapQuestions:()=>_,indexHtmlExists:()=>y});module.exports=yt(Pt);var N={};W(N,{DeployProjectType:()=>l,default:()=>x,getAbapQuestions:()=>_,indexHtmlExists:()=>y});var R=require("../commonlibs/yeoman-ui-types/index.js"),a=require("../open-ux-shared/deploy-config-generator-shared/index.js"),p=require("../fiori-generator-shared/dist/index.js"),h=require("../open-ux-shared/abap-deploy-config-inquirer/index.js"),nt=require("../abap-deploy-config-writer/dist/index.js"),ot=require("../open-ux-shared/ui5-config/index.js"),b=require("../open-ux-shared/project-access/index.js"),at=require("../open-ux-shared/store/index.js");var T=require("../open-ux-shared/project-access/index.js"),G=require("node:path");var Q=wt(require("../commonlibs/i18next/index.js"),1);var K={error:{telemetry:"Failed to send telemetry data after deployment configuration has been added: {{- error}}"},info:{filesGenerated:"The files have been generated.",skippedInstallation:"Option: `--skipInstall` was specified. Installation of dependencies will be skipped."},debug:{configExists:"Existing deployment configuration file found at {{- configPath}}.",configNotFound:"No existing deployment configuration file found. Create a deployment configuration file.",indexExists:"The `webapp/index.html` file already exists and will not be overwritten.",initFailed:"Initializing failed. Unable to process the project configuration: {{- error}}",initTelemetry:"Initializing telemetry in ABAP deployment configuration generator...",appRootPath:"Application loaded from: {{- appRootPath}}.",lrepNamespaceNotFound:"Failed to get the `lrep` namespace: {{- error}}"}};var J="abap-deploy-config-sub-generator",j=Q.default.createInstance();async function k(){await j.init({lng:"en",fallbackLng:"en",showSupportNotice:!1}),j.addResourceBundle("en",J,K)}o(k,"initI18n");function c(t,e){return e?.ns||(e=Object.assign(e??{},{ns:J})),j.t(t,e)}o(c,"t");k().catch(()=>{});var X=require("../open-ux-shared/deploy-config-generator-shared/index.js");async function y(t,e){let i=await(0,T.getWebappPath)(e),s=(0,G.join)(i,"index.html");return t.exists(s)}o(y,"indexHtmlExists");async function q(t,e,i){if(!e)try{let s=(0,G.join)(await(0,T.getWebappPath)(t,i),T.FileName.ManifestAppDescrVar);if(i.exists(s))return i.readJSON(s).namespace}catch(s){X.DeploymentGenerator.logger?.debug(c("debug.lrepNamespaceNotFound",{error:s.message}))}}o(q,"getVariantNamespace");var A=require("../open-ux-shared/deploy-config-generator-shared/index.js");function O(t,e){let i=A.ErrorHandler.fileDoesNotExist(e);throw(0,A.handleErrorMessage)(t,{errorMsg:i}),A.ERROR_TYPE.ABORT_SIGNAL}o(O,"handleProjectDoesNotExist");var d=require("../open-ux-shared/btp-utils/index.js"),E=require("../open-ux-shared/deploy-config-generator-shared/index.js"),C=require("../open-ux-shared/store/index.js");var Y={},B=[];function Z(t,e){return t.url.trim().replace(/\/$/,"")===e.url?.trim().replace(/\/$/,"")&&(t.client??"")===(e?.client??"")}o(Z,"isSameSystem");async function H(){if(Object.keys(Y)?.length===0)try{Y=await(0,d.listDestinations)({stripS4HCApiHosts:!0})}catch(t){E.DeploymentGenerator.logger.error(`Failed to fetch destinations. Error: ${t.message}`)}return Y}o(H,"getDestinations");async function tt(){if(B?.length===0)try{B=await(await(0,C.getService)({logger:E.DeploymentGenerator.logger,entityName:"system"}))?.getAll()}catch(t){E.DeploymentGenerator.logger.error(`Failed to fetch systems list. Error: ${t.message}`)}return B}o(tt,"getBackendSystems");async function U(t){let e;return(0,d.isAppStudio)()&&t&&(e=(await H())?.[t]?.Host),e}o(U,"determineUrlFromDestination");async function L(t){let e=!1;if((0,d.isAppStudio)()&&t.destination){let i=await H();i?.[t.destination]&&(e=(0,d.isAbapEnvironmentOnBtp)(i?.[t.destination]))}else t.url&&(e=!!(await tt())?.find(n=>Z(n,t))?.serviceKeys);return e}o(L,"determineScpFromTarget");async function M(t){let e=!1;if((0,d.isAppStudio)()&&t.destination){let i=await H();i?.[t.destination]&&(e=(0,d.isS4HC)(i?.[t.destination]))}else t.url&&(e=(await tt())?.find(n=>Z(n,t))?.authenticationType===C.AuthenticationType.ReentranceTicket);return e}o(M,"determineS4HCFromTarget");var it=require("../open-ux-shared/abap-deploy-config-inquirer/index.js"),F=require("../open-ux-shared/project-access/index.js"),D=require("../fiori-generator-shared/dist/index.js"),st=require("../open-ux-shared/btp-utils/index.js");var et="deploy-to-abap";var l;(function(t){t.Application="application",t.Library="library"})(l||(l={}));function bt(t,e,i,s){let n,m,f,r,u,g;if((0,st.isAppStudio)()&&t)r=t.Name;else if(e){try{let w=new URL(e.url);n=w.origin,g=w.pathname==="/"?void 0:w.pathname}catch{n=e.url}f=e.client,m=!!e.serviceKeys,u=e.authenticationType}else i?.target?(n=i.target.url,f=i.target.client,m=i.target.scp,u=i.target.authenticationType,r=i.target.destination):s&&(n=s.url,g=s.connectPath,m=s.scp,f=s.client,u=s.authenticationType,r=s?.destination);return{url:n,scp:m,client:f||"",destination:r,authenticationType:u,connectPath:g}}o(bt,"getAbapTarget");async function _({appRootPath:t,connectedSystem:e,backendConfig:i,configFile:s=F.FileName.UI5DeployYaml,indexGenerationAllowed:n=!1,showOverwriteQuestion:m=!1,projectType:f=l.Application,promptOptions:r={},logger:u}){let{backendSystem:g,serviceProvider:w,destination:dt}=e||{},v;try{v=(await(0,F.readUi5Yaml)(t,s)).findCustomTask(et)?.configuration}catch{}let V=bt(dt,g,v,i),S=v?.app;return u?.debug(`Retrieve ABAP prompts using: App path: ${t}, ABAPTarget: ${JSON.stringify(V)}, SystemName: ${g?.name}, ServiceProvider: ${!!w}, showOverwriteQuestion ${m}, indexGenerationAllowed ${n}`),(0,it.getPrompts)({backendTarget:{abapTarget:V,systemName:g?.name,serviceProvider:w,type:f},adpProjectType:r.adpProjectType,ui5AbapRepo:{default:S?.name,...r?.ui5AbapRepo},description:{default:S?.description},packageManual:{default:S?.package??r?.packageManual?.default,...r?.packageManual},transportManual:{default:S?.transport},index:{indexGenerationAllowed:n},packageAutocomplete:{useAutocomplete:!0,...r?.packageAutocomplete},overwriteAbapConfig:{hide:!m},transportInputChoice:{hideIfOnPremise:r?.transportInputChoice?.hideIfOnPremise??!1}},u,(0,D.getHostEnvironment)()!==D.hostEnvironment.cli)}o(_,"getAbapQuestions");var I;(function(t){t.DEPLOY_CONFIG="DEPLOY_CONFIG"})(I||(I={}));var rt=require("../open-ux-shared/feature-toggle/index.js"),pt=require("../open-ux-shared/btp-utils/index.js");var ct=require("../open-ux-shared/adp-tooling/index.js"),z=require("../open-ux-shared/axios-extension/index.js");var x=class extends a.DeploymentGenerator{static{o(this,"default")}appWizard;vscode;launchDeployConfigAsSubGenerator;launchStandaloneFromYui;abort=!1;backendConfig;indexGenerationAllowed;configExists;answers;projectType;adpProjectType;isAdp;constructor(t,e){super(t,e),this.launchDeployConfigAsSubGenerator=e.launchDeployConfigAsSubGenerator??!1,this.launchStandaloneFromYui=e.launchStandaloneFromYui,this.adpProjectType=e.adpProjectType,this.appWizard=e.appWizard||R.AppWizard.create(e),this.vscode=e.vscode,this.options=e}async initializing(){await super.initializing(),await k(),a.DeploymentGenerator.logger?.debug(c("debug.initTelemetry")),await p.TelemetryHelper.initTelemetrySettings({consumerModule:{name:"@sap-ux/abap-deploy-config-sub-generator",version:this.rootGeneratorVersion()},internalFeature:(0,rt.isInternalFeaturesSettingEnabled)(),watchTelemetrySettingStore:!1}),(0,p.setYeomanEnvConflicterForce)(this.env,this.options.force),this.launchDeployConfigAsSubGenerator||(await this._initializing(),this.adpProjectType=await(0,ct.getExistingAdpProjectType)(this.destinationRoot()))}_initDestinationRoot(){this.options.appRootPath&&(this.destinationRoot(this.options.appRootPath),a.DeploymentGenerator.logger?.debug(c("debug.appRootPath",{appRootPath:this.options.appRootPath})))}_processProjectConfig(){this.options.base=this.options.base||b.FileName.Ui5Yaml,this.options.config=this.options.config||b.FileName.UI5DeployYaml,this.fs.exists(this.destinationPath(this.options.base))||(this.abort=!0,O(this.appWizard,this.destinationPath(this.options.base))),this.configExists=this.fs.exists(this.destinationPath(this.options.config)),this.configExists&&a.DeploymentGenerator.logger?.debug(c("debug.configExists",{configPath:this.destinationPath(this.options.config)}))}async _processIndexHtmlConfig(){this.projectType===l.Library?this.indexGenerationAllowed=!1:await y(this.fs,this.destinationPath())?(this.indexGenerationAllowed=!1,this.options.index&&a.DeploymentGenerator.logger?.debug(c("debug.indexExists")),delete this.options.index):this.indexGenerationAllowed=!0}async _initBackendConfig(){let t=await ot.UI5Config.newInstance(this.fs.read(this.destinationPath(this.options.base??b.FileName.Ui5Yaml)));this.projectType=t.getType()==="library"?l.Library:l.Application,this.backendConfig=t.getBackendConfigsFromFioriToolsProxyMiddleware()[0]}async _initializing(){this._initDestinationRoot();try{this._processProjectConfig(),await this._initBackendConfig(),await this._processIndexHtmlConfig()}catch(t){if(t===a.ERROR_TYPE.ABORT_SIGNAL)a.DeploymentGenerator.logger?.debug(c("debug.initFailed",{error:a.ErrorHandler.getErrorMsgFromType(a.ERROR_TYPE.ABORT_SIGNAL)}));else throw t}}async prompting(){if(this.answers={},!this.abort){if(!this.launchDeployConfigAsSubGenerator){let t=await(0,b.getAppType)(this.destinationPath());this.isAdp=t==="Fiori Adaptation";let e={shouldValidatePackageForStartingPrefix:this.isAdp,shouldValidatePackageType:this.isAdp,shouldValidateFormatAndSpecialCharacters:this.isAdp},i=this.adpProjectType===z.AdaptationProjectType.ON_PREMISE,s={ui5AbapRepo:{hideIfOnPremise:i},transportInputChoice:{hideIfOnPremise:i},packageAutocomplete:{additionalValidation:e},packageManual:{additionalValidation:e},adpProjectType:this.adpProjectType},n=this.indexGenerationAllowed&&!this.isAdp,{prompts:m,answers:f={}}=await _({appRootPath:this.destinationRoot(),connectedSystem:this.options.connectedSystem,backendConfig:this.backendConfig,configFile:this.options.config,indexGenerationAllowed:n,showOverwriteQuestion:(0,a.showOverwriteQuestion)(this.launchDeployConfigAsSubGenerator,this.launchStandaloneFromYui,this.options.overwrite,this.configExists),projectType:this.projectType,logger:a.DeploymentGenerator.logger,promptOptions:s}),r=await this.prompt(m);this.answers=(0,h.reconcileAnswers)(r,f)}await this._reconcileAnswersWithOptions()}}async _processAbapTargetAnswers(){this.answers.destination=this.options.destination||this.answers.destination,this.answers.url=this.options.url||this.answers.url||await U(this.answers.destination),this.answers.connectPath=this.options.connectPath||this.answers.connectPath,this.answers.client=this.options.client||this.answers.client,this.answers.scp=this.options.scp||this.answers.scp||await L({url:this.answers.url,client:this.answers.client,destination:this.answers.destination}),this.answers.isAbapCloud=this.options.isAbapCloud||this.answers.isAbapCloud||await M({url:this.answers.url,client:this.answers.client,destination:this.answers.destination}),!(0,pt.isAppStudio)()&&this.answers.scp&&delete this.answers.client}_processBspAppAnswers(){this.answers.ui5AbapRepo=(this.options.ui5AbapRepo||this.answers.ui5AbapRepo)?.toUpperCase(),this.answers.description=this.options.description||this.answers.description,this.answers.package||(this.answers.package=(0,h.getPackageAnswer)(this.options,this.options.package)||(0,h.getPackageAnswer)(this.answers)||(this.answers.scp?"":h.DEFAULT_PACKAGE_ABAP)),this.answers.transport||(this.answers.transport=this.options.transport??((0,h.getTransportAnswer)(this.options)||(0,h.getTransportAnswer)(this.answers)))}async _reconcileAnswersWithOptions(){await this._processAbapTargetAnswers(),this._processBspAppAnswers(),this.answers.index=this.options.index??this.answers.index,this.answers.overwrite=this.options.overwrite??this.answers.overwrite}async writing(){this.launchDeployConfigAsSubGenerator?(await this._initializing(),await this._writing()):await this._writing()}async _writing(){if(this.abort||this.answers.overwrite===!1)return;let t=this.adpProjectType===z.AdaptationProjectType.CLOUD_READY,e=await q(this.destinationPath(),t,this.fs);await(0,nt.generate)(this.destinationPath(),{target:{url:this.answers.url,connectPath:this.answers.connectPath,client:this.answers.client,scp:this.answers.scp,destination:this.answers.destination,authenticationType:this.answers.isAbapCloud?at.AuthenticationType.ReentranceTicket:void 0},app:{name:this.answers.ui5AbapRepo,description:this.answers.description,package:this.answers.package,transport:this.answers.transport},index:this.answers.index,lrep:e},{baseFile:this.options.base,deployFile:this.options.config,addBuildToUndeployScript:!this.isAdp},this.fs)}install(){this.answers.overwrite!==!1&&this._install()}_install(){this.options.skipInstall?a.DeploymentGenerator.logger?.info(c("info.skippedInstallation")):this.spawnCommand("npm",["install","--no-audit","--no-fund","--silent","--prefer-offline","--no-progress"])}async end(){this.abort||this.answers.overwrite===!1||(this.launchStandaloneFromYui&&(0,p.isExtensionInstalled)(this.vscode,p.YUI_EXTENSION_ID,p.YUI_MIN_VER_FILES_GENERATED_MSG)&&this.appWizard?.showInformation(c("info.filesGenerated"),R.MessageType.notification),(0,p.sendTelemetry)(I.DEPLOY_CONFIG,p.TelemetryHelper.createTelemetryData({DeployTarget:"ABAP",...this.options.telemetryData})??{},this.destinationRoot())?.catch(t=>{a.DeploymentGenerator.logger.error(c("error.telemetry",{error:t}))}))}};var lt=N&&x?x:N,xt={"generators/app":lt};0&&(module.exports={DeployProjectType,__entries,__entry_generators_app,getAbapQuestions,indexHtmlExists});