Skip to content

Commit 13ea375

Browse files
authored
Merge pull request #1456 from relu91/cli-enachements
Update CLI implementation with modern tooling and conventions
2 parents 45d3cfb + f63f2f7 commit 13ea375

40 files changed

Lines changed: 1411 additions & 1032 deletions

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ STOPSIGNAL SIGINT
3535
ENTRYPOINT [ "node", "dist/cli.js" ]
3636
CMD [ "-h" ]
3737

38-
## docker build -t wot-servient ./docker/Dockerfile
38+
## docker build -t node-wot ./docker/Dockerfile

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ You can alternatively use node-wot via its command line interface (CLI). Please
118118

119119
#### As global tool
120120

121-
To make the `wot-servient` command available on your machine, install the CLI tool in the global scope:
121+
To make the `node-wot` command available on your machine, install the CLI tool in the global scope:
122122

123123
```
124124
npm i @node-wot/cli -g
@@ -140,16 +140,16 @@ Go into the repository:
140140
cd node-wot
141141
```
142142

143-
Build the Docker image named `wot-servient` from the `Dockerfile`:
143+
Build the Docker image named `node-wot` from the `Dockerfile`:
144144

145145
```
146146
npm run build:docker
147147
```
148148

149-
Run the wot-servient as a container:
149+
Run the `node-wot` as a container:
150150

151151
```
152-
docker run --rm wot-servient -h
152+
docker run --rm node-wot -h
153153
```
154154

155155
## Examples
@@ -252,12 +252,12 @@ Can't find your preferred MediaType? More codecs can be easily added by implemen
252252
Run all the steps above including "Link Packages" and then run this:
253253

254254
```
255-
wot-servient -h
255+
node-wot -h
256256
cd examples/scripts
257-
wot-servient
257+
node-wot
258258
```
259259

260-
Without the "Link Packages" step, the `wot-servient` command is not available and `node` needs to be used (e.g., Windows CMD shell):
260+
Without the "Link Packages" step, the `node-wot` command is not available and `node` needs to be used (e.g., Windows CMD shell):
261261

