-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from longieirl/feat/generate-third-party-app
feat: How to add a third party module
- Loading branch information
Showing
41 changed files
with
3,658 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Adding External Library to your SAP Fiori UI application | ||
|
||
# Prerequisites | ||
|
||
- You’ll need an SAP Business Technology Platform (SAP BTP) account | ||
- You are subscribed to SAP Business Application Studio, follow this [tutorial](https://help.sap.com/products/SAP%20Business%20Application%20Studio/9d1db9835307451daa8c930fbd9ab264/6331319fd9ea4f0ea5331e21df329539.html) for more information | ||
- Sub-account destination `northwind` is available, please see attached `northind` configuration | ||
|
||
# Sample Project | ||
The [freestyle SAPUI5 application](./ztravelapp/README.md) demonstrates how to add an external third party library `xml-js` to the project. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# | ||
URL=https\://services.odata.org | ||
Name=northwind | ||
ProxyType=Internet | ||
Type=HTTP | ||
Authentication=NoAuthentication |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
node_modules/ | ||
dist/ | ||
.scp/ | ||
.env | ||
Makefile*.mta | ||
mta_archives | ||
mta-* | ||
resources | ||
archive.zip | ||
.*_mta_build_tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Ensure we always use public packages, i.e. avoid using local registries from ~/.npmrc | ||
@sap:registry=https://registry.npmjs.org/ | ||
registry=https://registry.npmjs.org/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Adding External Library to your SAP Fiori UI application | ||
|
||
In this sample project, `xml-js` is going to be added as an external library. | ||
|
||
# Prerequisites | ||
|
||
- You’ll need an SAP Business Technology Platform (SAP BTP) account | ||
- You are subscribed to SAP Business Application Studio, follow this [tutorial](https://help.sap.com/products/SAP%20Business%20Application%20Studio/9d1db9835307451daa8c930fbd9ab264/6331319fd9ea4f0ea5331e21df329539.html) for more information | ||
- Sub-account destination `northwind` is available | ||
|
||
# Create SAP Fiori Dev Space | ||
|
||
From your SAP BTP cockpit, select Instances and Subscriptions, select SAP Business Application Studio which will open a new tab into your dev space manager. Generate a SAP Fiori dev space. | ||
|
||
# Generate a freestyle SAPUI5 application | ||
|
||
Please refer to the following link, [Developing Apps with SAP Fiori Tools](https://sapui5.hana.ondemand.com/sdk/#/topic/a460a7348a6c431a8bd967ab9fb8d918) for more information. | ||
|
||
# Tasks | ||
|
||
Append third party library to `package.json`; | ||
```bash | ||
npm install xml-js --save-prod | ||
``` | ||
|
||
Append UI5 tooling extension to include a custom middleware and a custom task which allows use of NPM package names in your code; | ||
```bash | ||
npm install ui5-tooling-modules --save-prod | ||
``` | ||
|
||
Open `ui5.yaml` and append a new task, ensuring the alignment is maintained; | ||
```YAML | ||
- name: ui5-tooling-modules-middleware | ||
afterMiddleware: compression | ||
configuration: | ||
addToNamespace: true | ||
``` | ||
Open `View1.controller.js` and append the `xml-js` library; | ||
```JS | ||
sap.ui.define( | ||
["sap/ui/core/mvc/Controller", "xml-js"], | ||
``` | ||
|
||
Understanding the `sap.ui.defined` JavaScript namespace, please refer to this [link](https://sapui5.hana.ondemand.com/sdk/#/api/sap.ui%23methods/sap.ui.define) paying attention to the `Third Party Modules` section, as this provides guidance on how third party modules are imported and referenced. | ||
|
||
Next, update the `function` to reference this library; | ||
```JS | ||
function (Controller, xmljs) { | ||
``` | ||
|
||
With these changes, you can now consume the library inside your code; | ||
```JS | ||
var xmlToJson = JSON.parse( | ||
xmljs.xml2json(xml, { | ||
compact: true, | ||
spaces: 4, | ||
}) | ||
); | ||
console.log(`>>>> xmlToJson ${JSON.stringify(xmlToJson)}`); | ||
``` | ||
|
||
# Additional Links | ||
|
||
* [External libraries in UI5 + CAP + SAP Build Work Zone, Standard Edition](https://blogs.sap.com/2023/11/08/external-libraries-in-ui5-cap-sap-build-work-zone-standard-edition/) | ||
* [Smart templates and SAP Fiori Apps – 57 Tips and Tricks](https://blogs.sap.com/2019/09/20/smart-templates-tips-and-tricks/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
_schema-version: "3.2" | ||
ID: reuselibtravelapp | ||
version: 0.0.1 | ||
modules: | ||
- name: reuselibtravelapp-destination-content | ||
type: com.sap.application.content | ||
requires: | ||
- name: reuselibtravelapp-destination-service | ||
parameters: | ||
content-target: true | ||
- name: reuselibtravelapp-repo-host | ||
parameters: | ||
service-key: | ||
name: reuselibtravelapp-repo-host-key | ||
- name: reuselibtravelapp-uaa | ||
parameters: | ||
service-key: | ||
name: reuselibtravelapp-uaa-key | ||
parameters: | ||
content: | ||
instance: | ||
destinations: | ||
- Name: reuselibtravelapp_html_repo_host | ||
ServiceInstanceName: reuselibtravelapp-html5-srv | ||
ServiceKeyName: reuselibtravelapp-repo-host-key | ||
sap.cloud.service: reuselibtravelapp | ||
- Authentication: OAuth2UserTokenExchange | ||
Name: reuselibtravelapp_uaa | ||
ServiceInstanceName: reuselibtravelapp-xsuaa-srv | ||
ServiceKeyName: reuselibtravelapp-uaa-key | ||
sap.cloud.service: reuselibtravelapp | ||
existing_destinations_policy: ignore | ||
build-parameters: | ||
no-source: true | ||
- name: reuselibtravelapp-app-content | ||
type: com.sap.application.content | ||
path: . | ||
requires: | ||
- name: reuselibtravelapp-repo-host | ||
parameters: | ||
content-target: true | ||
build-parameters: | ||
build-result: resources | ||
requires: | ||
- artifacts: | ||
- reuselibtravelapp.zip | ||
name: reuselibtravelapp | ||
target-path: resources/ | ||
- name: reuselibtravelapp | ||
type: html5 | ||
path: . | ||
build-parameters: | ||
build-result: dist | ||
builder: custom | ||
commands: | ||
- npm install | ||
- npm run build:cf | ||
supported-platforms: [] | ||
resources: | ||
- name: reuselibtravelapp-destination-service | ||
type: org.cloudfoundry.managed-service | ||
parameters: | ||
config: | ||
HTML5Runtime_enabled: true | ||
init_data: | ||
instance: | ||
destinations: | ||
- Authentication: NoAuthentication | ||
Name: ui5 | ||
ProxyType: Internet | ||
Type: HTTP | ||
URL: https://ui5.sap.com | ||
existing_destinations_policy: update | ||
version: 1.0.0 | ||
service: destination | ||
service-name: reuselibtravelapp-destination-service | ||
service-plan: lite | ||
- name: reuselibtravelapp-uaa | ||
type: org.cloudfoundry.managed-service | ||
parameters: | ||
path: ./xs-security.json | ||
service: xsuaa | ||
service-name: reuselibtravelapp-xsuaa-srv | ||
service-plan: application | ||
- name: reuselibtravelapp-repo-host | ||
type: org.cloudfoundry.managed-service | ||
parameters: | ||
service: html5-apps-repo | ||
service-name: reuselibtravelapp-html5-srv | ||
service-plan: app-host | ||
parameters: | ||
deploy_mode: html5-repo | ||
enable-parallel-deployments: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{ | ||
"name": "ztravel", | ||
"version": "0.0.1", | ||
"private": true, | ||
"description": "A Fiori application.", | ||
"keywords": [ | ||
"ui5", | ||
"openui5", | ||
"sapui5" | ||
], | ||
"main": "webapp/index.html", | ||
"dependencies": { | ||
"ui5-tooling-modules": "3.2.4", | ||
"xml-js": "^1.6.11" | ||
}, | ||
"devDependencies": { | ||
"@sap-ux/ui5-middleware-fe-mockserver": "2", | ||
"@sap/ui5-builder-webide-extension": "^1.1.8", | ||
"@sap/ux-ui5-tooling": "1", | ||
"@ui5/cli": "^3.0.0", | ||
"mbt": "^1.2.18", | ||
"ui5-task-zipper": "^0.5.0" | ||
}, | ||
"scripts": { | ||
"start": "fiori run --open \"test/flpSandbox.html?sap-ui-xx-viewCache=false#ztestdocapp1ztravel-display\"", | ||
"start-local": "fiori run --config ./ui5-local.yaml --open \"test/flpSandbox.html?sap-ui-xx-viewCache=false#ztestdocapp1ztravel-display\"", | ||
"build": "ui5 build --config=ui5.yaml --clean-dest --dest dist", | ||
"deploy": "fiori verify", | ||
"deploy-config": "fiori add deploy-config", | ||
"start-noflp": "fiori run --open \"index.html?sap-ui-xx-viewCache=false\"", | ||
"start-mock": "fiori run --config ./ui5-mock.yaml --open \"test/flpSandbox.html?sap-ui-xx-viewCache=false#ztestdocapp1ztravel-display\"", | ||
"start-variants-management": "fiori run --open \"preview.html?sap-ui-xx-viewCache=false&fiori-tools-rta-mode=true&sap-ui-rta-skip-flex-validation=true#preview-app\"", | ||
"unit-tests": "fiori run --config ./ui5-mock.yaml --open 'test/unit/unitTests.qunit.html'", | ||
"int-tests": "fiori run --config ./ui5-mock.yaml --open 'test/integration/opaTests.qunit.html'", | ||
"build:cf": "ui5 build preload --clean-dest --config ui5-deploy.yaml --include-task=generateCachebusterInfo" | ||
}, | ||
"sapuxLayer": "VENDOR", | ||
"ui5": { | ||
"dependencies": [ | ||
"@sap/ui5-builder-webide-extension", | ||
"ui5-task-zipper", | ||
"mbt" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# yaml-language-server: $schema=https://sap.github.io/ui5-tooling/schema/ui5.yaml.json | ||
specVersion: "2.4" | ||
metadata: | ||
name: ztest.docapp1.ztravel | ||
type: application | ||
resources: | ||
configuration: | ||
propertiesFileSourceEncoding: UTF-8 | ||
builder: | ||
resources: | ||
excludes: | ||
- "/test/**" | ||
- "/localService/**" | ||
customTasks: | ||
- name: webide-extension-task-updateManifestJson | ||
afterTask: replaceVersion | ||
configuration: | ||
appFolder: webapp | ||
destDir: dist | ||
- name: ui5-task-zipper | ||
afterTask: generateCachebusterInfo | ||
configuration: | ||
archiveName: ztestdocapp1ztravel | ||
additionalFiles: | ||
- xs-app.json | ||
- name: ui5-tooling-modules-task | ||
afterTask: replaceVersion | ||
configuration: | ||
addToNamespace: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# yaml-language-server: $schema=https://sap.github.io/ui5-tooling/schema/ui5.yaml.json | ||
|
||
specVersion: "3.1" | ||
metadata: | ||
name: ztest.docapp1.ztravel | ||
type: application | ||
framework: | ||
name: SAPUI5 | ||
version: 1.114.7 | ||
libraries: | ||
- name: sap.m | ||
- name: sap.ui.core | ||
- name: sap.f | ||
- name: sap.suite.ui.generic.template | ||
- name: sap.ui.comp | ||
- name: sap.ui.generic.app | ||
- name: sap.ui.table | ||
- name: sap.ushell | ||
- name: themelib_sap_horizon | ||
server: | ||
customMiddleware: | ||
- name: fiori-tools-appreload | ||
afterMiddleware: compression | ||
configuration: | ||
port: 35729 | ||
path: webapp | ||
delay: 300 | ||
- name: fiori-tools-proxy | ||
afterMiddleware: compression | ||
configuration: | ||
ignoreCertError: false # If set to true, certificate errors will be ignored. E.g. self-signed certificates will be accepted | ||
backend: | ||
- path: /V2/Northwind/Northwind.svc | ||
url: https://services.odata.org | ||
destination: northwind | ||
- name: sap-fe-mockserver | ||
beforeMiddleware: csp | ||
configuration: | ||
mountPath: / | ||
services: | ||
- urlPath: /northwind/V2/Northwind/Northwind.svc/ | ||
metadataPath: ./webapp/localService/metadata.xml | ||
mockdataPath: ./webapp/localService/data | ||
generateMockData: true | ||
annotations: [] | ||
- name: fiori-tools-preview | ||
afterMiddleware: fiori-tools-appreload | ||
configuration: | ||
component: ztest.docapp1.ztravel | ||
ui5Theme: sap_horizon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# yaml-language-server: $schema=https://sap.github.io/ui5-tooling/schema/ui5.yaml.json | ||
|
||
specVersion: "3.1" | ||
metadata: | ||
name: ztest.docapp1.ztravel | ||
type: application | ||
server: | ||
customMiddleware: | ||
- name: fiori-tools-proxy | ||
afterMiddleware: compression | ||
configuration: | ||
ignoreCertError: false # If set to true, certificate errors will be ignored. E.g. self-signed certificates will be accepted | ||
ui5: | ||
path: | ||
- /resources | ||
- /test-resources | ||
url: https://ui5.sap.com | ||
backend: | ||
- path: /V2/Northwind/Northwind.svc | ||
url: https://services.odata.org | ||
destination: northwind | ||
- name: fiori-tools-appreload | ||
afterMiddleware: compression | ||
configuration: | ||
port: 35729 | ||
path: webapp | ||
delay: 300 | ||
- name: sap-fe-mockserver | ||
beforeMiddleware: csp | ||
configuration: | ||
mountPath: / | ||
services: | ||
- urlPath: /sap/opu/odata/dmo/UI_TRAVEL_A_D_O2 | ||
metadataPath: ./webapp/localService/metadata.xml | ||
mockdataPath: ./webapp/localService/data | ||
generateMockData: true | ||
annotations: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# yaml-language-server: $schema=https://sap.github.io/ui5-tooling/schema/ui5.yaml.json | ||
|
||
specVersion: "3.1" | ||
metadata: | ||
name: ztest.docapp1.ztravel | ||
type: application | ||
server: | ||
customMiddleware: | ||
- name: fiori-tools-proxy | ||
afterMiddleware: compression | ||
configuration: | ||
ignoreCertError: false # If set to true, certificate errors will be ignored. E.g. self-signed certificates will be accepted | ||
ui5: | ||
path: | ||
- /resources | ||
- /test-resources | ||
url: https://ui5.sap.com | ||
backend: | ||
- path: /V2/Northwind/Northwind.svc | ||
url: https://services.odata.org | ||
destination: northwind | ||
- name: fiori-tools-appreload | ||
afterMiddleware: compression | ||
configuration: | ||
port: 35729 | ||
path: webapp | ||
delay: 300 | ||
- name: fiori-tools-preview | ||
afterMiddleware: fiori-tools-appreload | ||
configuration: | ||
component: ztest.docapp1.ztravel | ||
ui5Theme: sap_horizon | ||
- name: ui5-tooling-modules-middleware | ||
afterMiddleware: compression | ||
configuration: | ||
addToNamespace: true |
Oops, something went wrong.