Skip to content

Commit

Permalink
chore: 0.1.10
Browse files Browse the repository at this point in the history
  • Loading branch information
TbhT committed Jul 13, 2024
1 parent 224bcd8 commit 04eaa68
Show file tree
Hide file tree
Showing 5 changed files with 2,607 additions and 3,287 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/onRelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
run: npm install pnpm -g

- run: pnpm install
- uses: JS-DevTools/npm-publish@19c28f1ef146469e409470805ea4279d47c3d35c
- run: pnpm run build
- uses: JS-DevTools/npm-publish@v3
with:
token: ${{ secrets.NPM_TOKEN }}
14 changes: 7 additions & 7 deletions README-ZH.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
@tbht/thrift-cli
@olierjs/thrift-cli
=================

generate typescript code from thrift files


[![oclif](https://img.shields.io/badge/cli-oclif-brightgreen.svg)](https://oclif.io)
[![Version](https://img.shields.io/npm/v/@tbht/thrift-cli.svg)](https://npmjs.org/package/@tbht/thrift-cli)
[![Downloads/week](https://img.shields.io/npm/dw/@tbht/thrift-cli.svg)](https://npmjs.org/package/@tbht/thrift-cli)

[![Version](https://img.shields.io/npm/v/@olierjs/thrift-cli.svg)](https://npmjs.org/package/@olierjs/thrift-cli)
[![Downloads/week](https://img.shields.io/npm/dw/@olierjs/thrift-cli.svg)](https://npmjs.org/package/@olierjs/thrift-cli)


<!-- toc -->
* [Usage](#usage)
* [Commands](#commands)
<!-- tocstop -->
# Usage
<!-- usage -->
```sh-session
$ npm install -g @tbht/thrift-cli
$ npm install -g @olierjs/thrift-cli
$ thrift-cli COMMAND
running command...
$ thrift-cli (--version)
@tbht/thrift-cli/0.0.0 darwin-arm64 node-v18.19.0
@olierjs/thrift-cli/0.0.0 darwin-arm64 node-v18.19.0
$ thrift-cli --help [COMMAND]
USAGE
$ thrift-cli COMMAND
Expand All @@ -29,7 +29,7 @@ USAGE
<!-- usagestop -->
# Commands
<!-- commands -->
- [@tbht/thrift-cli](#tbhtthrift-cli)
- [@olierjs/thrift-cli](#tbhtthrift-cli)
- [Usage](#usage)
- [Commands](#commands)
- [`thrift-cli hello PERSON`](#thrift-cli-hello-person)
Expand Down
64 changes: 47 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,72 @@
# thrift-cli ⚡

---
[![oclif](https://img.shields.io/badge/cli-oclif-brightgreen.svg)](https://oclif.io)
[![Version](https://img.shields.io/npm/v/@olierjs/thrift-cli.svg)](https://npmjs.org/package/@olierjs/thrift-cli)
[![Downloads/week](https://img.shields.io/npm/dw/@olierjs/thrift-cli.svg)](https://npmjs.org/package/@olierjs/thrift-cli)

> A tool to help developers use Thrift for __BFF__ (Backend for Frontend) development, reducing manual boilerplate code.
- 💡 Generates boilerplate code based on the Thrift IDL, including `ts-types`, `validator`, and `mock` code.

<!-- tocstop -->
# Usage

<!-- usagestop -->
```sh-session
$ npm install -g @olierjs/thrift-cli
$ thrift-cli COMMAND
running command...
$ thrift-cli (--version)
@olierjs/thrift-cli/0.1.9 darwin-arm64 node-v18.19.0
$ thrift-cli --help [COMMAND]
USAGE
$ thrift-cli COMMAND
...
```

# Commands

## `thrift-cli help [COMMAND]`

Display help for thrift-cli

```shell

USAGE
$ thrift-cli help [COMMAND...] [-n]

ARGUMENTS
COMMAND... Command to show help for.

FLAGS
-n, --nested-commands Include all nested commands in the output.

DESCRIPTION
Display help for thrift-cli.

```

## Features
# Features

The `thrift-cli` scaffolding tool converts the Thrift IDL to corresponding TypeScript (TS) code. It currently generates the following types of code:

- **ts types**
- __ts types__

Converts the Thrift file to TypeScript types and request code for browser usage.
- **validator**
- __validator__

Converts the Thrift file to request validation schemas defined in the `service`. Supported schema options include `Joi`, `Zod`, and `class-validator`.

- **mock**
- __mock__

Generates TypeScript code that corresponds to the structure of the Thrift file.

- **controller (experimental)**
- __controller (experimental)__

The generated code needs to be used in the appropriate positions of the controller, such as validator schemas that need to be used at the entry point of requests and TypeScript types that need to be imported in requests and responses.
The generated code needs to be used in the appropriate positions of the controller, such as validator schemas that need to be used at the entry point of requests and TypeScript types that need to be imported in requests and responses.

The mock data also needs to be imported in the returned interface or places required by the frontend. The controller provides configurations to import these generated code into the controller.


## IDL Config Options

### Core Configuration
Expand Down Expand Up @@ -183,12 +221,10 @@ interface TSPluginOptions {
}
```


### Validator Plugin Configuration

This section mainly covers the configuration of the plugin responsible for generating validator schema code. Currently, there are three supported validation code generators:


- [Joi](https://joi.dev/)

- [Zod](https://zod.dev/)
Expand Down Expand Up @@ -260,7 +296,6 @@ service S {

The resulting TypeScript code, which can be directly imported when using the corresponding type, will be as follows. More annotations will be added in the future:


```typescript
import { faker } from '@faker-js/faker';

Expand Down Expand Up @@ -298,16 +333,12 @@ interface MockPluginOptions {

The generation of mock code depends on fakerjs to generate mock data. Mock code is essentially a combination of the API provided by fakerjs with the corresponding structure in the IDL.



| annotation key | annotation value | meaning | example |
|:--------------:|:-----------------|:------------------------------------------------------------------------------------------|----------|
| :------------: | :--------------- | :---------------------------------------------------------------------------------------- | -------- |
| `mock` or `m` | any string | Indicates the mock code used for the current field. Currently, only fakerjs is supported. | see blow |


- Examples of mock-related IDL:


```thrift
typedef i64 Int64 (mock="typedef should not work")
Expand Down Expand Up @@ -341,7 +372,6 @@ struct MockStructWithAnnotation {

- Example of generated mock code:


```typescript

import { faker } from "@faker-js/faker";
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@olierjs/thrift-cli",
"description": "generate typescript code from thrift files",
"version": "0.1.9",
"version": "0.1.10",
"author": "TbhT",
"bin": {
"thrift-cli": "bin/run.js"
Expand Down Expand Up @@ -60,8 +60,7 @@
"dirname": "thrift-cli",
"commands": "./dist/commands",
"plugins": [
"@oclif/plugin-help",
"@oclif/plugin-plugins"
"@oclif/plugin-help"
],
"topicSeparator": " ",
"topics": {
Expand All @@ -85,6 +84,7 @@
"prepack": "oclif manifest && oclif readme",
"test": "mocha --forbid-only \"test/**/*.test.ts\"",
"version": "oclif readme && git add README.md",
"prepublish": "pnpm run build"
"prepublish": "pnpm run build",
"publish": "npm publish"
}
}
Loading

0 comments on commit 04eaa68

Please sign in to comment.