cincheo / jsweet

A Java to JavaScript transpiler.
http://www.jsweet.org
Other
1.46k stars 160 forks source link

Bridging a local js file #556

Closed c4bade6fdec3d9cb86a281668cbab42b closed 4 years ago

c4bade6fdec3d9cb86a281668cbab42b commented 4 years ago

Hello, I took a look at this repo https://github.com/cincheo/jsweet-candy-js-quickstart as a reference to package my own candy

Now I see sprintf gets pulled in from bower...

My question is how would I go about doing this with gradle (I already got jsweet working with gradle) and with a local js file ?

Thanks

lgrignon commented 4 years ago

Hello @aXZhbg, Thanks for your interest in JSweet. This repo uses JSweet 1, which is kind of old. Did you take a look at the candy generator project? https://github.com/cincheo/jsweet/tree/develop/candy-generator You can find information on how to package candy here: https://github.com/cincheo/jsweet/blob/master/doc/jsweet-language-specifications.md#packaging-a-jsweet-jar-candy

Basically you would need to write (or generate) your JSweet definitions, package it as a Jar and deploy it using Maven or Gradle, and then include it in your host project as a dependency. Your JS source file can be either 1) included in your candy 2) included manually in your host project 3) generated by your candy build process (ie pure JSweet candies can generate valid JS files)

You have several examples of working candies here: https://github.com/jsweet-candies/

lgrignon commented 4 years ago

I keep it opened for a while in case you have more questions. Please close if you have all the info you need for this specific matter.

c4bade6fdec3d9cb86a281668cbab42b commented 4 years ago

Hey - thanks for the response and for keeping this issue open

I already managed to create a test candy that just alerts a string, however I still have some doubts so I hope you can at least give me an advice on what I'm trying to achieve.

So what I'm trying to achieve is package a library from npm thats not available as a candy already. I want to be able to have a Java project that includes this as a candy does some logic in java and then transpile everything into Javascript and then bundle it all and minify into 1 file using webpack again to be served by backend.

Now there are 2 issues I've encountered:

  1. My project structure is as follows: ~/main-project - this is where i keep my main app, thing is in this root directory theres a package.json with node_modules directory and then there is a nested directory ~/main-project/nested-jsweet-project, nested jsweet project has its own gradle and package json, the issue is however that if i run gradle jsweet command in nested project - ~/main-project/nested-jsweet-project ./gradlew run jsweet , it will pick up on node_modules from main project - so one level above, and it will throw errors, so i had to include a bash script into gradle task to remove node modules from root dir before doing jsweet, this is a temporary workaround i think this is a bug

  2. second issue i have is that when jsweet transpiles java into javascript it doesnt bundle dependencies of candy into the main.js, ive tried adding in various options but it just doesnt, and the solution is again to create a bash script that after transpiling puts them into one dir which will be picked up by webpack, bundled and minified - this i also feel is a workaround

I hope i have made my issues easy to read and understand and that you have some advices to give me to streamline this process im trying to create

If you have any questions please ask

Thank you !

c4bade6fdec3d9cb86a281668cbab42b commented 4 years ago

bump

lgrignon commented 4 years ago

Which version of JSweet are you using.please?

c4bade6fdec3d9cb86a281668cbab42b commented 4 years ago

jsweet core 6.0.2 jsweet transpiler 2.3.0

lgrignon commented 4 years ago

Thanks, it should be fine (even if I recommend the last 2.3.x for JSweet)

1) Well that's a good one. JSweet is supposed to take its node_modules from userdir. Why don't you put JSweet source in your main project? Did you try changing a bit your project structure to have project/ Java Sources JSweet Sources

2) there is a bundle option for jsweet-maven-plugin which should work. I guess you already tried, maybe some other option is conflicting. Could you please post here your pom.xml with your not working bundle option?

I had to answer this in a rush, sorry, but please tell me what's your status about all of this. Bye

c4bade6fdec3d9cb86a281668cbab42b commented 4 years ago

ive let this sit a bit and decided in the end that i did not want to do this feature since i would be making it hard for myself

what i wanted to do was use couple of js libraries that i would have to bridge myself, write logic in java and then again transpile everything to js again

so i just decided to go the route of just writing it in js and serving the script by backend

thanks for help anyway