Skip to content

Commit 6f7c74f

Browse files
Add syntax & type check for Node.js example on CI (#4410)
* Add syntax & type check for Node.js example on CI Signed-off-by: Johannes Marbach <[email protected]> * Fix quotes --------- Signed-off-by: Johannes Marbach <[email protected]> Co-authored-by: Florian Duros <[email protected]>
1 parent 3fcc566 commit 6f7c74f

File tree

4 files changed

+65
-15
lines changed

4 files changed

+65
-15
lines changed

.github/workflows/static_analysis.yml

+35
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,41 @@ jobs:
4444
- name: Run Linter
4545
run: "yarn run lint:js"
4646

47+
node_example_lint:
48+
name: "Node.js example"
49+
runs-on: ubuntu-latest
50+
steps:
51+
- uses: actions/checkout@v4
52+
53+
- uses: actions/setup-node@v4
54+
with:
55+
cache: "yarn"
56+
node-version-file: package.json
57+
58+
- name: Install Deps
59+
run: "yarn install"
60+
61+
- name: Build Types
62+
run: "yarn build:types"
63+
64+
- uses: actions/setup-node@v4
65+
with:
66+
cache: "npm"
67+
node-version-file: "examples/node/package.json"
68+
# cache-dependency-path: '**/package-lock.json'
69+
70+
- name: Install Example Deps
71+
run: "npm install"
72+
working-directory: "examples/node"
73+
74+
- name: Check Syntax
75+
run: "node --check app.js"
76+
working-directory: "examples/node"
77+
78+
- name: Typecheck
79+
run: "npx tsc"
80+
working-directory: "examples/node"
81+
4782
workflow_lint:
4883
name: "Workflow Lint"
4984
runs-on: ubuntu-24.04

examples/node/app.js

+9-15
Original file line numberDiff line numberDiff line change
@@ -94,20 +94,14 @@ rl.on("line", function (line) {
9494
);
9595
} else if (line.indexOf("/file ") === 0) {
9696
var filename = line.split(" ")[1].trim();
97-
var stream = fs.createReadStream(filename);
98-
matrixClient
99-
.uploadContent({
100-
stream: stream,
101-
name: filename,
102-
})
103-
.then(function (url) {
104-
var content = {
105-
msgtype: MsgType.File,
106-
body: filename,
107-
url: JSON.parse(url).content_uri,
108-
};
109-
matrixClient.sendMessage(viewingRoom.roomId, content);
97+
let buffer = fs.readFileSync("./your_file_name");
98+
matrixClient.uploadContent(new Blob([buffer])).then(function (response) {
99+
matrixClient.sendMessage(viewingRoom.roomId, {
100+
msgtype: MsgType.File,
101+
body: filename,
102+
url: response.content_uri,
110103
});
104+
});
111105
} else {
112106
matrixClient.sendTextMessage(viewingRoom.roomId, line).finally(function () {
113107
printMessages();
@@ -167,7 +161,7 @@ matrixClient.on(RoomEvent.Timeline, function (event, room, toStartOfTimeline) {
167161
if (toStartOfTimeline) {
168162
return; // don't print paginated results
169163
}
170-
if (!viewingRoom || viewingRoom.roomId !== room.roomId) {
164+
if (!viewingRoom || viewingRoom.roomId !== room?.roomId) {
171165
return; // not viewing a room or viewing the wrong room.
172166
}
173167
printLine(event);
@@ -386,7 +380,7 @@ function print(str, formatter) {
386380
}
387381
console.log.apply(console.log, newArgs);
388382
} else {
389-
console.log.apply(console.log, arguments);
383+
console.log.apply(console.log, [...arguments]);
390384
}
391385
}
392386

examples/node/package.json

+7
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,12 @@
99
"dependencies": {
1010
"cli-color": "^1.0.0",
1111
"matrix-js-sdk": "^34.5.0"
12+
},
13+
"devDependencies": {
14+
"@types/cli-color": "^2.0.6",
15+
"typescript": "^5.6.2"
16+
},
17+
"engines": {
18+
"node": ">=20.0.0"
1219
}
1320
}

examples/node/tsconfig.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es2022",
4+
"module": "commonjs",
5+
"esModuleInterop": true,
6+
"noImplicitAny": false,
7+
"noEmit": true,
8+
"skipLibCheck": true,
9+
"allowJs": true,
10+
"checkJs": true,
11+
"strict": true
12+
},
13+
"include": ["app.js"]
14+
}

0 commit comments

Comments
 (0)