Skip to content

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.

OptionDescriptionDefault
protoDirProto files directory./proto
includeFile patterns to include["*.proto"]
excludeFile patterns to exclude["*_test.proto"]
protoPathRoot path used to calculate relative paths./proto

output ​

Controls where generated code is written.

OptionDescriptionDefault
dirOutput directory./generated
clientsDirClient code subdirectoryclients
typesDirType definitions subdirectorytypes
cleanClean output directory before generationtrue

generation ​

Toggles what gets generated.

OptionDescriptionDefault
generateTypesGenerate type definitionstrue
generateClientsGenerate HTTP clientstrue
postProcessPost-process generated typestrue
generateIndexGenerate entry filetrue

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.

OptionDescriptionDefault
httpClientInterfaceHTTP client interface nameHttpClient
clientSuffixClient class name suffixClient
imports.typesPathTypes import path../types
imports.typesSubDirTypes subdirectory``
imports.httpClientPathHTTP client import path./http-client

publish ​

Multi-module npm publishing configuration.

OptionDescription
namePackage name to publish
descriptionPackage description
registryNPM registry URL
accessAccess level (public or restricted)
betaTagBeta version tag (default beta)
defaultRegistryDefault registry
modulesPer-module configuration for publishing multiple packages

logging ​

OptionDescriptionDefault
levelLog level (debug, info, warn, error)info
verboseEnable verbose loggingfalse