Skip to content

Commit

Permalink
Add the plugin option add_pb_suffix adds the suffix _pb to all fi…
Browse files Browse the repository at this point in the history
…le names, see #186
  • Loading branch information
timostamm committed Jan 3, 2022
1 parent ea11acf commit 5e07925
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
New features:

- Add the plugin option `ts_nocheck` to support most strict compiler options in userspace, see #152.
- The new plugin option `add_pb_suffix` adds the suffix `_pb` to all file names, see #186.


### v2.1.0
Expand Down
4 changes: 4 additions & 0 deletions MANUAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ Available plugin options:
Generate a @ts-nocheck annotation at the top of each file. This will become the
default behaviour in the next major release.

- "add_pb_suffix"
Adds the suffix `_pb` to the names of all generated files. This will become the
default behaviour in the next major release.

- "client_none"
Do not generate rpc clients.
Only applies to services that do *not* use the option `ts.client`.
Expand Down
8 changes: 6 additions & 2 deletions packages/plugin/src/protobufts-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ export class ProtobuftsPlugin extends PluginBase<OutFile> {
"the default behaviour, this option has no effect.",
excludes: ['ts_nocheck'],
},
add_pb_suffix: {
description: "Adds the suffix `_pb` to the names of all generated files. This will become the \n" +
"default behaviour in the next major release.",
},

// client
client_none: {
Expand Down Expand Up @@ -195,11 +199,11 @@ export class ProtobuftsPlugin extends PluginBase<OutFile> {

// ensure unique file names
for (let fileDescriptor of registry.allFiles()) {
const base = fileDescriptor.name!.replace('.proto', '');
const base = fileDescriptor.name!.replace('.proto', '') + (params.add_pb_suffix ? "_pb" : "");
fileTable.register(base + '.ts', fileDescriptor);
}
for (let fileDescriptor of registry.allFiles()) {
const base = fileDescriptor.name!.replace('.proto', '');
const base = fileDescriptor.name!.replace('.proto', '') + (params.add_pb_suffix ? "_pb" : "");
fileTable.register(base + '.server.ts', fileDescriptor, 'generic-server');
fileTable.register(base + '.grpc-server.ts', fileDescriptor, 'grpc1-server');
fileTable.register(base + '.client.ts', fileDescriptor, 'client');
Expand Down

0 comments on commit 5e07925

Please sign in to comment.