Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: update documentation about generating JS examples #1348

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/quickstart/presence-sensor.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*
* SPDX-License-Identifier: EPL-2.0 OR W3C-20150513
********************************************************************************/
Object.defineProperty(exports, "__esModule", { value: true });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be there (according to the tests that I did in the past), I'll double-check locally to understand why it generates this line now.

// This is an example Thing script which is a simple presence detector
// It fires an event when it detects a person (mocked as every 5 second)
const core_1 = require("@node-wot/core");
Expand Down
1 change: 1 addition & 0 deletions examples/quickstart/simple-coffee-machine.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*
* SPDX-License-Identifier: EPL-2.0 OR W3C-20150513
********************************************************************************/
Object.defineProperty(exports, "__esModule", { value: true });
// This is an example Thing script which is a simple coffee machine.
// You can order coffee and see the status of the resources
const core_1 = require("@node-wot/core");
Expand Down
3 changes: 2 additions & 1 deletion examples/quickstart/smart-clock.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
*
* SPDX-License-Identifier: EPL-2.0 OR W3C-20150513
********************************************************************************/
Object.defineProperty(exports, "__esModule", { value: true });
// This is an example Thing which is a smart clock that runs 60 times faster than real time, where 1 hour happens in 1 minute.
const core_1 = require("@node-wot/core");
const binding_coap_1 = require("@node-wot/binding-coap");
// create Servient add CoAP binding with port configuration
const servient = new core_1.Servient();
servient.addServer(new binding_coap_1.CoapServer(5686));
servient.addServer(new binding_coap_1.CoapServer({ port: 5686 }));
core_1.Helpers.setStaticAddress("plugfest.thingweb.io"); // comment this out if you are testing locally
let minuteCounter = 0;
let hourCounter = 0;
Expand Down
4 changes: 2 additions & 2 deletions examples/scripts/countdown.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";
/********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2021 Contributors to the Eclipse Foundation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These license changes are ok? should we maybe update the ones coming from TS ? are they good?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that also, but I think we should not bother too much. I think updating according to TS files is fine...

*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand All @@ -12,7 +13,6 @@
*
* SPDX-License-Identifier: EPL-2.0 OR W3C-20150513
********************************************************************************/

function uuidv4() {
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
const r = (Math.random() * 16) | 0;
Expand Down
2 changes: 1 addition & 1 deletion examples/scripts/counter-client.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"use strict";
/********************************************************************************
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
Expand All @@ -12,7 +13,6 @@
*
* SPDX-License-Identifier: EPL-2.0 OR W3C-20150513
********************************************************************************/

function getFormIndexForDecrementWithCoAP(thing) {
const forms = thing.getThingDescription().actions?.decrement.forms;
if (forms !== undefined) {
Expand Down
4 changes: 2 additions & 2 deletions examples/scripts/counter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";
/********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand All @@ -12,7 +13,6 @@
*
* SPDX-License-Identifier: EPL-2.0 OR W3C-20150513
********************************************************************************/

// This is an example Thing script.
// It has a count property that can be incremented or decremented via actions and its changes are reported via events.
// It also has two properties that return an image. The SVG property is also influenced by the increment and decrement actions.
Expand Down
3 changes: 2 additions & 1 deletion examples/scripts/smart-coffee-machine-client.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";
/********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down
3 changes: 2 additions & 1 deletion examples/scripts/smart-coffee-machine.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";
/********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down
3 changes: 2 additions & 1 deletion examples/security/oauth/consumer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";
/********************************************************************************
* Copyright (c) 2023 Contributors to the Eclipse Foundation
* Copyright (c) 2018 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down
4 changes: 3 additions & 1 deletion examples/security/oauth/exposer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";
/********************************************************************************
* Copyright (c) 2018 - 2020 Contributors to the Eclipse Foundation
* Copyright (c) 2018 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand All @@ -12,6 +13,7 @@
*
* SPDX-License-Identifier: EPL-2.0 OR W3C-20150513
********************************************************************************/
Object.defineProperty(exports, "__esModule", { value: true });
const td = {
"@context": "https://www.w3.org/2019/wot/td/v1",
title: "OAuth",
Expand Down
4 changes: 2 additions & 2 deletions examples/testthing/testclient.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";
/********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand All @@ -12,7 +13,6 @@
*
* SPDX-License-Identifier: EPL-2.0 OR W3C-20150513
********************************************************************************/

console.log = () => {
/* empty */
};
Expand Down
3 changes: 2 additions & 1 deletion examples/testthing/testthing.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";
/********************************************************************************
* Copyright (c) 2023 Contributors to the Eclipse Foundation
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down
30 changes: 11 additions & 19 deletions packages/examples/README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,25 @@
# node-wot Examples

## Script Examples
## Examples

Script examples are located in
Examples are located in

- `src\scripts`
- `src\testthing`
- `src\scripts`
- `src\testthing`
- ...

The idea of these folders is to use TypeScript to work on the examples which offers support in being up-to-date with the current API.

see https://github.com/eclipse-thingweb/node-wot/issues/171.

### Workflow
## Workflow for generating JS examples

1. Run `npm run build`
2. Remove the following 3/4 lines in JS files of folder `dist/`

```
Object.defineProperty(exports, "__esModule", { value: true });
require("wot-typescript-definitions");
let WoT;
let WoTHelpers;
```
2. Copy the according JS file(s) from `<node-wot>/packages/examples/dist` to

3. Copy the according JS file(s) to
- `<node-wot>/examples/scripts`
- `<node-wot>/examples/testthing`
- ...

- `<node-wot>/examples/scripts`
- `<node-wot>/examples/testthing`

## Test Thing

Test thing and client is located in `src\testthing`.
3. Run `npm run format`
Loading