@sap/generator-fiori
Version:
Create an SAPUI5 application using SAP Fiori elements or a freestyle approach
5 lines (3 loc) • 5.67 kB
JavaScript
const __esmImportMetaUrl = require('node:url').pathToFileURL(__filename).href;
var _=Object.create;var h=Object.defineProperty;var q=Object.getOwnPropertyDescriptor;var z=Object.getOwnPropertyNames;var K=Object.getPrototypeOf,B=Object.prototype.hasOwnProperty;var i=(t,e)=>h(t,"name",{value:e,configurable:!0});var G=(t,e)=>{for(var n in e)h(t,n,{get:e[n],enumerable:!0})},k=(t,e,n,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of z(e))!B.call(t,o)&&o!==n&&h(t,o,{get:()=>e[o],enumerable:!(a=q(e,o))||a.enumerable});return t};var H=(t,e,n)=>(n=t!=null?_(K(t)):{},k(e||!t||!t.__esModule?h(n,"default",{value:t,enumerable:!0}):n,t)),Q=t=>k(h({},"__esModule",{value:!0}),t);var ot={};G(ot,{applyCAPUpdates:()=>V,checkCdsUi5PluginEnabled:()=>L.checkCdsUi5PluginEnabled,default:()=>nt,enableCdsUi5Plugin:()=>l,getAppLaunchText:()=>E});module.exports=Q(ot);var L=require("../open-ux-shared/project-access/index.js");var O=require("node:path"),A=require("../commonlibs/mem-fs/index.js"),J=require("../commonlibs/mem-fs-editor/index.js");var d=require("../open-ux-shared/project-access/index.js");function b(t){(0,d.hasMinCdsVersion)(t)||(t.dependencies??={},t.dependencies["@sap/cds"]=`^${d.MinCdsVersion}`)}i(b,"ensureMinCdsVersion");async function N(t,e){let{appWorkspace:n,workspaceEnabled:a,workspacePackages:o}=await(0,d.getWorkspaceInfo)(t,e);a||(o.length===0&&(e.workspaces??=[],Array.isArray(e.workspaces)?o=e.workspaces:(e.workspaces.packages=[],o=e.workspaces.packages)),o.push(n))}i(N,"enableWorkspaces");function j(t){(0,d.hasDependency)(t,"cds-plugin-ui5")||(t.devDependencies??={},t.devDependencies["cds-plugin-ui5"]=`^${d.MinCdsPluginUi5Version}`)}i(j,"addCdsPluginUi5");async function l(t,e){e||(e=(0,J.create)((0,A.create)()));let n=(0,O.join)(t,"package.json"),a=e.readJSON(n)??{},o=structuredClone(a);return b(a),await N(t,a),j(a),JSON.stringify(o)!==JSON.stringify(a)&&e.writeJSON(n,a),e}i(l,"enableCdsUi5Plugin");var U=require("node:fs"),u=require("../open-ux-shared/project-access/index.js"),c=require("node:path");function w(t,e){let n="sap-ui-xx-viewCache=false",a=e??t+"/webapp";return{[`watch-${t}`]:`cds watch --open ${a}/index.html?${n}${e?" --livereload false":""}`}}i(w,"getCDSWatchScript");function X(t,e,n){t.extendJSON(e,{scripts:n})}i(X,"updatePackageJsonWithScripts");async function Z(t,e,n,a){let o={};if(!a?.scripts)return o;for(let r in a.scripts)if(r.startsWith("watch-")&&a?.scripts?.[r]?.includes("/webapp/")){let p=r.split("-")[1],s=(0,c.join)(e,n,p);if((0,U.existsSync)(s)){let m=(0,c.join)(await(0,u.getWebappPath)(s),u.FileName.Manifest),g=t.readJSON(m)["sap.app"]?.id;g&&Object.assign(o,w(p,g))}}return o}i(Z,"updateExistingWatchScripts");async function tt(t,e,{projectPath:n,projectName:a,appsPath:o,appId:r},p){let s={};p?(Object.assign(s,await Z(t,n,o,e)),Object.assign(s,w(a,r))):s=w(a),X(t,(0,c.join)(n,"package.json"),s)}i(tt,"updateScripts");async function D(t,e,n,a,o,r){let p=(0,c.join)(a.projectPath,"package.json"),s=t.readJSON(p)??{},m="Node.js",f=(await(0,u.getCapCustomPaths)(a.projectPath)).app;if(a?.capType===m&&(r&&await l(a.projectPath,t),await tt(t,s,{projectPath:a.projectPath,projectName:e,appsPath:f,appId:o},r)),n){let g=(0,c.join)(a.appPath??f,e),S=(0,c.normalize)(g).split(/[\\/]/g).join(c.posix.sep),F=Array.isArray(s?.sapux)?[...s.sapux,S]:[S];t.extendJSON(p,{sapux:F})}}i(D,"updateRootPackageJson");function T(t,e){let n=(0,c.join)(e,"package.json"),a=t.readJSON(n)??{};delete a.sapux,a?.scripts&&delete a.scripts["int-test"];for(let o in a.scripts)o.startsWith("start")&&delete a.scripts[o];t.writeJSON(n,a)}i(T,"updateAppPackageJson");var R=require("../open-ux-shared/project-access/index.js"),Y=require("../open-ux-shared/yaml/index.js"),v=require("node:path");var W=H(require("../commonlibs/i18next/index.js"),1);var I={info:{capServiceName:"CAP Service Name: {{ capServiceName }}.",cdsUpdateInfo:"Update CDS file with `projectPath`: {{ projectPath }}, `annotationPath`: {{ annotationPath }} and `capService`: {{ capService }}."},warn:{cdsDKNotInstalled:"`cds-dk` {{ minCdsVersion }} or higher is required to add CDS watch scripts. Install `cds-dk` to continue."},error:{updateApplicationYaml:"An error occured when updating the application YAML. Error: {{ error }}."},launchCapText:`To launch the generated app, start your CAP project: {{mvnCommand}} and navigate to the following location in your browser:
{{- capUrl}}`};var x="cap-config-writer",$=W.default.createInstance();async function P(){await $.init({resources:{en:{[x]:I}},lng:"en",fallbackLng:"en",defaultNS:x,ns:[x],showSupportNotice:!1})}i(P,"initI18n");function C(t,e){return $.t(t,e)}i(C,"t");P().catch(()=>{});function M(t,e){let n=(0,v.join)(e,R.FileName.Tsconfig);if(t.exists(n)){let a=t.readJSON(n);if(a.compilerOptions.typeRoots){let o=a.compilerOptions.typeRoots,r=o.map(p=>p.replace(/\.\//g,"../../"));t.extendJSON(n,{compilerOptions:{typeRoots:[...o,...r]}})}}}i(M,"updateTsConfig");async function V(t,e,n){let{appRoot:a,packageName:o,appId:r,sapux:p=!1,enableCdsUi5Plugin:s=!0,enableTypescript:m=!1,disableRootPackageJsonUpdates:f=!1}=n;f?s&&await l(e.projectPath,t):await D(t,o,p,e,r,s),m&&M(t,a),e.capType==="Node.js"&&s&&T(t,a)}i(V,"applyCAPUpdates");function at(t,e,n){let a=n??e+"/webapp";return t==="Java"?`http://localhost:8080/${e}/webapp/index.html`:`http://localhost:4004/${a}/index.html`}i(at,"getCapUrl");async function E(t,e,n){await P();let a=t==="Java"?" (```mvn spring-boot:run```)":"",o=at(t,e,n);return`${C("launchCapText",{mvnCommand:a,capUrl:o})}`}i(E,"getAppLaunchText");var nt=void 0;0&&(module.exports={applyCAPUpdates,checkCdsUi5PluginEnabled,enableCdsUi5Plugin,getAppLaunchText});