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

(Partially) Automate generating examples from TypeScript to JavaScript #178

Merged
merged 20 commits into from
Mar 2, 2020

Conversation

danielpeintner
Copy link
Member

I started a test PR for issue #171.

The idea is to have a package examples where we can use TypeScript to create examples and we are sure that the syntax and the API usages are correct.

To be able to run it as JavaScript with the CLI one needs to copy the code between

// --> BEGIN CODE for scripts

and

// <-- END CODE for scripts

to the scripts folder (e.g., danielpeintner@fe19c76) so that the CLI can properly run it.

This is not ideal but I think doing so at least there is a guarantee that the code fits the API and the syntax is correct.

Any opinions?

Note: I also wonder whether the package demo-servients should be combined.

@egekorkan
Copy link
Member

I would support this PR and also combining demo-servients. I don't understand however the following:

// --> BEGIN CODE for scripts

and

// <-- END CODE for scripts

@danielpeintner
Copy link
Member Author

The reason for begin/end is that one needs to manually copy the code between the 2 markers to scripts in https://github.com/eclipse/thingweb.node-wot/tree/master/examples/scripts (as I also did in this PR for the counter.js example).
This test also showed that we were using thing.title incorrectly and should rather use thing.getThingDescription().title instead.

The package uses TS while the scripts folder is meant to be used for CLI environment.

@egekorkan do you have a better approach. I am all open!

@danielpeintner
Copy link
Member Author

danielpeintner commented Feb 27, 2020

The recent update simplifies the process/workflow

Workflow

  1. Run npm run build
  2. Remove 3/4 lines in JS files of folder dist/
  3. Copy the file(s) to <node-wot>/examples/

On improvements or automatic scripts can be worked on later.

@danielpeintner danielpeintner changed the title [WIP] Examples (Partially) Automate generating examples from TypeScript to JavaScript Feb 27, 2020
@danielpeintner
Copy link
Member Author

I asked @sebastiankb for review.

@egekorkan If you can check as well would be great!

I think this PR contains NOW all changes I wanted to work on.

  • TS counterpart for each JS script
  • half automatic generation of JS scripts
  • all JS scripts are in sync now with the latest Scripting API

Remaining future topics:

  • fully automate TS to JS conversion

### Workflow

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

Choose a reason for hiding this comment

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

I'm not sure what I have to do here? 3/4 lines (do you mean 3-4 lines)?

Copy link
Member Author

Choose a reason for hiding this comment

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

the tsc command creates the 3/4 lines mentioned below which at the moment need to be removed manually. In the future we should have an automates travis script


## Test Thing

Test thing and client is located in `src\testthing`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the test thing related to the example? or is this a generic test thing?

Copy link
Member Author

Choose a reason for hiding this comment

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

The TestThing is developed in TypeScript in the example package. The result is copied to the examples folder so that people don't need to build/run node-wot but instead have a JavaScript file that can be used right away.

@danielpeintner danielpeintner mentioned this pull request Mar 2, 2020
@sebastiankb
Copy link
Contributor

Thanks @danielpeintner for clarification and for this PR. This will improve the quality of node-wot and its examples. Let's merge

@danielpeintner danielpeintner merged commit 7814b9c into master Mar 2, 2020
@egekorkan
Copy link
Member

Couldn't be sure where to put this information but instead of doing this removal of 3-4 lines in Travis, I think it would be better to have a postbuild script that gets triggered by npm once the npm run build is finished. This way, it would be easier to develop new examples and not need to push them to GitHub to trigger the Travis script. However, it must be made sure that this script runs on WIndows and Linux systems, which probably means a node.js script

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants