cincheo / jsweet

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

Transilation of sub maven Projects trough Include Option #408

Open courteous opened 6 years ago

courteous commented 6 years ago

I have two maven projects A and B i.e.

/home/tito/Projects/A/ /home/tito/Projects/B/

A is included as a pom in B and i would like to transpile the B project including all classes from A. If i transpile them separately all works as expected and i get the ts folder where all my POJOs are.

Now I would like to get during the tranpilation of project B all POJO objects from A are simultaneously trasnpiled. If i understand that correctly for that purpose i need to do the include path i.e. example

        <plugin>
            <groupId>org.jsweet</groupId>
            <artifactId>jsweet-maven-plugin</artifactId>
            <version>2.0.1-SNAPSHOT</version>
            <configuration>
                <!-- <workingDir>${project.basedir}</workingDir> -->
                <sourceMap>true</sourceMap>
                <declaration>true</declaration>
                <!-- <tsOut>${project.basedir}/target</tsOut> -->
                <outDir>target/js</outDir>
                <dtsOut>target/ts</dtsOut>
                <verbose>true</verbose>
                <tsOnly>false</tsOnly>
                <!-- <targetVersion>ES5</targetVersion> -->
                <targetVersion>ES6</targetVersion>
                <module>es2015</module>
                <bundle>false</bundle>

                <includes>
                    <include>/home/tito/Projects/B/src/**/*.java</include> 
                </includes>                         

                <excludes>
                    <exclude>**/test/**</exclude>
                </excludes>

                <executions>
                    <execution>
                        <id>generate-js</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>jsweet</goal>
                        </goals>
                    </execution>
                </executions>
            </configuration>
        </plugin>

but when i do that the transpilation does not even start. If i remove the include path then all works well i.e. i get the ts folder without the tests subfolder i.e. the excludes option works correctly. Am i using this feature correctly? How to tell jsweet to automatically tanspile everything that is in subfolder "/home/user/Projects/A" ?

What i would like to get at the end is that i would like to have nice TypeScript import statements like in my project B ts code.

import { ObjectFromA } from './base/ObjectFromA';

is this option not working for me or is this a known/unknown problem?

renaudpawlak commented 6 years ago

@lgrignon is this a Maven plugin problem?

lgrignon commented 6 years ago

This is a good one, thanks, I will take a look asap

lgrignon commented 6 years ago

Well I am sorry to respond this late for such a simple answer but I think you only have to include both projects in your includes in your pom.xml Anyway I am going to push an example on GitHub to confirm this assertion :)

Sorry again for the late reply

lgrignon commented 6 years ago

I took a deeper look at your problem. Actually the glob pattern you specify in the include parameter is relative to the project's source directory (src/main/java by default) so 1) your pattern should include the sources you want to transpile in the current project 2) you cannot use absolute path or ascending relative path (../xxx) in this parameter. We could modify the JSweet maven plugin to allow this but it wouldn't follow the maven spirit.

The preferred approach to deal with referencing an external project is to package this one as a candy. Please find below how to package it. Then you just have to include it as a regular maven dependency in your project. (Don't forget to specify the candiesJsOut option to extract your external project's js & .d.ts files) https://github.com/cincheo/jsweet/blob/master/doc/jsweet-language-specifications.md#packaging-a-jsweet-jar-candy

Please close if it seems ok for you

courteous commented 6 years ago

many thanks for the replay, i will package it and continue with your suggestion.