262262
```
263263
# expose
@@ -277,9 +277,9 @@ First [build the docker image](#as-a-docker-image) and then run the counter exam
277277

278278
```
279279
# expose
280-
docker run -it --init -p 8080:8080/tcp -p 5683:5683/udp -v "$(pwd)"/examples:/srv/examples --rm wot-servient /srv/examples/scripts/counter.js
280+
docker run -it --init -p 8080:8080/tcp -p 5683:5683/udp -v "$(pwd)"/examples:/srv/examples --rm node-wot /srv/examples/scripts/counter.js
281281
# consume
282-
docker run -it --init -v "$(pwd)"/examples:/srv/examples --rm --net=host wot-servient /srv/examples/scripts/counter-client.js --client-only
282+
docker run -it --init -v "$(pwd)"/examples:/srv/examples --rm --net=host node-wot /srv/examples/scripts/counter-client.js --client-only
283283
```
284284

285285
- The counter exposes the HTTP endpoint at 8080/tcp and the CoAP endpoint at 5683/udp and they are bound to the host machine (with `-p 8080:8080/tcp -p 5683:5683/udp`).

package-lock.json

Lines changed: 47 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
}
1515
},
1616
"scripts": {
17-
"build": "tsc -b && npm run build -w packages/browser-bundle",
17+
"build": "npm run build:transform -w packages/cli && tsc -b && npm run build -w packages/browser-bundle",
1818
"pretest": "npm run build",
1919
"start": "cd packages/cli && npm run start",
2020
"debug": "cd packages/cli && npm run debug",
@@ -31,8 +31,8 @@
3131
"prepare": "husky install",
3232
"publish": "npm publish --workspaces",
3333
"check:versions": "node utils/check_package_version_consistency.js",
34-
"build:docker": "docker build -t wot-servient .",
35-
"build:podman": "podman build -t wot-servient .",
34+
"build:docker": "docker build -t node-wot .",
35+
"build:podman": "podman build -t node-wot .",
3636
"clean:dist": "npm exec --workspaces -- npx rimraf tsconfig.tsbuildinfo dist",
3737
"update:wot-typescript-definitions": "npx npm-check-updates -u -f \"wot-typescript-definitions\" --deep",
3838
"link": "npm link -ws",

packages/binding-mqtt/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ Please setup node-wot as described at the [node-wot main page](https://github.co
300300
- example-mqtt-publish.js: Shows when node-wot acts as a MQTT Client that publishes data (latest counter value) to a broker.
301301
At the same time, another client can invoke an action, such as `resetCounter`, by sending a publication message to the topic of this action.
302302
This other client does not have to be node-wot, any MQTT client can interact with this Thing.
303-
For node-wot clients, make sure to provide MQTT broker details (`host`, `port`, `username`, `password`, `clientId`) in the wot-servient.conf.json:
303+
For node-wot clients, make sure to provide MQTT broker details (`host`, `port`, `username`, `password`, `clientId`) in the `node-wot.conf.json`:
304304

305305
```js
306306
{
@@ -315,11 +315,11 @@ Please setup node-wot as described at the [node-wot main page](https://github.co
315315

316316
```
317317

318-
Start the script by the command `wot-servient mqtt-publish.js` or `node ../../packages/cli/dist/cli.js mqtt-publish.js`.
318+
Start the script by the command `node-wot mqtt-publish.js` or `node ../../packages/cli/dist/cli.js mqtt-publish.js`.
319319

320320
- example-mqtt-subscription.js: Shows how node-wot consumes a Thing Description to do MQTT subscription on the provided event (=latest counter value) as well as initiate the action (reset counter).
321321

322-
Start the script by the command `wot-servient -c mqtt-subscribe.js` or `node ../../packages/cli/dist/cli.js -c mqtt-subscribe.js`.
322+
Start the script by the command `node-wot -c mqtt-subscribe.js` or `node ../../packages/cli/dist/cli.js -c mqtt-subscribe.js`.
323323

324324
### More Details
325325

packages/binding-mqtt/src/mqtt-broker-server.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export default class MqttBrokerServer implements ProtocolServer {
6565
private port = -1;
6666
private address?: string = undefined;
6767

68-
private brokerURI: string;
68+
private brokerURI?: string;
6969

7070
private readonly things: Map<string, ExposedThing> = new Map();
7171

@@ -77,15 +77,14 @@ export default class MqttBrokerServer implements ProtocolServer {
7777
private hostedBroker?: net.Server;
7878

7979
constructor(config: MqttBrokerServerConfig) {
80-
this.config = config ?? this.defaults;
81-
this.config.uri = this.config.uri ?? this.defaults.uri;
82-
8380
// if there is a MQTT protocol indicator missing, add this
84-
if (config.uri.indexOf("://") === -1) {
81+
if (config.uri?.indexOf("://") === -1) {
8582
config.uri = this.scheme + "://" + config.uri;
8683
}
8784

8885
this.brokerURI = config.uri;
86+
this.config = config ?? this.defaults;
87+
this.config.uri = this.config.uri ?? this.defaults.uri;
8988
}
9089

9190
public async expose(thing: ExposedThing): Promise<void> {
@@ -446,6 +445,10 @@ export default class MqttBrokerServer implements ProtocolServer {
446445

447446
private async startBroker() {
448447
return new Promise<void>((resolve, reject) => {
448+
if (this.brokerURI == null) {
449+
throw new Error("Unexpected configuration state. Broker was started but brokerURI is null");
450+
}
451+
449452
this.hostedServer = Server({});
450453
let server: tls.Server | net.Server;
451454
if (this.config.key) {

packages/binding-mqtt/src/mqtt.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export interface MqttClientConfig {
5151
}
5252

5353
export interface MqttBrokerServerConfig {
54-
uri: string;
54+
uri?: string;
5555
user?: string;
5656
psw?: string;
5757
clientId?: string;

packages/binding-netconf/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ The Binding example in the `./examples` directory provides a TD (`netconf-thing.
4444
Depending on which NETCONF server is used, the following might have to be changed:
4545

4646
- IP address and port in `examples/netconf-thing.jsonld`
47-
- credentials for the NETCONF Thing (id `urn:dev:wot:org:eclipse:netconf-example`) have to be changed in `wot-servient.conf.json`.
47+
- credentials for the NETCONF Thing (id `urn:dev:wot:org:eclipse:netconf-example`) have to be changed in `node-wot.conf.json`.
4848

4949
## New Form Fields for the NETCONF Binding
5050

@@ -53,7 +53,7 @@ Depending on which NETCONF server is used, the following might have to be change
5353
The href contains: URI schema + IP address + port + XPath
5454

5555
- URI schema: the schema for NETCONF is not registered with IANA; the Binding is using `netconf`.
56-
- IP address and port: IP address and port of the NETCONF server. The credentials for the SSH connection to the server can be added into the `wot-servient.configuration.json`.
56+
- IP address and port: IP address and port of the NETCONF server. The credentials for the SSH connection to the server can be added into the `node-wot.configuration.json`.
5757
- XPath: the XPath of the YANG model node addressed by the given InteractionAffordance. The XPath is automatically converted into the corresponding XML needed by the RPC. If an attribute refers to a particular namespace, an alias can be used. The complete URN for the alias should be added to the **nc:NSs** field.
5858

5959
### nc:target

packages/browser-bundle/web-test-runner.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ async function cleanup() {
169169

170170
function controlTestServient() {
171171
return {
172-
name: "wot-servient",
172+
name: "node-wot",
173173

174174
async executeCommand({ command }) {
175175
switch (command) {

packages/cli/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
src/generated
2+
test/resources

0 commit comments

Comments
 (0)