Continuing with our CAP series using TypeScript, we will build a TypeScript project and deploy it on Cloud Foundry. So far, we have successfully run the application locally.
Part 1- https://community.sap.com/t5/technology-blogs-by-members/exploring-the-typescript-ecosystem-with-cap...
Now, let's add the deployment descriptor and build the project.
Step 1: Add the `mta.yaml` file
cds add mta
it will add the mta.yaml file at the root of your project. In this file, you can define the service and deployer modules. However, I want to draw your attention to an important section called `build-parameters:`. It will look like this:
_schema-version: '3.1'
ID: BookShopTyper
version: 1.0.0
description: "A simple BookShop application using typescript"
parameters:
enable-parallel-deployments: true
build-parameters:
before-all:
- builder: custom
commands:
- npx cds build --production
.......
build the project, run below command.
mbt build
You can see the logs below, and the `.mtar` file has been generated.
[2024-07-19 20:29:22] INFO the build results of the "BookShopTyper-db-deployer" module will be packaged and saved in the "/Users/satyadwivedi/VSCode/BookShopTyper/.BookShopTyper_mta_build_tmp/BookShopTyper-db-deployer" folder
[2024-07-19 20:29:25] INFO finished building the "BookShopTyper-db-deployer" module
[2024-07-19 20:29:25] INFO running the "after-all" build...
[2024-07-19 20:29:25] INFO generating the metadata...
[2024-07-19 20:29:25] INFO generating the "/Users/satyadwivedi/VSCode/BookShopTyper/.BookShopTyper_mta_build_tmp/META-INF/mtad.yaml" file...
[2024-07-19 20:29:25] INFO generating the MTA archive...
[2024-07-19 20:29:26] INFO the MTA archive generated at: /Users/satyadwivedi/VSCode/BookShopTyper/mta_archives/BookShopTyper_1.0.0.mtar
[2024-07-19 20:29:26] INFO cleaning temporary files...
Let's deploy to cloudfoundry.
cf deploy mta_archives/BookShopTyper_1.0.0.mtar
Once the deployment is successful, check the metadata and the exposed entities. Now, test the actions using Postman.
Oops, the implementation is missing. This means that at runtime, the `.ts` files are not running and require `.js` files. Therefore, we need to generate all `.ts` to `.js` files in the gen folder and then deploy.
Let's fix this issue by adjusting the `build-parameters:` section of the `mta.yaml` file as shown below.
_schema-version: '3.1'
ID: BookShopTyper
version: 1.0.0
description: "A simple BookShop application using typescript"
parameters:
enable-parallel-deployments: true
build-parameters:
before-all:
- builder: custom
commands:
- npx cds build --production
- npx @cap-js/cds-typer "*" --outputDirectory gen/srv/@cds-models
- tsc
......
build again.
mbt build
Now, you can see that inside the gen folder, all `.js` files corresponding to each `.ts` file are available.
Deploy to cloudfoundry.
cf deploy mta_archives/BookShopTyper_1.0.0.mtar
now lets test the custome action, and check logs.
This time, we are able to successfully hit the service. That's all.
Check the complete code on GitHub: github repo
Happy Learning!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 29 | |
| 18 | |
| 17 | |
| 15 | |
| 14 | |
| 12 | |
| 11 | |
| 10 | |
| 9 | |
| 8 |