Configuration
Proto Codegen is driven by a JSON config file (default: proto-codegen.config.json) and can be overridden with CLI flags.
Full example
json
{
"input": {
"protoDir": "./proto",
"include": ["*.proto"],
"exclude": ["*_test.proto"],
"protoPath": "./proto"
},
"output": {
"dir": "./generated",
"clientsDir": "clients",
"typesDir": "types",
"clean": true
},
"generation": {
"generateTypes": true,
"generateClients": true,
"postProcess": true,
"generateIndex": true
},
"tsProto": {
"options": {
"onlyTypes": true,
"useOptionals": "all",
"stringEnums": false,
"unrecognizedEnum": false,
"snakeToCamel": false,
"outputIndex": true,
"exportCommonSymbols": false,
"esModuleInterop": true
}
},
"client": {
"httpClientInterface": "HttpClient",
"clientSuffix": "Client",
"imports": {
"typesPath": "../types",
"typesSubDir": "",
"httpClientPath": "./http-client"
}
},
"publish": {
"name": "@scope/package-name",
"description": "Package description",
"registry": "https://registry.npmjs.org",
"access": "public",
"betaTag": "beta",
"defaultRegistry": "https://registry.npmjs.org",
"modules": [
{
"name": "module-name",
"scope": "@scope",
"description": "Module description",
"registry": "https://registry.npmjs.org",
"access": "public",
"outDir": "./dist/packages/module-name",
"include": ["*.ts"],
"exclude": [],
"buildTarget": "es2020"
}
]
},
"logging": {
"level": "info",
"verbose": false
}
}Sections
input
Controls which proto files are read.
| Option | Description | Default |
|---|---|---|
protoDir | Proto files directory | ./proto |
include | File patterns to include | ["*.proto"] |
exclude | File patterns to exclude | ["*_test.proto"] |
protoPath | Root path used to calculate relative paths | ./proto |
output
Controls where generated code is written.
| Option | Description | Default |
|---|---|---|
dir | Output directory | ./generated |
clientsDir | Client code subdirectory | clients |
typesDir | Type definitions subdirectory | types |
clean | Clean output directory before generation | true |
generation
Toggles what gets generated.
| Option | Description | Default |
|---|---|---|
generateTypes | Generate type definitions | true |
generateClients | Generate HTTP clients | true |
postProcess | Post-process generated types | true |
generateIndex | Generate entry file | true |
tsProto
Passed through to the ts-proto plugin. See the ts-proto documentation for the full list of options and their behavior.
client
Controls the generated HTTP client layer.
| Option | Description | Default |
|---|---|---|
httpClientInterface | HTTP client interface name | HttpClient |
clientSuffix | Client class name suffix | Client |
imports.typesPath | Types import path | ../types |
imports.typesSubDir | Types subdirectory | `` |
imports.httpClientPath | HTTP client import path | ./http-client |
publish
Multi-module npm publishing configuration.
| Option | Description |
|---|---|
name | Package name to publish |
description | Package description |
registry | NPM registry URL |
access | Access level (public or restricted) |
betaTag | Beta version tag (default beta) |
defaultRegistry | Default registry |
modules | Per-module configuration for publishing multiple packages |
logging
| Option | Description | Default |
|---|---|---|
level | Log level (debug, info, warn, error) | info |
verbose | Enable verbose logging | false |