Giter VIP home page Giter VIP logo

java-ts-definition-generator's Introduction

Java typescript definition generator

This is the typescript definition generator for the java-bridge package. It generates typescript definitions for java classes and interfaces.

It can either be invoked from the command line or used as a library.

Installation

Note: You need to install java-bridge separately

npm install -g java-ts-definition-generator java-bridge

Command line usage

java-ts-gen <output> <classnames..>

Positionals:
  classnames  The fully qualified class name(s) to convert              [string]
  output      The output file                                           [string]

Options:
  --help             Show help                                         [boolean]
  --version          Show version number                               [boolean]
  --classpath, --cp  The classpath to use                               [string]

Notes

  • The classpath argument can be supplied multiple times to add multiple jars to the classpath
  • Multiple class names can be supplied to generate definitions for multiple classes
  • The generated typescript files will automatically import all classes once the module is loaded.

Examples

Generate definitions for a single class

Generate definitions for the java.lang.String class and all its referenced classes and save them to ./project:

java-ts-gen ./project java.lang.String

This will create a directory called java containing the definitions for the java.lang.String class and all its dependencies all inside subdirectories. The java.lang.String class will be saved to ./project/java/lang/String.ts. Thus, the folder structure of project will look something like this:

.
├── ...
├── java
│   ├── lang
│   │   ├── String.ts
│   │   ├── Object.ts
│   │   └── ...
│   ├── util
│   │   └── ...
│   └── ...
└── ...

Generate definitions for multiple classes

Generate definitions for the java.lang.String and java.util.ArrayList classes and all of their dependencies and save them to ./project:

java-ts-gen ./project java.lang.String java.util.ArrayList

Library usage

import { TypescriptDefinitionGenerator } from 'java-ts-definition-generator';

const generator = new TypescriptDefinitionGenerator('java.lang.String');
// Generate the typescript definitions
const definitions = await generator.generate();

// Save the definitions to a directory
await TypescriptDefinitionGenerator.save(definitions, './project');

Generate definitions for multiple classes

const generator = new TypescriptBulkDefinitionGenerator();

// Generate definitions for the provided modules
await generator.generate([
    'java.lang.String',
    'java.util.List',
    'java.util.Map',
    'java.io.FileOutputStream',
    'java.io.FileInputStream',
    'java.io.File',
    'java.lang.System',
]);

// Save the definitions to a directory
await generator.save('javaDefinitions');

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.