Skip to content

Commit

Permalink
fill README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
manland committed Jan 13, 2017
1 parent 0153acb commit 10e6874
Showing 1 changed file with 82 additions and 2 deletions.
84 changes: 82 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

> A simple java to ts generator, designed for DTO.
* [Install](#install)
* [Js Api](#js-api)
* [CLI](#cli)
* [Example](#example)
* [Development](#development)
* [Contribution](#contribution)

## Install

> npm install j2ts
Expand Down Expand Up @@ -34,12 +41,85 @@ After install, add a script in your `package.json` :
}
```

To see all options run `j2ts --help`
And run `npm run j2ts`. To see all options run `j2ts --help`

## Example

If you start with User java class :

```java
package dto;

public class User {

private String username;
private Integer stats;

public User() {
}

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public Integer getStats() {
return stats;
}

public void setStats(Integer stats) {
this.stats = stats;
}
}
```

You compile it with java :

> javac "dto/User.java"
Pass `dto/User.class` through `j2ts` :

> j2ts -f "./dto/*.class" -d "./dto"
You will obtain `dto/User.ts` :

```ts
export interface User {

username: string;

stats: number;

}
```

And an `index.ts` containing a reference to all exported members :

```ts
export * from './User';
```

Now you can use it in your project when you request user from server :

```ts
import {User} from './dto';

fetch('myserver/user/1').then((user: User) => ...);
```

Test it against all your big, fat and complicated dto in real projects ;) And please, open issues if something goes wrong.

## Development

> clone
> npm install
> npm run test
## Contribution

This repository ❤ pull-request ;)
This repository ❤ pull-request ;) Make sure no one else work on same feature by opening an issue!

0 comments on commit 10e6874

Please sign in to comment.