UNPKG

@sap/generator-fiori

Version:

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

1 lines 4.81 kB
"use strict";exports.id=7947,exports.ids=[7947],exports.modules={29511(e,r,a){a.d(r,{c:()=>generate});var o=a(76760),n=a(73136),i=a(64812),s=a(90718),c=a(27381),p=a(29473),l=a(7083),m=a(2307),d=a(85263);function getTypePackageFor(e,r){const a=(0,d.gte)(r,"1.113.0")?"types":"ts-types-esm";return`@${e.toLowerCase()}/${a}`}var u=a(68801);const h=JSON.parse('{"error":{"missingRequiredProperty":"The property: {{ propertyName }} must have a value.","useAlphaNumeric":"Only use lowercase alphanumeric characters for the property: {{ propertyName }}.","invalidUI5Version":"The specified SAPUI5 version is invalid: {{ version }}. Choose a valid SAPUI5 version.","invalidNamespace":{"mustStartWithLetter":"The namespace must start with a letter.","endsInPeriod":"The namespace cannot end with a period.","isSap":"The namespace cannot be {{ str }}.","startsWithNew":"The namespace cannot start with {{ str }}.","numAfterPeriod":"A number cannot follow a period in the namespace.","specialCharacter":"The namespace must only contain letters, digits, dots, and underscores.","tooLong":"The combined length of the application namespace and module name must not exceed {{ length }} characters."}}}'),f="ui5-library-writer",w=u.createInstance();function t(e,r){return w.t(e,r)}function validateNamespace(e,r){if(!e)throw new Error(t("error.missingRequiredProperty",{propertyName:"namespace"}));return function validateNamespacePattern(e,r){if(!/^[a-zA-Z]/.test(e))throw new Error(t("error.invalidNamespace.mustStartWithLetter"));if(e.endsWith("."))throw new Error(t("error.invalidNamespace.mustEndInPeriod"));if("SAP"===e.toUpperCase())throw new Error(t("error.invalidNamespace.cannotBeSap",{str:e}));if(e.toLowerCase().startsWith("new"))throw new Error(t("error.invalidNamespace.cannotStartWithNew",{str:e.substring(0,3)}));if(/\.\d/.test(e))throw new Error(t("error.invalidNamespace.numAfterPeriod"));if(!/^[a-zA-Z\d_.]+$/.test(e))throw new Error(t("error.invalidNamespace.specialCharacter"));if((r+e).length>70)throw new Error(t("error.invalidNamespace.tooLong",{length:70}));return!0}(e,r)}function validate(e){return function validateLibName(e){if(!e)throw new Error(t("error.missingRequiredProperty",{propertyName:"libraryName"}));if(!/^[a-z][a-z0-9]*$/g.test(e))throw new Error(t("error.useAlphaNumeric",{propertyName:"libraryName"}));return!0}(e.libraryName)&&validateNamespace(e.namespace,e.libraryName)&&function validateUI5Version(e){if(e&&null===d.coerce(e))throw new Error(t("error.invalidUI5Version",{version:e}));return!0}(e.frameworkVersion)}(async function initI18n(){await w.init({resources:{en:{[f]:h}},lng:"en",fallbackLng:"en",defaultNS:f,ns:[f],showSupportNotice:!1})})().catch(()=>{});const g="1.120.0";function getTemplateVersionPath(e){let r="";return r=function compareUI5VersionGte(e,r){return""===e||(0,d.gte)(e,r,{loose:!0})}(e,g)?g:"1.71.0",r}const y=(0,o.dirname)((0,n.fileURLToPath)(require("node:url").pathToFileURL(__filename).href));async function generate(e,r,a){const n=c(r);a||(a=(0,s.v)((0,i.v)()));const d=function mergeWithDefaults(e){validate(e);const r=`${e.namespace}.${e.libraryName}`,a=e.author??"UX Tools";return{...e,author:a,namespaceURI:e.namespace.split(".").join("/"),libraryNamespace:r,libraryNamespaceURI:r.split(".").join("/"),libraryBasepath:r.split(".").map(e=>"..").join("/")+"/"}}(r);e=(0,o.join)(e,d.libraryNamespace);const u=(0,o.join)(y,"..","templates"),h=[n.typescript?"**/*.js":"**/*.ts"],f=getTemplateVersionPath(n.frameworkVersion);return a.copyTpl((0,o.join)(u,"common",f,"**/*.*"),e,d,void 0,{globOptions:{dot:!0,ignore:h},processDestinationPath:e=>e.replace("baselibrary",d.libraryNamespaceURI).replace(/gitignore.tmpl/g,".gitignore").replace(/karma.conf.tmpl/g,"karma.conf.js")}),n.typescript&&await async function enableTypescript(e,r,a,n){const i=(0,o.join)(a,"optional","typescript"),s=await(0,l.be)(i),c={...e,tsTypes:getTypePackageFor(e.framework,e.frameworkVersion),tsTypesVersion:e.frameworkVersion};s.forEach(e=>{const a=e.replace(i,""),s=(0,o.join)(r,a);if(n.exists(s)){const r=JSON.parse((0,p.render)(n.read(e),c,{})),a=JSON.parse(n.read(s)),o=(0,m.rL)(a,r);n.writeJSON(s,o)}else n.copyTpl(e,s,c,void 0,{globOptions:{dot:!0}})});const d=(0,o.join)(r,"ui5.yaml"),u=await m.io.newInstance(n.read(d));u.updateCustomMiddleware({name:"fiori-tools-appreload",afterMiddleware:"compression",configuration:{path:"src",port:35729,delay:300}}),u.updateCustomMiddleware({name:"ui5-tooling-transpile-middleware",afterMiddleware:"compression",configuration:{debug:!0,transformModulesToUI5:{overridesToOverride:!0},excludePatterns:["/Component-preload.js"]}}),u.addCustomTasks([{name:"ui5-tooling-transpile-task",afterTask:"replaceVersion",configuration:{debug:!0,transformModulesToUI5:{overridesToOverride:!0}}}]),n.write(d,u.toString())}(d,e,u,a),a}}};