UNPKG

@sap/generator-fiori

Version:

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

1 lines 12.6 kB
"use strict";exports.id=8236,exports.ids=[8236],exports.modules={22341(e,i,o){o.r(i),o.d(i,{default:()=>u,promptNames:()=>r.rp});var a=o(59636),n=o(76760),s=o(7083),p=o(58808);var r=o(90657),g=o(73667);function getDeployTargetQuestion(e,i){return[{type:"list",name:r.rp.targetName,guiOptions:{breadcrumb:(0,r.t)("prompts.deployTarget.breadcrumb")},message:(0,r.t)("prompts.deployTarget.message"),default:()=>e[0].name,validate:e=>(0,r.lh)(e,i),choices:e.map(e=>({name:e.description,value:e.name}))}]}var h=o(67566),c=o(70987),l=o(29448);async function getSubGenPrompts(e,i,{launchDeployConfigAsSubGenerator:o,launchStandaloneFromYui:a,promptOptions:g,supportedTargets:u,backendConfig:d,cfDestination:f,isCap:m,apiHubConfig:b,isLibrary:C},y){p.z4.logger?.debug((0,r.t)("debug.loadingPrompts"));const A=e.exists((0,n.join)(i.appRootPath,i.config||s.o3.UI5DeployYaml)),P=(0,p.dO)(A,o,a,i.overwrite),S=!C&&a&&!await(0,c.indexHtmlExists)(e,i.appRootPath);let T=[],v={};y&&y!==p.VR.ABAP||({prompts:T,answers:v}=await(0,c.getAbapQuestions)({appRootPath:i.appRootPath,connectedSystem:i.connectedSystem,backendConfig:d,configFile:i.config,indexGenerationAllowed:S,showOverwriteQuestion:P,promptOptions:i?.subGenPromptOptions,logger:p.z4.logger}));let w=[];y&&y!==p.VR.CF||(w=await(0,l.getCFQuestions)({projectRoot:i.projectRoot,isAbapDirectServiceBinding:i.isAbapDirectServiceBinding,cfDestination:f,isCap:m,addOverwrite:P,apiHubConfig:b,promptOptions:i?.subGenPromptOptions}));let D=[];return D=y?y===p.VR.ABAP?T:w:function combineAllPrompts(e,{supportedTargets:i,abapPrompts:o,cfPrompts:a,promptOptions:n}){const s=getDeployTargetQuestion(i,e);return s.push(...(0,h.withCondition)(o,e=>e.targetName===p.VR.ABAP)),s.push(...(0,h.withCondition)(a,e=>e.targetName===p.VR.CF)),n?(0,h.extendWithOptions)(s,n):s}(i.projectRoot,{supportedTargets:u,abapPrompts:T,cfPrompts:w,promptOptions:g}),{questions:D,abapAnswers:v}}const u=class extends p.z4{appWizard;prompts;genNamespace;launchStandaloneFromYui;apiHubConfig;launchDeployConfigAsSubGenerator;promptOptions;vscode;cfDestination;mtaPath;backendConfig;isLibrary=!1;isCap=!1;target;answers;setPromptsCallback;constructor(e,i){super(e,i),this.appWizard=i.appWizard??g.AppWizard.create(i),this.genNamespace=i.namespace,this.launchDeployConfigAsSubGenerator=i.launchDeployConfigAsSubGenerator??!1,this.promptOptions=i?.subGenPromptOptions,this.target=function parseTarget(e,i){let o;return"string"==typeof e?o=e:Array.isArray(e)&&(o=e?.[0]),o||(o=i.target),o}(e,i),this.vscode=i.vscode,this.rootGeneratorName()&&this.env.lookup({packagePatterns:[this.rootGeneratorName()]}),this.options.data?.destinationRoot?(this.launchStandaloneFromYui=!0,this.launchDeployConfigAsSubGenerator||=this.options.data.launchDeployConfigAsSubGenerator,this.options.appRootPath=(0,n.join)((0,n.dirname)(this.options.data.destinationRoot),(0,n.basename)(this.options.data.destinationRoot)),this.options.projectRoot=this.options.data.destinationRoot,a.config({path:(0,n.join)(this.options.data.destinationRoot,".env"),quiet:!0})):(this.options.projectPath&&this.options.projectName?this.options.appRootPath=(0,n.join)(this.options.projectPath,this.options.projectName):this.options.appRootPath=this.destinationRoot(),a.config({quiet:!0}),this.apiHubConfig=this.options.apiHubConfig??(0,r.HM)(),this.launchStandaloneFromYui=!1),this.launchStandaloneFromYui&&(this.appWizard.setHeaderTitle(r.Gk),this.prompts=new g.Prompts(function getYUIDetails(e){return[{name:"Deployment Configuration",description:`Configure Deployment settings - ${(0,n.basename)(e)}`}]}(this.options.projectRoot)),this.setPromptsCallback=e=>{this.prompts&&this.prompts.setCallback(e)})}async initializing(){await super.initializing();const e=await(0,p.GJ)(this.env.create.bind(this.env),"@sap-ux/deploy-config-sub-generator",this.vscode);this.promptOptions={...e,...this.promptOptions};const i=await(0,s.JR)(this.options.appRootPath);this.isCap=!!i,this.mtaPath=(await(0,s.ez)(this.options.appRootPath))?.mtaPath,this.isCap&&!this.mtaPath&&(this.target=p.VR.CF);"Fiori Adaptation"===await(0,s.Ov)(this.options.appRootPath)&&(this.target=p.VR.ABAP,this.launchDeployConfigAsSubGenerator=!1),this.options.projectRoot=i??(this.mtaPath&&(0,n.dirname)(this.mtaPath))??this.options.appRootPath,({backendConfig:this.backendConfig,isLibrary:this.isLibrary}=await(0,r.dl)(this.fs,this.options,this.launchStandaloneFromYui,this.options.appRootPath));const{destinationName:o,servicePath:a}=await(0,r.sk)(this.fs,{appPath:this.options.appRootPath,servicePath:this.options.appGenServicePath});this.options.appGenServicePath||=a,this.cfDestination=o??this.options.appGenDestination??this.backendConfig?.destination}async prompting(){const e=await(0,r.Nj)(this.fs,this.options.appRootPath,this.isCap,!!this.mtaPath,this.apiHubConfig);if(this.target){e.find(e=>e.name===this.target)||(0,p.VI)(p.zc.unrecognizedTarget(this.target))}if(!this.target||this.launchDeployConfigAsSubGenerator){const{target:i,answers:o}=await async function promptDeployConfigQuestions(e,i,o,{launchDeployConfigAsSubGenerator:a,launchStandaloneFromYui:n,promptOptions:s,supportedTargets:p,backendConfig:r,cfDestination:g,isCap:h,apiHubConfig:c,isLibrary:l},u){let d={};if(a){const{questions:f,abapAnswers:m}=await getSubGenPrompts(e,i,{launchDeployConfigAsSubGenerator:a,launchStandaloneFromYui:n,promptOptions:s,supportedTargets:p,backendConfig:r,cfDestination:g,isCap:h,apiHubConfig:c,isLibrary:l},u),b=await o(f);Object.assign(d,b,m),d.overwrite=b.overwriteAbapConfig??b.overwriteCfConfig}else d=await o(getDeployTargetQuestion([...p],i.projectRoot));const f=p.find(e=>e.name===d?.targetName||e.name===u)?.name;return{target:f,answers:d}}(this.fs,this.options,this.prompt.bind(this),{launchDeployConfigAsSubGenerator:this.launchDeployConfigAsSubGenerator,launchStandaloneFromYui:this.launchStandaloneFromYui,promptOptions:this.promptOptions,supportedTargets:e,backendConfig:this.backendConfig,cfDestination:this.cfDestination,isCap:this.isCap,apiHubConfig:this.apiHubConfig,isLibrary:this.isLibrary},this.target);this.target=i,this.answers=o}this.target?await this._composeWithSubGenerator(this.target,this.answers):(p.z4.logger?.debug((0,r.t)("debug.exit")),process.exit(0))}async _composeWithSubGenerator(e,i){try{const o=e,a=this.launchDeployConfigAsSubGenerator?{...this.options,launchStandaloneFromYui:this.launchStandaloneFromYui,launchDeployConfigAsSubGenerator:!0,...i}:{...this.options,launchDeployConfigAsSubGenerator:!1};this.apiHubConfig&&(a.apiHubConfig=this.apiHubConfig),await this.composeWith((0,r.pA)(this.genNamespace,o),a)}catch(e){p.z4.logger?.error(e.message)}}}},65797(e,i,o){o.r(i),o.d(i,{default:()=>g});var a=o(76760),n=o(73024),s=o(58808),p=o(90657),r=o(94443);const g=class extends s.z4{genNamespace;absAppConfigPath;appConfig;deployTarget;constructor(e,i){super(e,i),this.genNamespace=i.namespace;try{if(this.argument("appConfig",{type:String,description:(0,p.t)("headless.info.generatorArgAppConfig"),required:!1}),0===Object.keys(this.options.appConfig??{}).length)throw Error((0,p.t)("headless.error.headlessGenOptions"));"object"==typeof this.options.appConfig?this.appConfig=this.options.appConfig:this.fs.exists(this.options.appConfig)?(this.appConfig=JSON.parse(this.fs.read(this.options.appConfig)),this.absAppConfigPath=(0,a.resolve)(this.options.appConfig)):this.appConfig=JSON.parse(this.options.appConfig),this.deployTarget=this.appConfig.deployConfig?.deployTarget}catch(e){s.z4.logger?.error((0,p.t)("headless.error.generationExiting")),this.env.error(e)}}async initializing(){s.z4.logger?.info((0,p.t)("headless.info.generatorNameVersion",{generatorName:this.rootGeneratorName(),generatorVersion:this.rootGeneratorVersion()}));const e={AppGenLaunchSource:this.options.appConfig.telemetryData?.generationSourceName??"Headless",AppGenLaunchSourceVersion:this.options.appConfig.telemetryData?.generationSourceVersion??"Not Provided"},i=this.transformExtConfig();if(i&&this.deployTarget){const o=this.deployTarget===r.DeployTarget.CF?p.hT.name:p.WG.name;await this.composeWith((0,p.pA)(this.genNamespace,o),{arguments:this.args,...Object.assign(this.options,i,{telemetryData:e})})}}transformExtConfig(){let e;if(this.deployTarget===r.DeployTarget.CF){const i=this.appConfig.deployConfig;this.appConfig.project.targetFolder&&(e={projectRoot:this.appConfig.project.targetFolder,destinationName:i.destinationName,destinationAuthType:i.destinationAuthType,addManagedAppRouter:i.addToManagedAppRouter,launchDeployConfigAsSubGenerator:!0,appRootPath:(0,a.join)(this.appConfig.project.targetFolder,this.appConfig.project.name),addMTADestination:i.addMTADestination,lcapModeOnly:i.lcapModeOnly,cloudServiceName:i.cloudServiceName})}else if(this.deployTarget===r.DeployTarget.ABAP){const i=this.appConfig.deployConfig;this.appConfig.project.targetFolder&&(e={appRootPath:(0,a.join)(this.appConfig.project.targetFolder,this.appConfig.project.name),destination:i?.destination,url:i?.url??"",client:i?.client,scp:i?.scp,ui5AbapRepo:i?.ui5AbapRepo,description:i?.description,package:i?.package,transport:i?.transport,launchDeployConfigAsSubGenerator:!0})}return e}end(){this.options.deleteFile&&this.fs.exists(this.absAppConfigPath)&&(s.z4.logger?.info((0,p.t)("headless.info.deletingApplicationConfigFile",{filepath:this.absAppConfigPath})),(0,n.unlinkSync)(this.absAppConfigPath))}}},90657(e,i,o){o.d(i,{WG:()=>h,hT:()=>c,pA:()=>generatorNamespace,Gk:()=>g,sk:()=>getApiHubOptions,dl:()=>getBackendConfig,HM:()=>getEnvApiHubConfig,Nj:()=>getSupportedTargets,lh:()=>isMTAInstalled,rp:()=>l,t:()=>t});var a=o(76760),n=o(70987),s=o(2307),p=o(7083);async function getBackendConfig(e,i,o,r){let g,h=!1;if(o){const o=await s.io.newInstance(e.read((0,a.join)(r,i.base??p.o3.Ui5Yaml)));g=o.getBackendConfigsFromFioriToolsProxyMiddleware()[0],h=o.getType()===n.DeployProjectType.Library}else g={destination:i.appGenDestination||i.connectedSystem?.destination?.Name,url:i.appGenServiceHost,client:i.appGenClient,scp:!!i.connectedSystem?.backendSystem?.serviceKeys||!1};return{backendConfig:g,isLibrary:h}}var r=o(58808);const generatorNamespace=(e,i)=>`${e}_${i}`,g="Deployment Configuration Generator",h={name:r.VR.ABAP,description:"ABAP"},c={name:r.VR.CF,description:"Cloud Foundry"};var l;!function(e){e.targetName="targetName"}(l||(l={}));var u=o(68801);const d=JSON.parse('{"prompts":{"deployTarget":{"breadcrumb":"Target Type","message":"Please choose the target."}},"debug":{"exit":"Exiting the deployment generator","loadingPrompts":"Loading deploy prompts..."},"headless":{"info":{"generatorArgAppConfig":"Path to the application config file or application config as a string.","generatorNameVersion":"Generating application with: {{- generatorName}} {{generatorVersion}}","deletingApplicationConfigFile":"Deleting application config file: {{- filepath}}."},"error":{"headlessGenOptions":"Please provide one of the following: 1) The first argument of the file path to the application config file, 2) The first argument of the application config file as a JSON string, or 3) The option `appconfig` as a JSON object.","generationExiting":"Application generation exiting due to error: {{- error}}"}}}');var f=o(67566);const m="deploy-config-sub-generator",b=u.createInstance();function t(e,i){return i?.ns||(i=Object.assign(i??{},{ns:m})),b.t(e,i)}(async function initI18n(){await b.init({lng:"en",fallbackLng:"en",showSupportNotice:!1}),b.addResourceBundle("en",m,d),(0,f.addi18nResourceBundle)()})().catch(()=>{});var C=o(44425),y=o(29448),A=o(73024);function isMTAInstalled(e,i){if("cf"===e&&!C.sync(r.rs)||"abap"===e&&!C.sync(r.rs)&&(0,A.existsSync)((0,a.join)(i,"mta.yaml"))){const e=r.zc.getErrorMsgFromType(r.Sd.NO_MTA_BIN);return r.z4.logger?.warn(e),e}return!0}function getEnvApiHubConfig(){const e=process.env.API_HUB_API_KEY,i=process.env.API_HUB_TYPE;return e?{apiHubKey:e,apiHubType:i===y.ApiHubType.apiHubEnterprise?y.ApiHubType.apiHubEnterprise:y.ApiHubType.apiHub}:void 0}async function getApiHubOptions(e,{appPath:i,servicePath:o},a){let n;if(a?.apiHubType===y.ApiHubType.apiHubEnterprise){if(!o){const a=await(0,y.loadManifest)(e,i);o=a?.["sap.app"].dataSources?.mainService?.uri}n=(0,r.rv)(y.API_BUSINESS_HUB_ENTERPRISE_PREFIX,o)}return{destinationName:n,servicePath:o}}async function getSupportedTargets(e,i,o=!1,r=!1,g,l=p.o3.Ui5Yaml){const u=g?.apiHubType===y.ApiHubType.apiHubEnterprise,d=e.exists((0,a.join)(i,".extconfig.json"));let f=!1;try{f=(await s.io.newInstance(e.read((0,a.join)(i,l)))).getType()===n.DeployProjectType.Library}catch{}return u||o?[c]:f||d?[h]:r?[c,h]:[h,c]}}};