CLI
Install
sh
npm add -D @grpc.ts/cli @grpc.ts/coresh
pnpm add -D @grpc.ts/cli @grpc.ts/coresh
yarn add -D @grpc.ts/cli @grpc.ts/coreConfigure
ts
// grpc-cli.ts
import type { IConfigProps } from '@grpc.ts/cli';
const config: IConfigProps = {
paths: ['../proto/*.proto'],
external: ['google.protobuf'],
};
export default config;Run Script
sh
npm run gen-grpc-typingsh
pnpm gen-grpc-typingsh
yarn gen-grpc-typingDefault 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.
sh
npm --workspace=my-workspace add -D @data/grpcsh
pnpm --filter=my-workspace add -D @data/grpcsh
yarn workspace my-workspace add -D @data/grpcts
import type {
IExampleService,
ISendMessageRequest,
} from '@data/grpc/example3.interface';