Skip to content

Commit 3d23d61

Browse files
committed
Improve Model SDK tutorial
1 parent ba373f4 commit 3d23d61

2 files changed

Lines changed: 34 additions & 40 deletions

File tree

content/en/docs/apidocs-mxsdk/mxsdk/sdk-howtos/creating-your-first-script.md

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,24 +92,20 @@ Once you are done with the model changes, you can flush the changes to make sure
9292

9393
## Compiling and Running the Script
9494

95-
1. Compile the script with the TypeScript compiler into JavaScript using the following command:
95+
1. Add the following section to `package.json`
9696

97-
```bash
98-
$ tsc
97+
```json
98+
"scripts": {
99+
"start": "tsc && node script.js"
100+
}
99101
```
100102

101-
A file named `script.js` should appear (or, if you named the original TypeScript file for example, `app.ts`, then it would be named `app.js`.
102-
103-
The TypeScript compiler will execute in a single run to compile all files configured in *tsconfig.json*. While developing your script, it can be practical to have the compiler immediately run once you make changes to your code. Use the `--watch` flag for `tsc` to monitor the files configured in the *tsconfig.json* file for changes and immediately run the compiler when you save the file:
104-
105-
```bash
106-
$ tsc --watch
107-
```
103+
This command will first compile your TypeScript code into JavaScript using the TypeScript compiler. After compilation, a file named `script.js` will be generated. The script will then be executed using Node.js.
108104

109-
2. Run the script with `node` to see the results:
105+
2. Run the script to see the results:
110106

111107
```text
112-
$ node script.js
108+
$ npm run start
113109
Creating new app 'NewApp-1637595970665'...
114110
Successfully created app with id '64760e41-9507-42d3-99da-3950454dd40a'
115111
Creating temporary working copy for branch 'main'...

content/en/docs/apidocs-mxsdk/mxsdk/sdk-howtos/setting-up-your-development-environment.md

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ Set up a new `node` project and install the dependencies using the following ste
1919
$ mkdir my-app-generator
2020
$ cd my-app-generator
2121
$ npm init --yes
22-
$ npm install -g typescript
2322
$ npm install mendixmodelsdk mendixplatformsdk --save
24-
$ tsc --init --target es2020
23+
$ npm install typescript@~4.6.2 @types/node@~22.0.3 --save-dev
2524
```
25+
You can now proceed directly to step 6 in the detailed instructions to configure TypeScript.
2626

2727
## Setting Up Your Development Tools {#setting}
2828

@@ -34,28 +34,15 @@ To set up your development tools, follow these steps:
3434

3535
```bash
3636
$ node --version
37-
v18.20.8
37+
v22.15.0
3838
```
3939

4040
For Debian-based Linux distributions such as Ubuntu, please refer to [NodeSource Node.js Binary Distributions](https://github.com/nodesource/distributions#user-content-installation-instructions) to properly set up your apt-get sources.
4141

4242
In the rest of the how-tos, in blocks such as the above, lines starting with a `$` represent commands to type into a terminal. Sometimes a line follows without a $, represents output of the command.
4343

4444
3. Install [Visual Studio Code](https://code.visualstudio.com/) (not to be confused with Visual Studio), a text editor/IDE with good support for [TypeScript](https://www.typescriptlang.org/). Make sure you have a recent version (v1.11.0+); check the version you are using through Help > About when you have Code opened.
45-
4. Install TypeScript 4.6.2 or higher with [`npm`](https://www.npmjs.com/) (or [`yarn`](https://yarnpkg.com/)), Node.js's package manager:
4645

47-
```bash
48-
$ npm install -g typescript
49-
```
50-
51-
5. Use the following command to check the TypeScript compiler version on your PATH:
52-
53-
```bash
54-
$ tsc --version
55-
Version 4.6.2 (or higher)
56-
```
57-
58-
If the version number is much lower, it could be that you also have an outdated TypeScript SDK on your system, left over from a previous installation. You can either uninstall the old TypeScript SDK, or bypass it by removing the old TypeScript SDK from your system's PATH environment variable.
5946

6047
## Setting Up a Working Directory for Your Script
6148

@@ -82,33 +69,44 @@ To set up a working directory for your script, follow these steps:
8269

8370
```json
8471
"dependencies": {
85-
"mendixmodelsdk": "^4.56.0",
86-
"mendixplatformsdk": "^5.0.0"
72+
"mendixmodelsdk": "^4.102.0",
73+
"mendixplatformsdk": "^5.2.0"
8774
}
8875
```
8976

9077
When a new major version of the Mendix SDK is released (as in, 1.0.0 to 2.0.0) and you run `npm update` in your project folder, the `^` in front of the version number makes sure that the installed version of the SDK will not be upgraded automatically. Only minor and patch releases (as in, 1.1.1) of the SDK will be automatically upgraded; otherwise, your script could inadvertently be broken. You may, of course, edit the dependency by hand yourself.
9178

92-
4. Save your changes and then execute the following to install the dependencies:
79+
4. Add `typescript`, and `@types/node` as dev dependencies.
80+
Packages like TypeScript, testing libraries, linters, and type definitions (@types/...) are not required for your app to run in production—they're only needed while writing and testing code.
81+
82+
```json
83+
"devDependencies": {
84+
"typescript": "~4.6.2",
85+
"@types/node": "~22.0.3"
86+
}
87+
```
88+
89+
5. Save your changes and then execute the following to install the dependencies:
9390
9491
```bash
9592
$ npm install
9693
```
9794
9895
If you are using version control, make sure to ignore the `node_modules` directory, otherwise you end up committing dependencies.
9996
100-
5. In Code, create a [tsconfig.json](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html) file next to your *package.json*. The *tsconfig.json* file is used by the TypeScript compiler to compile your code in the proper manner to a JS file. Create it with the following contents.
97+
6. In Code, create a [tsconfig.json](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html) file next to your *package.json*. The *tsconfig.json* file is used by the TypeScript compiler to compile your code in the proper manner to a JS file. Create it with the following contents.
10198
10299
```json
103100
{
104-
"compilerOptions" : {
105-
"module" : "commonjs",
106-
"target" : "es2020",
107-
"strict": true
108-
},
109-
"files" : [
110-
"script.ts"
111-
]
101+
"compilerOptions": {
102+
"target": "es2020",
103+
"module": "commonjs",
104+
"esModuleInterop": true,
105+
"forceConsistentCasingInFileNames": true,
106+
"strict": true,
107+
"skipLibCheck": true
108+
},
109+
"files": ["script.ts"]
112110
}
113111
```
114112

0 commit comments

Comments
 (0)