crossecore / crossecore-generator

Code generator for Java, C#, TypeScript and Swift
Apache License 2.0
12 stars 8 forks source link

Running the code in node.js #13

Closed TheRittler closed 3 years ago

TheRittler commented 4 years ago

Hi together,

is there a way of running the generated code in node.js? I am especially interested in transpiling the code to JS (e.g. with tsc) and then use it. In the end, the code will be used in a web app. (Written in Kotlin, transpiled to JS)

schwichti commented 4 years ago

is there a way of running the generated code in node.js?

Yes. CrossEcore's TypeScript runtime is 100% pure TypeScript and has zero dependencies on other npm packages. There is only one slight restriction I can think of at the moment. When you are loading XMI models via XmiResource, you have to pass a DomParser in the constructor. I can barely remember, but I think you can use dom-parser for that in a node environment. You also might have to adjust the generated tsconfig.json.

In the end, the code will be used in a web app. (Written in Kotlin, transpiled to JS)

I do not fully understand what you are going to do: Why are you asking whether "the code runs in node.js" when "the code will be used in a web app"? What is your target platform? node.js or (browser/mobile webview/Cordova/Ionic)?

Written in Kotlin, transpiled to JS

As far as I know, you can use Java libraries from Kotlin. I wonder if you can include the original EMF Java API in your Kotlin code and transpile the whole thing to JS (without CrossEcore in the loop). Have you considered this?

schwichti commented 4 years ago

I found out that CrossEcore TypeScirpt release 0.1.1. uses AMD modules that are not supported by nodejs. I think in the next release I might change that to UMD modules so that the code will run in nodejs and web browsers.

TheRittler commented 4 years ago

I do not fully understand what you are going to do: Why are you asking whether "the code runs in node.js" when "the code will be used in a web app"? What is your target platform? node.js or (browser/mobile webview/Cordova/Ionic)?

The target platform is web, I was just thinking that the code is currently also usable from node, so I tried some stuff in node. Releasing crossecore as UMD might be helpful!

schwichti commented 4 years ago

I think I will use ES5 modules instead of UMD modules. ES6 modules are standardized and are supported by modern web browsers and node.js

TheRittler commented 4 years ago

When will it be released?

schwichti commented 4 years ago

I have created a new branch es6-modules. Until it is released you can check out this branch and then run the following commands:

cd ecore-typescript
npm install
npm run build
npm link
cd your-app
npm link crossecore