Skip to content

Commit 41d7da8

Browse files
author
Auke Bruinsma
committed
Initial lean NIM-Script debug framework.
0 parents  commit 41d7da8

File tree

12 files changed

+219
-0
lines changed

12 files changed

+219
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/**/*
2+
out/**/*
3+
config.json

.vscode/launch.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "node",
9+
"request": "launch",
10+
"name": "Launch Program",
11+
"skipFiles": [
12+
"<node_internals>/**"
13+
],
14+
"sourceMaps": true,
15+
"program": "${workspaceFolder}\\out\\src\\main.js",
16+
"outFiles": [
17+
"${workspaceFolder}/**/*.js"
18+
]
19+
}
20+
]
21+
}

.vscode/settings.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"eslint.format.enable": true,
3+
"eslint.codeActionsOnSave.mode": "all",
4+
"editor.tabSize": 2,
5+
"[typescript]": {
6+
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
7+
},
8+
"editor.codeActionsOnSave": {
9+
"source.fixAll.eslint": "explicit",
10+
"source.organizeImports": "explicit"
11+
},
12+
}

.vscode/tasks.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"type": "typescript",
6+
"tsconfig": "tsconfig.json",
7+
"option": "watch",
8+
"problemMatcher": [
9+
"$tsc-watch"
10+
],
11+
"group": {
12+
"kind": "build",
13+
"isDefault": true
14+
},
15+
"label": "Transpile 'Service' on code change"
16+
}
17+
]
18+
19+
}

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# nimScript
2+
3+
nimScript is a node project to test and debug your nim script functions right within Microsoft Visual Code
4+
5+
## Installation
6+
7+
First install [Visual Code](https://code.visualstudio.com/download)
8+
9+
First install the latest 18.x release of [node](https://nodejs.org/en/about/previous-releases#looking-for-latest-release-of-a-version-branch)
10+
11+
Open the project folder in Visual Code and run `npm i`` in a terminal window
12+
13+
```bash
14+
npm i
15+
```
16+
17+
## Usage
18+
19+
Start NIM and download the nim references file, place this nim.ts file in the src directory.
20+
21+
Create a config.json (according to the options in the config.sample.json file)
22+
23+
In the script.ts you can write your own script functions, some examples are provided.
24+
Use the build task to build the output files to be able to debug your code.
25+
Place calls to your script functions inside main.ts
26+
Now run the project to execute the function in main.ts which in turn will execute your script functions.
27+

config.sample.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"serviceHost": "http://localhost:51947",
3+
"serviceUser": "your NIM user name",
4+
"servicePassword": "the password of the above user",
5+
"proxy": {
6+
"host": "localhost",
7+
"port": 8888,
8+
"protocol": "http"
9+
}
10+
}

package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "nimscript",
3+
"version": "1.0",
4+
"description": "nim script example project",
5+
"scripts": {
6+
"build": "tsc --build",
7+
"clean": "tsc --build --clean"
8+
},
9+
"dependencies": {
10+
"axios": "^1.6.2"
11+
},
12+
"devDependencies": {
13+
"@types/axios": "^0.14.0",
14+
"@types/node": "^18.19.3",
15+
"eslint-config-standard-with-typescript": "^43.0.0",
16+
"typescript": "^5.2.2"
17+
}
18+
}

src/main.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
async function run (): Promise<void> {
3+
// Here you can put call your script functions to test them.
4+
}
5+
6+
run().catch((error) => {
7+
console.error(error)
8+
})

src/nim.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// place the generated nim.ts over this file

src/nimHost.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import axios, { type AxiosProxyConfig } from 'axios'
2+
import nimSettings from '../config.json'
3+
4+
export class NimHost {
5+
constructor (private readonly _hostPort: string = '', private readonly _baseUrl: string = '', private readonly userName: string, private readonly passWord: string, private readonly proxy?: AxiosProxyConfig) { }
6+
public async post<T> (httpRequest: string, body: unknown): Promise<T> {
7+
const url = new URL(this._baseUrl + httpRequest, this._hostPort)
8+
const urlString = url.toString()
9+
10+
const proxy = this.proxy
11+
const data = await axios.post<T>(urlString, body, { auth: { username: this.userName, password: this.passWord }, proxy })
12+
return data.data
13+
}
14+
}
15+
16+
export const nimHost: NimHost = new NimHost(nimSettings.serviceHost, '/api/v1/script', nimSettings.serviceUser, nimSettings.servicePassword, nimSettings.proxy ?? undefined)

0 commit comments

Comments
 (0)