Skip to content

Commit

Permalink
[docs]: update doc for [email protected]
Browse files Browse the repository at this point in the history
  • Loading branch information
zgid123 committed Jun 2, 2024
1 parent 2f91039 commit dba8be8
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
62 changes: 62 additions & 0 deletions docs/src/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,65 @@ const config: IConfigProps = {

export default config;
```

### monorepo

- Type: `IMonorepoOutputProps`
- Default: `undefined`
- Required: `false`

Monorepo configuration, instead of creating files to the `output` option, CLI will create a workspace to for those files as a mono package inside monorepo project.

This option will override the option `output`.

If `package.json` and `tsconfig.json` already existed, CLI will not touch those files again.

```ts
// grpc-cli.ts

import type { IConfigProps } from '@grpc.ts/cli';

const config: IConfigProps = {
paths: ['../proto/*.proto'],
external: ['google.protobuf'],
monorepo: {
multiEntries: true,
packageName: '@data/grpc',
workspacePath: './packages',
},
};

export default config;
```

#### packageName

- Type: `string`
- Required: `true`

Name of the package, CLI will set to the `name` option of `package.json`.

#### workspacePath

- Type: `string`
- Required `true`

Path of the workspace that is set up for `npm`/`yarn`/`pnpm` workspaces.

#### multiEntries

- Type: `boolean`
- Default: `undefined`
- Required: `false`

If you want to have multi-entries using `package exports`, set this true. Else leave it as it is.

#### compiler

- Type: `ITsupConfigProps`
- Default: `undefined`
- Required: `false`

Set up compiler for the package. Use this option if your project needs to build the mono package before using.

At the moment, only support for `tsup`. Other like `rollup`, ..., you should set up after CLI finishes the setup.
6 changes: 6 additions & 0 deletions docs/src/changelogs.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@

## @grpc.ts/cli

### v1.2.0

- support generate files to a mono package inside monorepo project

**Full Changelog**: https://github.com/zgid123/grpc-ts/compare/%40grpc.ts/cli%401.1.0...%40grpc.ts/cli%401.2.0

### v1.1.0

- rework logic to support nested packages
Expand Down
49 changes: 49 additions & 0 deletions docs/src/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,52 @@ yarn gen-grpc-typing
:::

Default output will be `protobufTypings`. Change `output` option to specify the folder you want to store the typing files.

## Monorepo

In case you are working on a monorepo project and want to share generated typings to all mono projects. From version `1.2.0`, `@grpc.ts/cli` provides a config for this purpose.

```ts
// grpc-cli.ts

import type { IConfigProps } from '@grpc.ts/cli';

const config: IConfigProps = {
paths: ['../proto/*.proto'],
external: ['google.protobuf'],
monorepo: {
multiEntries: true,
packageName: '@data/grpc',
workspacePath: './packages',
},
};

export default config;
```

This will initialize `package.json` and `tsconfig.json` at the path `./packages/@data/grpc`. Also exports multi-entries using `package exports`.

Install the package, import type and use.

::: code-group

```sh [npm]
npm --workspace=my-workspace add -D @data/grpc
```

```sh [pnpm]
pnpm --filter=my-workspace add -D @data/grpc
```

```sh [yarn]
yarn workspace my-workspace add -D @data/grpc
```

:::

```ts
import type {
IExampleService,
ISendMessageRequest,
} from '@data/grpc/example3.interface';
```

0 comments on commit dba8be8

Please sign in to comment.