@sap/generator-fiori
Version:
Create an SAPUI5 application using SAP Fiori elements or a freestyle approach
7 lines (6 loc) • 43.6 kB
JavaScript
const __esmImportMetaUrl = require('node:url').pathToFileURL(__filename).href;
var Zt=Object.create;var Y=Object.defineProperty;var en=Object.getOwnPropertyDescriptor;var tn=Object.getOwnPropertyNames;var nn=Object.getPrototypeOf,rn=Object.prototype.hasOwnProperty;var s=(e,t)=>Y(e,"name",{value:t,configurable:!0});var on=(e,t)=>{for(var n in t)Y(e,n,{get:t[n],enumerable:!0})},Re=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of tn(t))!rn.call(e,r)&&r!==n&&Y(e,r,{get:()=>t[r],enumerable:!(i=en(t,r))||i.enumerable});return e};var k=(e,t,n)=>(n=e!=null?Zt(nn(e)):{},Re(t||!e||!e.__esModule?Y(n,"default",{value:e,enumerable:!0}):n,e)),an=e=>Re(Y({},"__esModule",{value:!0}),e);var Kn={};on(Kn,{DEFAULT_FLP_PATH:()=>Le,convertEslintConfig:()=>Fe,convertToVirtualPreview:()=>Vt,default:()=>Xn,enableCardGeneratorConfig:()=>Kt,generateEslintConfig:()=>Ce,generateFlpEmbeddedConfig:()=>zt,generateInboundNavigationConfig:()=>St,generateSmartLinksConfig:()=>Ze,generateVariantsConfig:()=>fe,getSmartLinksTargetFromPrompt:()=>xe,includeTestRunnersPrompt:()=>ot,readManifest:()=>j,simulatePrompt:()=>rt});module.exports=an(Kn);var J=k(require("../../commonlibs/chalk/index.js"),1),et=k(require("../../commonlibs/prompts/index.js"),1),q=require("../../open-ux-shared/btp-utils/index.js"),ie=require("../../open-ux-shared/project-access/index.js");var Ye=k(require("../../commonlibs/i18next/index.js"),1);var Oe={questions:{enter:"Enter {{-type}}",useTarget:"Do you want to use {{-target}}",target:"SmartLinks configuration source {{-type}} {{-file}}",client:"SAP client {{-file}}",credentials:"Credentials",credentialsDescription:"Provide username and password"},warnings:{useCredentialsFailed:"Retrieving stored credentials failed."},info:{username:"Username",password:"Password",searchTarget:"Searching for deploy target definition: {{-file}}.",targetFound:"Deploy target definition found: {{-file}}.",credentialsAvailable:"Credentials taken from stored system.",credentialsRequired:"Credentials are required. Please enter your credentials below.",operationAborted:"Operation aborted by the user.",connectTo:"Connecting to",connectSuccess:"Connected"},error:{target:"Please provide a target for the configuration.",noTarget:"No target definition found: {{-file}}.",emptyUsername:"Username cannot be empty. Provide a value for the username.",emptyPassword:"Password cannot be empty. Provide a value for the password."}};var De={error:{sapAppNotDefined:"The `manifest.json` file is missing the `sap.app` required section.",manifestNotFound:"The `manifest.json` file was not found at path: {{- path}}. Check the file exists.",inboundExists:"An inbound definition already exists for key: {{inboundKey}}. Choose another key."}};var ge="app-config-writer:smartLinksConfig",z="app-config-writer:navConfig",Je=Ye.default.createInstance();async function dn(){await Je.init({resources:{en:{[ge]:Oe,[z]:De}},lng:"en",fallbackLng:"en",defaultNS:ge,ns:[ge,z],showSupportNotice:!1})}s(dn,"initI18n");function f(e,t){return Je.t(e,t)}s(f,"t");dn().catch(()=>{});var He=require("../../commonlibs/mem-fs/index.js"),ze=require("../../commonlibs/mem-fs-editor/index.js");var ee=k(require("../../commonlibs/chalk/index.js"),1),Xe=require("../../commonlibs/ejs/index.js"),Ke=require("node:path"),te=require("../../open-ux-shared/axios-extension/index.js"),he=require("../../open-ux-shared/btp-utils/index.js"),we=require("../../open-ux-shared/project-access/index.js"),ne=require("../../open-ux-shared/store/index.js");var Z=require("node:path"),qe=require("node:url");var un=(0,Z.dirname)((0,qe.fileURLToPath)(__esmImportMetaUrl));function Ve(e=""){return(0,Z.join)(un,"../templates",e)}s(Ve,"getTemplatePath");var Ge=require("node:path"),C=require("../../open-ux-shared/project-access/index.js");var A;(function(e){e.DeployToAbap="deploy-to-abap",e.FioriToolsProxy="fiori-tools-proxy",e.FioriToolsServestatic="fiori-tools-servestatic"})(A||(A={}));var g;(function(e){e.destination="destination",e.url="url"})(g||(g={}));var h;(function(e){e.FioriToolsPreview="fiori-tools-preview",e.PreviewMiddleware="preview-middleware",e.ReloadMiddleware="reload-middleware",e.FioriToolsAppreload="fiori-tools-appreload"})(h||(h={}));async function We(e){let n=(await(0,C.readUi5Yaml)(e,C.FileName.UI5DeployYaml)).findCustomTask(A.DeployToAbap);if(!n?.configuration?.target)throw Error(f("error.noTarget",{file:`${C.FileName.UI5DeployYaml}`}));let{target:i,ignoreCertError:r}=n?.configuration||{};return{target:i,ignoreCertErrors:r}}s(We,"readUi5DeployConfigTarget");var fn=s((e,t)=>{let n={path:"/appconfig",src:"appconfig",fallthrough:!1};if(e.find(o=>o.path===n.path&&o.src===n.src))return;let i=[...e,n];return{name:"fiori-tools-servestatic",...t?{beforeMiddleware:"fiori-tools-proxy"}:{afterMiddleware:"compression"},configuration:{paths:i}}},"getFioriToolsServeStaticMiddlewareConfig");async function Be(e,t,n){let i=[C.FileName.Ui5Yaml,C.FileName.Ui5MockYaml,C.FileName.Ui5LocalYaml];for(let r of i){let o;try{o=await(0,C.readUi5Yaml)(e,r)}catch{n?.debug(`File ${r} not existing`);continue}let a=!!o.findCustomMiddleware(A.FioriToolsProxy),c=o.findCustomMiddleware(A.FioriToolsServestatic),u=fn(c?.configuration.paths||[],a);if(u){let p=o.updateCustomMiddleware(u).toString();t.write((0,Ge.join)(e,r),p)}}}s(Be,"addUi5YamlServeStaticMiddleware");var pn={so:"*",action:"*",systemAliasesFormat:"object","sap-language":"EN",shellType:"FLP",depth:0};async function ve(e,t,n){try{let r=await(await(0,ne.getService)({logger:n,entityName:"system"})).read(new ne.BackendSystemKey({url:e,client:t}));return r?.username?{username:r.username,password:r.password||""}:void 0}catch(i){n?.warn(f("warnings.useCredentialsFailed")),n?.debug(i)}}s(ve,"getLocalStoredCredentials");function ln(e){let{target:t,auth:n,ignoreCertErrors:i}=e,r;return(0,he.isAppStudio)()&&t.destination?(r=(0,te.createForDestination)({auth:n},{Name:t.destination}),delete r.defaults.params.saml2):r=(0,te.createForAbap)({baseURL:t.url,auth:n,ignoreCertErrors:i,params:t.client?{"sap-client":t.client}:void 0}),r}s(ln,"createSmartLinksProvider");async function mn(e,t){let n=(0,he.isAppStudio)()&&e.target.destination?e.target.destination:e.target.url;if(!n)throw new Error(f("error.target"));try{let i=ln(e);t?.info(`${ee.default.cyan(f("info.connectTo"))} ${n}`);let r=await i.get("/sap/bc/ui2/start_up",{params:pn});if(t?.info(ee.default.cyan(f("info.connectSuccess"))),r.status!==200||!r.data)throw new Error(`Invalid response from ${e.target.url??e.target.destination}: status: ${r.status}. data: '${r.data}'.`);return JSON.parse(r.data)}catch(i){throw t?.debug(`Request failed. ${i}`),new Error(i.message||"Unknown error occurred")}}s(mn,"sendRequest");async function ye(e,t){t?.info(f("info.searchTarget",{file:we.FileName.UI5DeployYaml}));try{let n=await We(e);return t?.info(ee.default.cyan(f("info.targetFound",{file:we.FileName.UI5DeployYaml}))),n}catch(n){t?.warn(n.message),t?.debug(n);return}}s(ye,"getTargetDefinition");async function gn(e,t){let n=await mn(e,t);if(!n?.targetMappings)throw new Error(f("error.noTarget",{file:`${e.target.destination??e.target.url}`}));return n.targetMappings}s(gn,"getTargetMappings");async function wn(e,t){let n=await gn(e,t),i={};for(let r in n){let o=n[r];i[r]={semanticObject:o.semanticObject,action:o.semanticAction,title:o.text,signature:{additionalParameters:"ignored",parameters:{},...o.signature},resolutionResult:{}}}return i}s(wn,"getTargetMappingsConfig");function hn(e,t,n){let r=n.readJSON(e).services?.ClientSideTargetResolution?.adapter?.config?.inbounds;return r?(Object.entries(t).forEach(([o,a])=>{r[o]=a}),r):t}s(hn,"mergeTargetMappings");async function Qe(e,t,n,i){let r=await wn(t,i),o=Ve("smartlinks-config/fioriSandboxConfig.json"),a=(0,Ke.join)(e,"appconfig","fioriSandboxConfig.json");if(!n.exists(a))n.copyTpl(o,a,{inboundTargets:r});else{r=hn(a,r,n);let c=(0,Xe.render)(n.read(o),{inboundTargets:r},{});n.extendJSON(a,JSON.parse(c))}await Be(e,n,i)}s(Qe,"writeSmartLinksConfig");async function Ze(e,t,n,i){return i||(i=(0,ze.create)((0,He.create)())),await Qe(e,t,i,n),i}s(Ze,"generateSmartLinksConfig");var{prompt:Te}=et.default,tt=s((e,t)=>e?.trim()?!0:f(t),"validator"),vn=s((e,t)=>{(t?.destination||t?.url)&&e.push({name:t?.destination?g.destination:g.url,message:f("questions.useTarget",{target:t.destination||t.url}),type:"confirm",initial:!0,format:s(n=>n&&(t.destination||t.url),"format")}),e.push({name:"select",type:s(n=>n?null:"select","type"),message:f("questions.target",{type:"",file:""}),choices:[{title:f("questions.enter",{type:g.destination}),value:g.destination},{title:f("questions.enter",{type:g.url}),value:g.url}]}),e.push({type:s(n=>n===g.destination?"text":null,"type"),name:g.destination,initial:t?.destination,message:f("questions.target",{type:g.destination,file:t?.destination?`(${ie.FileName.UI5DeployYaml})`:""}),validate:s(n=>tt(n,"error.target"),"validate")})},"addAppStudioQuestions"),yn=s(e=>{let t=[];return(0,q.isAppStudio)()&&vn(t,e),t.push({type:s(n=>!n||n===g.url?"text":null,"type"),name:g.url,initial:e?.url,message:f("questions.target",{type:g.url,file:e?.url?`(${ie.FileName.UI5DeployYaml})`:""}),validate:s(n=>tt(n,"error.target"),"validate")},{name:"client",type:s((n,i)=>i?.url?"text":null,"type"),initial:e?.client,message:f("questions.client",{file:e?.client?`(${ie.FileName.UI5DeployYaml})`:""}),format:s(n=>typeof n=="number"?n.toString():n,"format")}),t},"getTargetPromptQuestions"),Sn=s(async(e,t)=>{let n={onCancel:s(()=>(t?.info(J.default.yellow(f("info.operationAborted"))),process.exit(1)),"onCancel")},i=yn(e?.target),{url:r,client:o,destination:a}=await Te(i,n);return{url:r,client:o,destination:a}},"getTargetPrompt");async function Se(e){let{username:t,password:n}=await Te([{type:"text",name:"username",message:`${J.default.cyan(f("info.username"))}`,validate:s(i=>i?.trim()?!0:`${f("error.emptyUsername")}`,"validate")},{type:"invisible",name:"password",message:`${J.default.cyan(f("info.password"))}`,validate:s(i=>i?.trim()?!0:`${f("error.emptyPassword")}`,"validate")}],{onCancel:s(()=>(e?.info(J.default.yellow(f("info.operationAborted"))),process.exit(1)),"onCancel")});return{username:t,password:n}}s(Se,"promptUserPass");async function Tn(e,t){if((0,q.isAppStudio)()&&e.destination){let i=(await(0,q.listDestinations)())?.[e.destination];if(i?.Authentication==="NoAuthentication")return t?.info(f("info.credentialsRequired")),await Se(t);if(i){t?.info(f("info.credentialsAvailable"));return}}else if(e.url){let n=await ve(e.url,e.client,t);if(n?.username){let i=[{title:`Use ${n.username}`,value:n},{title:f("questions.credentialsDescription"),value:!1}],{credentials:r}=await Te([{name:"credentials",type:"select",message:f("questions.credentials"),choices:i,initial:0}]);if(r)return r}}return Se(t)}s(Tn,"getCredentialsPrompt");async function xe(e,t){let n=await ye(e,t),i=await Sn(n,t),r=await Tn(i,t);return{target:i,auth:r,ignoreCertErrors:n?.ignoreCertErrors}}s(xe,"getSmartLinksTargetFromPrompt");var nt=k(require("../../commonlibs/prompts/index.js"),1);var{prompt:it}=nt.default;async function rt(){return(await it([{type:"confirm",name:"simulate",initial:!0,message:`The converter renames the local HTML files, deletes the JavaScript and TypeScript files used for the existing preview functionality, and configures virtual endpoints instead.
Do you want to simulate the conversion?`}])).simulate??await Promise.reject(new Error("An error has occurred. The conversion has been canceled."))}s(rt,"simulatePrompt");async function ot(){return(await it([{type:"confirm",name:"includeTests",initial:!1,message:"Do you want to convert the test runners?"}])).includeTests??await Promise.reject(new Error("An error has occurred. The conversion has been canceled."))}s(ot,"includeTestRunnersPrompt");var at=require("../../commonlibs/mem-fs/index.js"),st=require("../../commonlibs/mem-fs-editor/index.js"),re=require("../../open-ux-shared/project-access/index.js"),V=require("node:path"),ct=require("../../ui5-application-writer/dist/index.js");async function Ce(e,t){let n=t.fs??(0,st.create)((0,at.create)()),i=t.logger;if(!await xn(e,n,i))throw new Error("The prerequisites are not met. For more information, see the log messages above.");return await Cn(e,n,t?.config),n}s(Ce,"generateEslintConfig");async function xn(e,t,n){let i=(0,V.join)(e,re.FileName.Package),r=t.readJSON(i);if(!r)return n?.error(`No package.json found at path '${i}'`),!1;if((0,re.hasDependency)(r,"eslint"))return n?.error(`EsLint already exists in this project. Found 'eslint' dependency in package.json at path '${i}'`),!1;let o=(0,V.join)(e,"eslint.config.mjs");return t.exists(o)?(n?.error(`An ESLint configuration file already exists at path '${o}'`),!1):!0}s(xn,"checkPrerequisites");async function Cn(e,t,n="recommended"){if(await(0,ct.addEslintFeature)(e,t),n==="recommended-for-s4hana"){let i=(0,V.join)(e,"eslint.config.mjs"),r=t.read(i);r=r.replace("...fioriTools.configs.recommended","...fioriTools.configs['recommended-for-s4hana']"),await t.write((0,V.join)(e,"eslint.config.mjs"),r)}}s(Cn,"addEslintConfig");var lt=require("../../commonlibs/mem-fs-editor/index.js"),mt=require("../../commonlibs/mem-fs/index.js"),w=require("node:path"),$=require("../../open-ux-shared/project-access/index.js");var Ie=require("node:path"),dt=require("../../open-ux-shared/project-access/index.js"),E=require("../../commonlibs/semver/index.js");var G=new Map;function Ee(e,t){let n=(0,Ie.join)(t,"package.json"),i=e.readJSON(n);return G.clear(),Object.entries(i?.scripts??{}).forEach(([r,o])=>{G.set(r,o??"")}),G}s(Ee,"getScriptsFromPackageJson");function P(e){let t=/ (?:--open|-o|--o) (\S*)/.exec(e)?.[1]??void 0;t=t?.replace(/['"]/g,"");let n=/^[^?#]+\.html/.exec(t??"")?.[0]??void 0,i=/(?<=#)\w+-\w+/.exec(t??"")?.[0]??void 0;return{path:n,intent:i?{object:i?.split("-")[0],action:i?.split("-")[1]}:void 0}}s(P,"extractUrlDetails");function Pe(e,t=!1){let n=e.name!="start-variants-management"&&e.name!="start-control-property-editor"&&e.name!="start-cards-generator",i=!!(e.value.includes("ui5 serve")||e.value.includes("fiori run")),{path:r}=P(e.value),o=_(e??"");return n&&i&&!(r==="index.html")&&(t?!0:!o)}s(Pe,"isValidPreviewScript");function ut(e,t,n){let i=(0,Ie.join)(n,"package.json");if(t.readJSON(i)){for(let[o,a]of Ee(t,n))if(Pe({name:o,value:a})&&W(a)===e)return{name:o,value:a}}}s(ut,"getRunScriptForYamlConfig");function W(e){return/ (?:--config|-c) (\S*)/.exec(e)?.[1]??dt.FileName.Ui5Yaml}s(W,"extractYamlConfigFileName");function _(e,t){let{path:n}=P(e.value);return n?n.includes(".qunit.html")?!0:t?.test?.some(i=>i.path===n)??!1:!!Ue(e.name)}s(_,"isTestPath");function ft(e,t){let{path:n}=P(e.value);if(!n)return!1;let i=t.rta?.editors?.some(o=>o.path===n)??t.editors?.rta?.endpoints?.some(o=>o.path===n)??!1,r=t.editors?.cardGenerator?.path===n;return!i&&!r&&!_(e,t)}s(ft,"isFlpPath");function Ue(e){let t="ui5-test-runner",n=s(c=>/ (?:--url|-u|--testsuite) (\S*)/.exec(c)?.[1]??void 0,"extractUrl"),i=s(c=>[...G.values()].find(u=>u.includes(` ${c} `)),"findReferencingScriptByScriptName"),r=s(c=>{for(let u of c.split(" ")){let d=G.get(u);if(d?.includes(t))return d}},"findReferencingUi5TestRunnerScriptByScriptValue"),o=i(e),a=o?.includes(t)?n(o):void 0;return a||(o=r(o??""),a=n(o??"")),a?new URL(a).pathname:void 0}s(Ue,"getTestPathForUi5TestRunner");function B(e,t,n,i=!0){let r=e?.devDependencies?.[t]??e?.dependencies?.[t];return r?r==="latest"?!1:(0,E.validRange)(r)?(0,E.outside)(n,r,">"):((0,E.valid)(r)&&(r=`<=${r}`),!(0,E.satisfies)(n,r)):i}s(B,"isLowerThanMinimalVersion");var gt=k(require("../../commonlibs/cross-spawn/index.js"),1),y=require("node:fs"),wt=require("node:os");var I={ESLINT:"eslint",ESLINT_MIGRATE_CONFIG:"@eslint/migrate-config",ESLINT_PLUGIN_FIORI_TOOLS:"@sap-ux/eslint-plugin-fiori-tools",ESLINT_PLUGIN_FIORI_CUSTOM:"eslint-plugin-fiori-custom"},In=["eslint:recommended"],En="plugin:@typescript-eslint/",pt="Migration to eslint version 9 failed. Check if there are error messages above. You can also delete the existing eslint `devDependency` and run `create add eslint` to create a eslint.config.mjs file with the flat config where you can transfer your old eslint config manually.` For more information, see [https://eslint.org/docs/latest/use/migrate-to-9.0.0#flat-config](Migrate to v9.x).";async function Fe(e,t){let n=t.fs??(0,lt.create)((0,mt.create)()),i=t.logger;if(!await Pn(e,n,i))throw new Error("The prerequisites are not met. For more information, see the log messages above.");let r=await Mn(e,n,i);return await An(e,n,r),await kn(e,n,t.config,i),await $n(e,n,i),n}s(Fe,"convertEslintConfig");async function Pn(e,t,n){let i=(0,w.join)(e,$.FileName.Package),r=t.readJSON(i);return r?(0,$.hasDependency)(r,I.ESLINT)?B(r,I.ESLINT,"9.0.0")?(0,$.hasDependency)(r,"@fxu/fincode")?(n?.error(`Dependency to '@fxu/fincode' found at path '${e}'. Please remove the dependency and any usage of this package before running the conversion.`),!1):!t.exists((0,w.join)(e,".eslintrc.json"))&&!t.exists((0,w.join)(e,".eslintrc"))?(n?.error(`No .eslintrc.json or .eslintrc found at path '${e}'`),!1):!0:(n?.error(`ESLint version is already 9.0.0 or higher in this project. Found ESLint dependency with version '${r.devDependencies?.eslint}' in package.json at path '${i}'`),!1):(n?.error(`Did not find ESLint dependency in package.json at path '${i}'. You might want to use the \`add eslint-config\` command instead.'`),!1):(n?.error(`No package.json found at path '${i}'`),!1)}s(Pn,"checkPrerequisites");function Un(e){let t=typeof e.extends=="string"?[e.extends]:e.extends??[],n=!1,i=!1,r=[];for(let o of t)o.includes(I.ESLINT_PLUGIN_FIORI_TOOLS)||(o.startsWith(En)?i=!0:In.includes(o)?n=!0:r.push(o));return t.length>0&&(r.length===0?delete e.extends:typeof e.extends=="string"?e.extends=r[0]:e.extends=r),{eslintRecommended:n,tsStripped:i}}s(Un,"stripNativeExtendsFromConfig");function Fn(e,t,n,i){if(!t&&!n)return;let r=[];t&&r.push("'eslint:recommended'"),n&&r.push("'plugin:@typescript-eslint/*'");let o=`${r.join(" and ")} ${r.length>1?"were":"was"} removed from the legacy config and will not be re-injected. Its rules are already covered by '@sap-ux/eslint-plugin-fiori-tools', so no manual re-addition is needed.`,a=e?` The legacy config had a 'files' scope (${JSON.stringify(e)}) that cannot be automatically preserved.`:"";i?.warn(o+a)}s(Fn,"warnIfFileScopeDropped");async function Mn(e,t,n){let i=(0,w.join)(e,".eslintrc.json"),r=(0,w.join)(e,".eslintrc"),o=t.exists(i)?i:r,a=t.readJSON(o);if(!a||typeof a!="object")throw new Error(`Existing eslint config at path '${o}' is not a valid JSON object.`);Array.isArray(a.plugins)&&(a.plugins=a.plugins.filter(d=>!d.includes(I.ESLINT_PLUGIN_FIORI_TOOLS)),a.plugins.length===0&&delete a.plugins);let{eslintRecommended:c,tsStripped:u}=Un(a);return Fn(a.files,c,u,n),n?.debug(`Removed SAP Fiori tools plugin references from ${o}`),JSON.stringify(a,null,2)}s(Mn,"removeFioriToolsFromExistingConfig");function Nn(e,t){let n=0;for(let i=t;i>=0;i--)if(e.charAt(i)==="]")n++;else if(e.charAt(i)==="["&&(n--,n===0))return i;return-1}s(Nn,"findMatchingOpenBracket");async function kn(e,t,n="recommended",i){let r=(0,w.join)(e,"eslint.config.mjs"),o=t.read(r),a=`import fioriTools from '${I.ESLINT_PLUGIN_FIORI_TOOLS}';
`;o.includes(a)||(o=a+o);let c=o.lastIndexOf("]);");if(c===-1)throw new Error("Unexpected format of migrated eslint config. Could not inject the SAP Fiori tools plugin configuration.");let u=o.slice(0,c),d=Nn(o,c),p=d===-1?"":o.slice(d+1,c),D=/^\s*$/.test(p)?"":",";o=u+`${D}
...fioriTools.configs['${n}'],
`+o.slice(c),t.write(r,o),i?.debug(`Injected SAP Fiori tools plugin into ${r}`)}s(kn,"injectFioriToolsIntoMigratedConfig");async function An(e,t,n){let i=(0,y.mkdtempSync)((0,w.join)((0,wt.tmpdir)(),"eslint-migration-"));try{let r=(0,w.join)(e,".eslintrc.json"),o=t.exists(r)?".eslintrc.json":".eslintrc";(0,y.writeFileSync)((0,w.join)(i,o),n,"utf-8");let a=(0,w.join)(e,".eslintignore");(0,y.existsSync)(a)&&(0,y.writeFileSync)((0,w.join)(i,".eslintignore"),(0,y.readFileSync)(a,"utf-8"),"utf-8"),await _n(i,o);let c=(0,w.join)(e,"eslint.config.mjs"),u=(0,y.readFileSync)((0,w.join)(i,"eslint.config.mjs"),"utf-8");t.write(c,u)}finally{(0,y.rmSync)(i,{recursive:!0,force:!0})}}s(An,"runMigrationCommand");async function _n(e,t){return new Promise((n,i)=>{let r=(0,gt.default)("npx",["--yes",I.ESLINT_MIGRATE_CONFIG,t],{cwd:e,shell:!1,stdio:"inherit"});r.on("close",o=>{o===0?n():i(new Error(`Migration command failed with exit code ${o??"unknown"}. ${pt}`))}),r.on("error",o=>{i(new Error(`Migration command failed: ${o.message}. ${pt}`))})})}s(_n,"spawnMigrationCommand");async function $n(e,t,n){let i=(0,w.join)(e,$.FileName.Package),r=t.readJSON(i);r.devDependencies??={},r.devDependencies[I.ESLINT]="^10.0.0",r.devDependencies[I.ESLINT_PLUGIN_FIORI_TOOLS]="^10.0.0",delete r.devDependencies[I.ESLINT_PLUGIN_FIORI_CUSTOM],r.scripts??={},r.scripts.lint&&n?.info("The `lint` script in the `package.json` file will be overwritten."),r.scripts.lint="eslint ./",t.writeJSON(i,r)}s($n,"updatePackageJson");var ht=require("../../commonlibs/mem-fs/index.js"),vt=require("../../commonlibs/mem-fs-editor/index.js"),yt=require("../../open-ux-shared/ui5-config/index.js");var F=require("../../open-ux-shared/project-access/index.js");var oe=require("node:path");function X(e){return e?.component!==void 0}s(X,"isFioriToolsDeprecatedPreviewConfig");async function v(e,t,n=F.FileName.Ui5Yaml,i){if(!t&&!e)throw new Error("Either base path or yaml config must be provided.");return e=e??await(0,F.readUi5Yaml)(t,n,i),e.findCustomMiddleware(h.FioriToolsPreview)??e.findCustomMiddleware(h.PreviewMiddleware)}s(v,"getPreviewMiddleware");function ae(e){if(X(e))return;let t=e?.flp?.intent;return t?`#${t.object}-${t.action}`:void 0}s(ae,"getIntentFromPreviewConfig");async function se(e,t,n){return(await v(void 0,e,t,n))?.name===h.PreviewMiddleware?"ui5 serve":"fiori run"}s(se,"getCLIForPreview");async function ce(e,t,n){t.forEach(i=>{e.exists(i)&&(e.delete(i),n?.info(`Deleted the '${(0,oe.basename)(i)}' file. This file is no longer needed for the virtual endpoints.`))})}s(ce,"deleteFiles");async function j(e,t){let n=(0,oe.join)(await(0,F.getWebappPath)(e,t),F.FileName.Manifest),i=t.readJSON(n);if(!i)throw new Error(`The \`manifest.json\` file was not found at path: ${n}. Check the file exists.`);if(!i["sap.app"])throw new Error("The `manifest.json` file is missing the `sap.app` required section.");return{manifest:i,manifestPath:n}}s(j,"readManifest");async function St(e,{semanticObject:t,action:n,title:i,subTitle:r},o=!1,a){a||(a=(0,vt.create)((0,ht.create)()));let{manifest:c,manifestPath:u}=await j(e,a),d=`${t}-${n}`;if(!o&&c["sap.app"].crossNavigation?.inbounds[d])throw Error(f("error.inboundExists",{inboundKey:d,ns:z}));let p={[d]:{semanticObject:t,action:n,title:i,subTitle:r,signature:{parameters:{},additionalParameters:"allowed"}}},m=Object.assign(c["sap.app"].crossNavigation??{},{inbounds:(0,yt.mergeObjects)(c["sap.app"].crossNavigation?.inbounds,p)});return a.extendJSON(u,{"sap.app":Object.assign(c["sap.app"],{crossNavigation:m})}),a}s(St,"generateInboundNavigationConfig");var Mt=require("../../commonlibs/mem-fs-editor/index.js"),Nt=require("../../commonlibs/mem-fs/index.js");var x=require("node:path");var M=require("../../open-ux-shared/project-access/index.js");var Tt={object:"app",action:"preview"},Me="/test/flp.html",K={qunit:{path:"/test/unitTests.qunit.html",framework:"QUnit"},opa5:{path:"/test/opaTests.qunit.html",framework:"OPA5"},testsuite:{path:"/test/testsuite.qunit.html",framework:"Testsuite"}};function jn(e,t){let n;if(e){let{editors:i,...r}=e;n={...r,endpoints:[...i]},t?.warn("The configuration option 'rta' is deprecated and has been adjusted to 'editors.rta'.")}return n}s(jn,"sanitizeRtaConfig");async function Ln(e){let t=e.findCustomMiddleware(h.FioriToolsAppreload)??e.findCustomMiddleware(h.ReloadMiddleware);if(t)return t?.configuration?.delay||(t.configuration={...t.configuration,delay:300}),t}s(Ln,"getEnhancedReloadMiddleware");function Ne(e,t){let n=(0,x.join)(t,"package.json");return{name:e.readJSON(n)?.devDependencies?.["@sap/ux-ui5-tooling"]?h.FioriToolsPreview:h.PreviewMiddleware,afterMiddleware:"compression"}}s(Ne,"createPreviewMiddlewareConfig");async function ue(e,t,n,i){let r=n?(0,x.basename)(n):M.FileName.Ui5Yaml,o=await(0,M.readUi5Yaml)(t,r,e),a=await v(o);if(!a)i?.warn(`No preview middleware found in ${r}. Preview middleware will be added.`),a=Ne(e,t);else{let u=ut(r,e,t);u?a=await ke(a,u,t,e,i):a=xt(a)}let c=await Ln(o);c&&(a.afterMiddleware=c.name,o.updateCustomMiddleware(c),i?.debug(`Updated reload middleware in ${r}.`)),o.updateCustomMiddleware(a),e.write((0,x.join)(t,r),o.toString()),i?.debug(`Updated preview middleware in ${r}.`)}s(ue,"updateMiddlewaresForPreview");function xt(e,t){if(!e.configuration)return e;if("rta"in e.configuration){let r=jn(e.configuration.rta,t);delete e.configuration.rta,e.configuration.editors??={},e.configuration.editors.rta=r}if(!X(e.configuration))return e;let n=e.configuration.ui5Theme;if(delete e.configuration,!n)return e;let i={};return i.flp={},i.flp.theme=n,e.configuration=i,e}s(xt,"sanitizePreviewMiddleware");async function ke(e,t,n,i,r){let{path:o,intent:a}=P(t.value),c=`${Tt.object}-${Tt.action}`,u=xt(e,r),d={...u.configuration},p=!1;if(ft(t,d))o?.includes(Me)||(d.flp=d.flp??{},d.flp.path=o,p=!0),a&&`${a?.object}-${a?.action}`!==c&&(d.flp=d.flp??{},d.flp.intent={object:a.object,action:a.action},p=!0);else if(o&&_(t,d))d.test=await de(d.test,o,n,i,r),p=!0;else if(!o){let m=Ue(t.name);m&&(d.test=await de(d.test,m,n,i),p=!0)}return p&&(u.configuration=d),u}s(ke,"updatePreviewMiddlewareConfig");async function de(e,t,n,i,r){let o=s(d=>d?.some(p=>p.framework==="Testsuite")??!1,"hasTestsuite");e=e??[];let a;if(t?.includes("testsuite.qunit.html")?a="Testsuite":t?.includes("opaTests.qunit.html")?a="OPA5":t?.includes("unitTests.qunit.html")&&(a="QUnit"),!a)return e;let c=K[a.toLowerCase()].path,u=e.find(d=>d.framework===a);if(u)u.path=t,u.path===c&&delete u.path;else{let d={framework:a,...t&&c!==(t.startsWith("/")?t:`/${t}`)&&{path:t}};await bn(i,n,t??c,d,r),e.push({...d}),o(e)||(e.push({framework:"Testsuite"}),r?.info("The test framework 'Testsuite' has been added because at least one test runner has been found."))}return e}s(de,"updateTestConfig");async function bn(e,t,n,i,r){let o=(0,x.join)(await(0,M.getWebappPath)(t),n.replace(".html",".js")),a=(0,x.join)(await(0,M.getWebappPath)(t),n.replace(".html",".ts")),c=e.exists(o)?o:a;if(e.exists(c))if(e.read(c).includes("sap/fe/test/JourneyRunner")){let p=c.replace(/(\.([jt])s)$/,".custom$1");e.move(c,p),i.pattern=`/test/**/${(0,x.basename)(p)}`,r?.info(`Renamed '${(0,x.basename)(c)}' to '${(0,x.basename)(p)}'. This file creates the JourneyRunner for OPA5 tests. As the handling of journey runners is not part of the virtual OPA5 test runner endpoint, this file has been renamed and added to the respective UI5 YAML configuration.`)}else await ce(e,[c])}s(bn,"sanitizeTestScript");var Q=require("node:path");var It=require("node:querystring"),Ae=require("../../commonlibs/semver/index.js");function Et(e){let t=s((o,a)=>o?.devDependencies?.[a]??o?.dependencies?.[a],"getDependencyVersion"),n={},i=t(e,"@sap-ux/preview-middleware"),r=t(e,"@sap/ux-ui5-tooling");return((i&&(0,Ae.satisfies)(i,"<0.16.89"))??(r&&(0,Ae.satisfies)(r,"<1.15.4"))??(!i&&!r))&&(n["fiori-tools-rta-mode"]="true",n["sap-ui-rta-skip-flex-validation"]="true",n["sap-ui-xx-condense-changes"]="true",n["sap-ui-xx-viewCache"]="false"),(0,It.stringify)(n)}s(Et,"getRTAUrlParameters");function Ct(e){let t=e&&"rta"in e?e?.rta?.editors:void 0;if(t??=e&&"editors"in e?e?.editors?.rta?.endpoints:void 0,t){for(let n of t)if(!("developerMode"in n))return n.path}}s(Ct,"getRTAMountPoint");async function Pt(e,t,n,i){let r;try{r=await v(void 0,e,n,i)}catch(u){throw new Error(`No ${n} file found. ${u}`)}if(r?.name===h.PreviewMiddleware&&!Ct(r?.configuration))return;let o=Ct(r?.configuration)??"/preview.html",a=ae(r?.configuration)??"#app-preview",c=t?"?"+t:"";return X(r?.configuration)?`${o}${c}#preview-app`:`${o}${c}${a}`}s(Pt,"getRTAUrl");var _e=require("../../open-ux-shared/project-access/index.js");var Ut="Script 'start-variants-management' cannot be written to package.json.";async function Ft(e,t,n,i){let r=(0,Q.join)(t,"package.json"),o=e.readJSON(r),a=n?(0,Q.basename)(n):_e.FileName.Ui5Yaml;if(!o)throw new Error(`${Ut} File 'package.json' not found at ${t}`);o.scripts||(i?.warn("File 'package.json' does not contain a script section. Script section added."),o.scripts={});let c=await Pt(t,Et(o),a,e),u=await se(t,a,e);if(!c)throw new Error(`${Ut} No RTA editor specified in ui5.yaml.`);let d=a!==_e.FileName.Ui5Yaml?` --config ./${(0,Q.basename)(a)}`:"",p=o.scripts["start-variants-management"]??void 0,m=`${u}${d} --open "${c}"`;if(!p)i?.debug("Script 'start-variants-management' not found. Script will be added.");else if(p!==m)i?.warn("Script 'start-variants-management' already exists but is outdated. Script will be updated.");else{i?.info("Script 'start-variants-management' is already up-to-date.");return}o.scripts["start-variants-management"]=m,e.writeJSON(r,o),i?.debug("Script 'start-variants-management' written to 'package.json'.")}s(Ft,"addVariantsManagementScript");async function fe(e,t,n,i){return i||(i=(0,Mt.create)((0,Nt.create)())),await ue(i,e,t,n),await Ft(i,e,t,n),i}s(fe,"generateVariantsConfig");var kt=require("node:path"),S=require("../../open-ux-shared/project-access/index.js");var U={WDIO_QUNIT_SERVICE:"wdio-qunit-service",KARMA_UI5:"karma-ui5",UI5_CLI:"@ui5/cli",SAP_UX_UI5_TOOLING:"@sap/ux-ui5-tooling",SAP_UX_UI5_MIDDLEWARE_FE_MOCKSERVER:"@sap-ux/ui5-middleware-fe-mockserver",SAP_GRUNT_SAPUI5_BESTPRACTICE_BUILD:"@sap/grunt-sapui5-bestpractice-build"};async function Rn(e,t){let n=await(0,S.findCapProjectRoot)(e,!1,t);return n?await(0,S.checkCdsUi5PluginEnabled)(n,t):!1}s(Rn,"isUsingCdsPluginUi5");async function At(e,t,n=!1,i){let r=(0,kt.join)(e,S.FileName.Package),o=t.readJSON(r),a=!0;if(!o)throw Error(`File '${S.FileName.Package}' not found at '${e}'`);return(0,S.hasDependency)(o,U.SAP_GRUNT_SAPUI5_BESTPRACTICE_BUILD)&&(i?.error(`Conversion from '${U.SAP_GRUNT_SAPUI5_BESTPRACTICE_BUILD}' is not supported. You must migrate to UI5 CLI version 3.0.0 or higher. For more information, see https://sap.github.io/ui5-tooling/v3/updates/migrate-v3.`),a=!1),B(o,U.UI5_CLI,"3.0.0")&&(i?.error("UI5 CLI version 3.0.0 or higher is required to convert the preview to virtual files. For more information, see https://sap.github.io/ui5-tooling/v3/updates/migrate-v3."),a=!1),B(o,U.SAP_UX_UI5_TOOLING,"1.15.4",!1)&&(i?.error("UX UI5 Tooling version 1.15.4 or higher is required to convert the preview to virtual files. For more information, see https://www.npmjs.com/package/@sap/ux-ui5-tooling."),a=!1),!(0,S.hasDependency)(o,U.SAP_UX_UI5_MIDDLEWARE_FE_MOCKSERVER)&&!await Rn(e,t)&&(i?.error(`Conversion from 'sap/ui/core/util/MockServer' or '@sap/ux-ui5-fe-mockserver-middleware' is not supported. You must migrate to '${U.SAP_UX_UI5_MIDDLEWARE_FE_MOCKSERVER}' first. For more information, see https://www.npmjs.com/package/@sap-ux/ui5-middleware-fe-mockserver.`),a=!1),n&&(0,S.hasDependency)(o,U.KARMA_UI5)&&i?.warn("This app seems to use Karma as a test runner. Please note that the converter does not convert any Karma configuration files. Please update your karma configuration ('ui5.configPath' and 'ui5.testpage') according to the new virtual endpoints after the conversion."),n&&(0,S.hasDependency)(o,U.WDIO_QUNIT_SERVICE)&&i?.warn("This app seems to use the WebdriverIO QUnit Service as a test runner. Please note that the converter does not convert any WebdriverIO configuration files. Please update your WebdriverIO QUnit Service test paths according to the new virtual endpoints after the conversion."),a}s(At,"checkPrerequisites");var Jt=require("../../commonlibs/mem-fs/index.js"),qt=require("../../commonlibs/mem-fs-editor/index.js");var l=require("node:path"),$e=require("../../open-ux-shared/project-access/index.js");var On=s(e=>`Renamed '${e}' to '${e.slice(0,-5)}_old.html'. This file is no longer needed for the virtual endpoints. If you have not modified this file, you can delete it. If you have modified this file, move the modified content to a custom init script for the preview middleware. For more information, see https://github.com/SAP/open-ux-tools/tree/main/packages/preview-middleware#migration.`,"renameMessage");async function pe(e,t,n,i){let r=(0,l.join)(await(0,$e.getWebappPath)(t),n);e.exists(r)?(n.endsWith("unitTests.qunit.html")&&i?.warn("Unit test files will be discovered automatically using the default pattern '/test/**/*Test.{js,ts}'. If your unit test files do not match this pattern, add a 'pattern' property to the QUnit test entry in your UI5 YAML configuration (e.g. pattern: '/test/unit/controller/*.{js,ts}'). For more details see https://github.com/SAP/open-ux-tools/blob/main/packages/preview-middleware/README.md#configuration-option-test"),e.move(r,r.replace(".html","_old.html")),i?.info(On(n))):Object.keys(e.dump(void 0,o=>o.history.includes(r)&&o.state!=="deleted")).length===0?i?.debug(`The file '${n}', has already been renamed. Skipping renaming.`):i?.debug(`The file '${n}', has not been found. Skipping renaming.`)}s(pe,"renameSandbox");async function _t(e,t,n){let i=[(0,l.join)("test","flpSandbox.html"),(0,l.join)("test","flpSandboxMockserver.html")];for(let r of i)await pe(e,t,r,n)}s(_t,"renameDefaultSandboxes");async function $t(e,t,n){for(let i of Object.values(K).map(r=>r.path))await pe(e,t,i,n)}s($t,"renameDefaultTestFiles");async function jt(e,t,n,i){let r=(0,l.join)(await(0,$e.getWebappPath)(t,e),"test"),o=[(0,l.join)(r,"locate-reuse-libs.js"),(0,l.join)(r,"changes_loader.js"),(0,l.join)(r,"changes_loader.ts"),(0,l.join)(r,"changes_preview.js"),(0,l.join)(r,"changes_preview.ts"),(0,l.join)(r,"flpSandbox.js"),(0,l.join)(r,"flpSandbox.ts"),(0,l.join)(r,"initFlpSandbox.js"),(0,l.join)(r,"initFlpSandbox.ts")];n&&(o.push((0,l.join)(r,"testsuite.qunit.js")),o.push((0,l.join)(r,"testsuite.qunit.ts")),o.push((0,l.join)(r,"integration","opaTests.qunit.js")),o.push((0,l.join)(r,"integration","opaTests.qunit.ts")),o.push((0,l.join)(r,"unit","unitTests.qunit.js")),o.push((0,l.join)(r,"unit","unitTests.qunit.ts"))),await ce(e,o,i)}s(jt,"deleteNoLongerUsedFiles");var H=require("node:path");var L=require("node:path");var Lt=require("../../open-ux-shared/project-access/index.js");function bt(e,t){let n=(0,L.join)(t,"package.json"),i=e.readJSON(n);!i||["@sap-ux/preview-middleware","@sap/ux-ui5-tooling"].some(o=>(0,Lt.hasDependency)(i,o))||(i.devDependencies={...i.devDependencies,"@sap-ux/preview-middleware":"latest"},e.writeJSON(n,i))}s(bt,"ensurePreviewMiddlewareDependency");async function Rt(e,t,n){let i=(0,L.join)(t,"package.json"),r=e.readJSON(i);if(r?.scripts?.["start-variants-management"]){let o=(0,L.basename)(W(r?.scripts?.["start-variants-management"])),a=(0,L.join)(t,o);await fe(t,a,n,e)}}s(Rt,"updateVariantsCreationScript");var T=require("../../open-ux-shared/project-access/index.js");function Dn(e,t,n,i){return n.includes(e)?!0:(i?.warn(`Skipping script '${t}', because the UI5 YAML configuration file, '${e}', could not be found.`),!1)}s(Dn,"isUi5YamlToBeConverted");async function Yn(e,t,n,i,r,o){let a=Object.keys(e.dump(t,d=>d.basename===n&&d.state==="modified")).length>0,c=(await v(void 0,t,n,e))?.configuration?.flp?.path,{path:u}=P(i.value);return a&&c!=u&&(!r||!_(i))?(o?.warn(`Skipping script '${i.name}', because another script also refers to UI5 YAML configuration file, '${n}'. Adjust the 'flp.path' property in the UI5 YAML configuration file to the correct endpoint or create a separate UI5 YAML configuration file for script '${i.name}'. ${n} currently uses ${c??Me} whereas script '${i.name}' uses '${u}'.`),!0):!1}s(Yn,"isUi5YamlFlpPathAlreadyConverted");async function Ot(e,t,n,i,r,o=!1){let a;try{a=await(0,T.readUi5Yaml)(t,n,e,{validateSchema:!0})}catch(d){throw new Error(`An error occurred when reading '${n}': ${d.message}`)}let c=await v(a);if(o&&!c)return;c||(c=Ne(e,t)),c=await ke(c,i,t,e,r),a.updateCustomMiddleware(c);let u=(0,H.join)(t,n);e.write(u,a.toString())}s(Ot,"processUi5YamlConfig");async function Dt(e,t,n){let i=await(0,T.getAllUi5YamlFileNames)(t,e);for(let c of i.filter(u=>u!==T.FileName.Ui5Yaml)){let u=await(0,T.readUi5Yaml)(t,c,e);if((await v(u))?.configuration?.test)return}let r;try{r=await(0,T.readUi5Yaml)(t,T.FileName.Ui5Yaml,e)}catch(c){n?.warn(`The UI5 YAML configuration file 'ui5.yaml', can't be updated to support test frameworks: '${c}'. Please manually add the test configuration to the UI5 YAML configuration file used for testing according to https://github.com/SAP/open-ux-tools/tree/main/packages/preview-middleware#configuration-option-test.`);return}let o=await v(r);for(let c of Object.values(K)){if(o.configuration?.test?.some(u=>u.framework.toLowerCase()===c.framework.toLowerCase()))break;o.configuration.test=await de(o.configuration.test,c.path,t,e,n),n?.info(`The UI5 YAML configuration file 'ui5.yaml', has been updated to support the test framework '${c.framework}'. Please consider transferring the test configuration to the UI5 YAML configuration file used for testing.`)}r.updateCustomMiddleware(o);let a=(0,H.join)(t,T.FileName.Ui5Yaml);e.write(a,r.toString())}s(Dt,"updateDefaultTestConfig");async function Yt(e,t,n,i){let r=await(0,T.getAllUi5YamlFileNames)(t,e),o=[...r];for(let[a,c]of Ee(e,t)){let u={name:a,value:c};if(!c||!Pe(u,n))continue;let d=(0,H.basename)(W(c));if(o.splice(o.indexOf(d),1),!Dn(d,a,r,i)||await Yn(e,t,d,u,n,i))continue;try{await Ot(e,t,d,u,i)}catch(m){i?.warn(`Skipping script '${a}', which refers to the UI5 YAML configuration file '${d}'. ${m.message}`);continue}let{path:p}=P(c);p&&await pe(e,t,p,i),bt(e,t),i?.info(`The UI5 YAML configuration file '${d}', has been updated according to script, '${a}'.`)}for(let a of o){let c={name:"",value:""};try{await Ot(e,t,a,c,i,!0)}catch(u){i?.warn(`Skipping UI5 YAML configuration file '${a}'. ${u.mesage}`)}i?.warn(`The UI5 YAML configuration file '${a}', is not used in any preview script. Outdated preview middleware will be adjusted, if necessary.`)}}s(Yt,"updatePreviewMiddlewareConfigs");async function Vt(e,t){let n=t.fs??(0,qt.create)((0,Jt.create)()),i=t.logger,r=t.convertTests??!1;if(!await At(e,n,r,i))throw new Error("The prerequisites are not met. For more information, see the log messages above.");return await Yt(n,e,r,i),await _t(n,e,i),r&&(await $t(n,e,i),await Dt(n,e,i)),await jt(n,e,r,i),await Rt(n,e,i),n}s(Vt,"convertToVirtualPreview");var R=require("node:path"),Bt=require("../../commonlibs/mem-fs/index.js"),Xt=require("../../commonlibs/mem-fs-editor/index.js");var O=require("../../open-ux-shared/project-access/index.js");var b=require("../../open-ux-shared/project-access/index.js"),Gt=require("../../commonlibs/semver/index.js");var Jn="1.121.0",qn="1.149.0";async function Wt(e,t){let{manifest:n}=await j(e,t),i=(0,b.getMinimumUI5Version)(n),r=await(0,b.findProjectRoot)(e,!0,!0,t),a=await(0,b.getProjectType)(r)==="EDMXBackend"?Jn:qn;if(i&&!(0,Gt.gte)(i,a))throw new Error(`The card generator is only supported for projects with a minimum SAPUI5 version of ${a} or higher. The detected minimum SAPUI5 version is ${i}. Update the sap.ui5.minUI5Version property in the manifest.json file and ensure the SAPUI5 version used is ${a} or higher.`)}s(Wt,"ensureMinUI5Version");var je="@sap-ux/cards-editor-middleware",le="sap-cards-generator";async function Vn(e,t,n,i){let r=n?(0,R.basename)(n):O.FileName.Ui5Yaml,o=await(0,O.readUi5Yaml)(t,r,e);if(o.findCustomMiddleware(le))try{o.removeCustomMiddleware(le),i?.info(`Removed '${le}' middleware configuration from ${r}. It is no longer needed because this feature has been integrated into fiori-tools-preview / preview-middleware.`)}catch(c){i?.warn(`Failed to remove '${le}' middleware: ${c.message}`)}let a=await v(o,t,n,e);if(a){a.configuration??={};let c=a.configuration,u=c?.editors?.cardGenerator?.path??"/test/flpCardGeneratorSandbox.html";c.editors??={},c.editors.cardGenerator={path:u},o.updateCustomMiddleware(a),e.write((0,R.join)(t,r),o.toString()),i?.debug(`Updated preview middleware in ${r}.`)}}s(Vn,"updateMiddlewareConfigWithGeneratorPath");async function Gn(e,t,n,i){let r=(0,R.join)(e,"package.json");if(!t.exists(r))throw new Error("package.json not found");let o=t.readJSON(r)??{},a=n?(0,R.basename)(n):O.FileName.Ui5Yaml,c=await(0,O.readUi5Yaml)(e,a,t),u=await v(c,e,a,t),d=ae(u?.configuration)??"#app-preview",p=u?.configuration?.editors?.cardGenerator?.path??"/test/flpCardGeneratorSandbox.html",m=await se(e,a,t);o.scripts??={},o.scripts["start-cards-generator"]=`${m} --open "${p}${d}"`,o.devDependencies?.[je]&&(delete o.devDependencies[je],i?.info(`Removed devDependency ${je} from package.json. It is no longer needed because this feature has been integrated into fiori-tools-preview / preview-middleware.`)),t.writeJSON(r,o)}s(Gn,"updatePackageJson");async function Kt(e,t,n,i,r=!0){return i=i??(0,Xt.create)((0,Bt.create)()),await Wt(e,i),await ue(i,e,t,n),await Vn(i,e,t,n),r&&await Gn(e,i,t,n),i}s(Kt,"enableCardGeneratorConfig");var me=require("node:path"),Qt=require("../../commonlibs/mem-fs-editor/index.js"),Ht=require("../../commonlibs/mem-fs/index.js"),N=require("../../open-ux-shared/project-access/index.js");var Le="sap/bc/ui5_ui5/ui2/ushell/shells/abap/Fiorilaunchpad.html";async function zt(e,t,n=Le,i=N.FileName.Ui5Yaml,r=(0,Qt.create)((0,Ht.create)()),o){let a=t.trim().toLowerCase();if(!a)throw new Error("Mandatory parameter bspApplication is missing.");if(await(0,N.isCapProject)(e))throw new Error("CAP projects are not supported for FLP Embedded Mode configuration.");let c=(0,me.join)(e,i);if(!r.exists(c))throw new Error(`Configuration file ${c} not found. Please provide a valid path`);return Wn(r,e,n,o),await Bn(r,e,i,a,o),r}s(zt,"generateFlpEmbeddedConfig");function Wn(e,t,n,i){let r=(0,me.join)(t,N.FileName.Package),o=e.readJSON(r);if(!o)throw new Error(`File 'package.json' not found at ${t}`);o.scripts??={},o.scripts["start-embedded"]=`ui5 build && fiori run --config ./flp.yaml --open "${n}?sap-ushell-nocb=true"`,e.writeJSON(r,o),i?.debug("Script 'start-embedded' written to 'package.json'.")}s(Wn,"addStartEmbeddedScript");async function Bn(e,t,n,i,r){let o=(0,me.join)(t,"flp.yaml"),a=await(0,N.readUi5Yaml)(t,n,e),c=a.getMetadata();if(!c?.name)throw new Error(`The configuration file '${n}' is missing a 'metadata.name' field.`);let u=c.name.replaceAll(".","/"),d="dist",p=[{path:"/**/"+i,src:d}];u!==i&&p.push({path:"/**/"+u,src:d}),a.setConfiguration({paths:{webapp:d}});let m=a.findCustomMiddleware("fiori-tools-appreload");m&&a.updateCustomMiddleware({...m,configuration:{...m.configuration,path:d}});let D=a.findCustomMiddleware("fiori-tools-proxy");D&&a.updateCustomMiddleware({...D,configuration:{...D.configuration,bsp:i}}),a.addCustomMiddleware([{name:"fiori-tools-servestatic",beforeMiddleware:"fiori-tools-proxy",configuration:{paths:p}}]),e.write(o,a.toString()),r?.debug("'flp.yaml' written.")}s(Bn,"addFlpYaml");var Xn=void 0;0&&(module.exports={DEFAULT_FLP_PATH,convertEslintConfig,convertToVirtualPreview,enableCardGeneratorConfig,generateEslintConfig,generateFlpEmbeddedConfig,generateInboundNavigationConfig,generateSmartLinksConfig,generateVariantsConfig,getSmartLinksTargetFromPrompt,includeTestRunnersPrompt,readManifest,simulatePrompt});