Skip to content

Maven plugin to convert a TypeScript definition file into Java API wrappers

License

Notifications You must be signed in to change notification settings

dukescript/maven-typings-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Maven Typings Plugin

Convert any TypeScript Definition files into Java APIs that can be used everywhere thanks to DukeScript presenters.

Use the benefits of Java language (excellent tooling, strongly typed code, refactorings, etc.) and combine them with the dynamics of JavaScript libraries. Get the best of both worlds!

How can I use the Plugin?

Find your typings file (you can choose any from more than 1500 available in DukeScript Definitely Typed repository) and add following into your pom.xml file:

<plugin>
    <groupId>com.dukescript.libraries</groupId>
    <artifactId>typings-maven-plugin</artifactId>
    <version>0.2</version> <!-- check for the latest! -->
    <executions>
        <execution>
            <id>generate-sources</id>
            <goals>
                <goal>generate</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <typings>path/to/your/typings.d.ts</typings>
        <package>package.to.store.the.files.in</package>
        <!-- optionally -->
        <imports>
            <!-- list other already generated packages you depend on -->
            <import>net.java.html.lib.dom</import>
        </imports>
        <!-- optionally -->
        <scripts>
            <!-- the JavaScript code of the library -->
            <script>path.to.library.js</script>
        </scripts>
    </configuration>
</plugin>

and that is it! The types and functions found in your typings file will be converted into Java classes and you can use them in your own applications.

Alternatively you can contribute your typings Java conversions to everyone as described at DukeScript DefinitelyTyped README.

Are There any Typings Ready?

Yes, the DukeScript project has uploaded Java typings for the most popular JavaScript libraries to Maven. Check the central repository for current status. Visit the DukeScript DefinitelyTyped project for instructions how to use them.

How Does it Work?

There is the Generator class at the heart of the Maven typings plugin. It uses the JDK's scripting engine to start TypeScript parser (converted to JavaScript) and parse the provided typings file. Then it converts the result into Java AST classes generated by @Model annotation. Then the generator visits the tree of AST nodes and based on them generates appropriate Java source files.

The generated code is using @JavaScriptBody annotation which is extremely portable - the generated libraries are known to run in a JavaFX webview, in JDK's Nashorn, in a WebKit component, on Android, iOS and even directly in a browser. Find more info in DukeScript presenters project.

Important part of the project is focus on quality. As such there are focused tests testing various constructs of the TypeScript language and whether they get properly converted into Java. The tests are executed with JUnit Browser Runner which is the most flexible way of running your tests in all supported environments.

License

The plugin is GPLv3 licensed. Contribute to the development of the plugin by forking it on GitHub!

You can use publicly available version of the Maven typings plugin to generate Java typings from any TypeScript typings file and publish the result under any license. For example the DukeScript Definitely Typed libraries are MIT licensed.

About

Maven plugin to convert a TypeScript definition file into Java API wrappers

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages