Closed mueller-jens closed 4 years ago
Not at this point as far as I know. I guess it could be fairly doable by wrapping moment.js. What would be missing so that one can contribute and get started on this project?
(Link to the original issue: https://github.com/j4ts/j4ts/issues/57)
Thanks for the answer @renaudpawlak . For starting contribute I miss some basics on how this library works, where the right point to add it (jsweet, jtds, a candy). Also I am unsure if wrapping moment is the right way or using the js-joda library is a better way.
You are right. I was discussing with @lgrignon about the fact that a quickstart/howto to create a new J4TS lib would be extremely useful. I don't have any opportunity to find the time right now but I will discuss it with Louis. In the meantime, I have pushed my last (unfinished) work as is in the j4ts-time repo. It is 6 years old, so I am not sure it is a significant start (it does not compile) but I guess it is better than nothing.
In order to wrap a JS library in a J4TS project, just do it the very same way as in a regular JSweet project (i.e. add a reference to the candy, or if the candy does not exist, just create a def
package and place the JS lib API definitions there).
I have hastily created an empty j4ts-quickstart project where we can write a first example and some documentation to get started. https://github.com/j4ts/j4ts-quickstart
Hope this will help. I should be able to guide, but difficult for me to actively participate for now on.
@renaudpawlak Thanks for the information. I will try to start with it and it is hopefully ok if i come back to you if i have any question.
Sorry but I can't get it work. If i use your example replace the Calendar classes by java.time.LocalDateTime
and try to transpile it with jdk 1.8 i get the error message:
org.jsweet:jsweet-maven-plugin:1.2.0-SNAPSHOT:jsweet failed: A required class was missing while executing org.jsweet:jsweet-maven-plugin:1.2.0-SNAPSHOT:jsweet: com/sun/tools/javac/util/Context
if i try to use the actual versions of jsweet and jtds I get a lot of errors starting with
package exists in another module: java.base at D:\tools\git\j4ts-time\src\main\java\java\time\LocalDateTime.java(62)
And i do not know how i came over it.
Could you please try with 2.3.7?
@lgrignon Thanks for the suggestion. I tried it and saw that i use a java8 jre not a jdk. Thahs why i got the missing com/sun/tools/javac/util/Context
Is tools.jar included in pom.xml?
I switched to a jdk now the bild works and i try to understand what i have to change in the class to map LocalDateTime and the other classes to th js-jods library. But it is very hard for me.
Well done @mueller-jens ! What's your newest problem then? Let's try to fix them one by one :)
Did you take a look at other similar projects, such as: https://github.com/j4ts/j4ts-awtgeom
I try to find out how to add js-joda as dependency and how to map the java API to the js API.
I may be wrong but you do not need to add js-joda (JS version) as a dependency. You can add it in your webapp as a runtime dependency. However, you need the "type declarations" for JSweet. Simplest way to achieve it is to write only what you need in a def.xxx package. For instance, define in your project a def.jsjoda package, and then declare the classes / methods / functions you need from js-joda. (More info here) Example:
@Interface
public abstract class JsJodaClass {
public native void jsJodaMethod();
}
Ok Thanks @lgrignon . I will try it. Can you give me an example for a test class for this?
@lgrignon I have pushed my first try to my repository: https://github.com/mueller-jens/j4ts-time But i get some compile errors. I am not do familar with typescript so I can not find out what is wrong. Can you assist me? I think there is something worng with inheritence and the mapping of static functions. Thanks and Best regards Jens
Are there any plans to support java.time API in the transpiler?