Skip to content

Commit

Permalink
0.2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
PuffMeow committed Aug 10, 2023
1 parent 2f6a50b commit 2d0313d
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 39 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ jobs:
- host: windows-latest
build: yarn build
target: x86_64-pc-windows-msvc
- host: windows-latest
build: |
yarn build --target i686-pc-windows-msvc
yarn test
target: i686-pc-windows-msvc
- host: ubuntu-latest
target: x86_64-unknown-linux-gnu
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian
Expand Down Expand Up @@ -64,6 +69,16 @@ jobs:
build: |
yarn build --target armv7-unknown-linux-gnueabihf
arm-linux-gnueabihf-strip *.node
- host: ubuntu-latest
target: aarch64-linux-android
build: |
yarn build --target aarch64-linux-android
${ANDROID_NDK_LATEST_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip *.node
- host: ubuntu-latest
target: armv7-linux-androideabi
build: |
yarn build --target armv7-linux-androideabi
${ANDROID_NDK_LATEST_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip *.node
- host: ubuntu-latest
target: aarch64-unknown-linux-musl
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine
Expand Down Expand Up @@ -189,6 +204,43 @@ jobs:
name: bindings-freebsd
path: ${{ env.APP_NAME }}.*.node
if-no-files-found: error
test-macOS-windows-binding:
name: Test bindings on ${{ matrix.settings.target }} - node@${{ matrix.node }}
needs:
- build
strategy:
fail-fast: false
matrix:
settings:
- host: macos-latest
target: x86_64-apple-darwin
- host: windows-latest
target: x86_64-pc-windows-msvc
node:
- '14'
- '16'
- '18'
runs-on: ${{ matrix.settings.host }}
steps:
- uses: actions/checkout@v3
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
check-latest: true
cache: yarn
- name: Install dependencies
run: yarn install
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: bindings-${{ matrix.settings.target }}
path: .
- name: List packages
run: ls -R .
shell: bash
- name: Test bindings
run: yarn test
test-linux-x64-gnu-binding:
name: Test bindings on Linux-x64-gnu - node@${{ matrix.node }}
needs:
Expand Down
62 changes: 24 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
## Introduce
## Introduction

This is a tool that can help you transform your JSON Schema to TypeScript interface quickly🧲.

It's written by Rust(napi-rs) and only support in Node.js(Support for all platforms except Android).
It's written by Rust(napi-rs) and only support in Node.js.

If you want the same feature that can work in Browser or all other platforms, you can see [schema2ts](https://github.com/PuffMeow/schema2ts).

Git repository: [rusty-schema2ts](https://github.com/PuffMeow/rusty-schema2ts). If you like it, please give me a little star♥

__The api of them are all the same.__
**The api of them are all the same.**

## TypeScript vs Rust

Expand All @@ -19,22 +19,6 @@ You can find [benchmark here](https://github.com/PuffMeow/rusty-schema2ts/blob/m
| 0 | TypeScript: schema2ts | 2,796 | 357534.31021794415 | ±1.08% | 1399 |
| 1 | Rust: rustySchema2ts | 5,431 | 184122.05448994122 | ±0.29% | 2716 |

## Support matrix

| | node12 | node14 | node16 | node18 |
| ---------------------------- | ------ | ------ | ------ | ------ |
| Windows x64 |||||
| Windows x32 |||||
| Windows arm64 |||||
| macOS x64 |||||
| macOS arm64 (m chips) |||||
| Linux x64 gnu (glibc 2.17) |||||
| Linux x64 musl |||||
| Linux arm gnu (glibc 2.17) |||||
| Linux arm64 gnu (glibc 2.17) |||||
| Linux arm64 musl |||||
| FreeBSD x64 |||||

## Install

npm
Expand Down Expand Up @@ -67,10 +51,27 @@ import { schema2ts } from "@puffmeow/rusty-schema2ts";
schema2ts(`your schema`, options);
```

If you have a schema like this:
## Options

| key | type | required | default | description |
| ----------------- | -------- | -------- | ------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| preffix | string | × | I | Interface preffix, if you don't like this, you can give it a empty string |
| preffixOfEnum | string | × | T | Enum type preffix, if you don't like this, you can give it a empty string |
| isGenComment | boolean | × | false | Whether to automatically generate comments |
| isExport | boolean | × | true | Whether to export the interfaces and types |
| indent | number | × | 2 | Code indent |
| semi | boolean | × | true | Is enable semicolon |
| optional | boolean | × | true | If this is enabled, it will generate the optional interface, default value is true |
| ignoreKeys | string[] | × | [] | If you don't want to generate the type of an attribute in a root object, you can pass in the key name of the corresponding attribute.<br /><br />Like this, ignoreKeys: ["firstName", "lastName"]<br /><br />Schema2ts will ignore the two attributes and doesn't generate the type of them. |
| explain | string | × | | Display some comments at the top of the code |
| parseErrorMessage | string | × | // Parse schema error, please check your schema. | When parsing schema error, this message will be return |

## Example:

### Input schema

If you have a schema like this:

```json
{
"title": "Schema",
Expand Down Expand Up @@ -158,7 +159,7 @@ If you have a schema like this:

Finally it will output like this:

```ts
````ts
export type THairColor = "color1" | "color2" | "color3";

export interface ISchema {
Expand Down Expand Up @@ -188,30 +189,15 @@ export interface IArr3 {
enen3?: boolean;
enen4?: any;
}
```

## Options

| key | type | required | default | description |
| ----------------- | -------- | -------- | ------------------------------------------------ | ------------------------------------------------------------ |
| preffix | string | × | I | Interface preffix, if you don't like this, you can give it a empty string |
| preffixOfEnum | string | × | T | Enum type preffix, if you don't like this, you can give it a empty string |
| isGenComment | boolean | × | false | Whether to automatically generate comments |
| isExport | boolean | × | true | Whether to export the interfaces and types |
| indent | number | × | 2 | Code indent |
| semi | boolean | × | true | Is enable semicolon |
| optional | boolean | × | true | If this is enabled, it will generate the optional interface, default value is true |
| ignoreKeys | string[] | × | [] | If you don't want to generate the type of an attribute in a root object, you can pass in the key name of the corresponding attribute.<br /><br />Like this, ignoreKeys: ["firstName", "lastName"]<br /><br />Schema2ts will ignore the two attributes and doesn't generate the type of them. |
| explain | string | × | | Display some comments at the top of the code |
| parseErrorMessage | string | × | // Parse schema error, please check your schema. | When parsing schema error, this message will be return |
``` |
## More examples
### 1.generate comment
```ts
schema2ts(`below json`, { isGenComment: true });
```
````

#### input json

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@puffmeow/rusty-schema2ts",
"version": "0.2.3",
"version": "0.2.4",
"main": "index.js",
"types": "index.d.ts",
"files": [
Expand Down

0 comments on commit 2d0313d

Please sign in to comment.