From 00329984851292fc9c98addb0ca39c771b1e1802 Mon Sep 17 00:00:00 2001 From: ericwenn Date: Wed, 28 Apr 2021 10:28:30 +0200 Subject: [PATCH] feat: add protoc-insertion-point In order for other plugins to generate extra code in the index.ts file protoc_insertion_point can be used. This commit adds one insertion point at the end of the file. From docs: > If non-empty, indicates that the named file should already exist, and the > content here is to be inserted into that file at a defined insertion > point. This feature allows a code generator to extend the output > produced by another code generator. The original generator may provide > insertion points by placing special annotations in the file that look > like: > @@protoc_insertion_point(NAME) --- .../proto/gen/typescript/einride/example/freight/v1/index.ts | 2 ++ .../proto/gen/typescript/einride/example/syntax/v1/index.ts | 2 ++ .../proto/gen/typescript/einride/example/syntax/v2/index.ts | 2 ++ internal/plugin/generate.go | 2 ++ 4 files changed, 8 insertions(+) diff --git a/examples/proto/gen/typescript/einride/example/freight/v1/index.ts b/examples/proto/gen/typescript/einride/example/freight/v1/index.ts index 0c8e254..82c8d01 100644 --- a/examples/proto/gen/typescript/einride/example/freight/v1/index.ts +++ b/examples/proto/gen/typescript/einride/example/freight/v1/index.ts @@ -644,3 +644,5 @@ export function createFreightServiceClient( }, }; } + +// @@protoc_insertion_point(typescript-http-eof) diff --git a/examples/proto/gen/typescript/einride/example/syntax/v1/index.ts b/examples/proto/gen/typescript/einride/example/syntax/v1/index.ts index 0cc7f77..98f6284 100644 --- a/examples/proto/gen/typescript/einride/example/syntax/v1/index.ts +++ b/examples/proto/gen/typescript/einride/example/syntax/v1/index.ts @@ -400,3 +400,5 @@ export function createSyntaxServiceClient( }, }; } + +// @@protoc_insertion_point(typescript-http-eof) diff --git a/examples/proto/gen/typescript/einride/example/syntax/v2/index.ts b/examples/proto/gen/typescript/einride/example/syntax/v2/index.ts index 731bf6e..51f42a9 100644 --- a/examples/proto/gen/typescript/einride/example/syntax/v2/index.ts +++ b/examples/proto/gen/typescript/einride/example/syntax/v2/index.ts @@ -251,3 +251,5 @@ export type einrideexamplesyntaxv1_Message_NestedMessage = { export type einrideexamplesyntaxv1_Message_NestedEnum = // NESTEDENUM_UNSPECIFIED "NESTEDENUM_UNSPECIFIED"; + +// @@protoc_insertion_point(typescript-http-eof) diff --git a/internal/plugin/generate.go b/internal/plugin/generate.go index 76afc5c..e4d6a72 100644 --- a/internal/plugin/generate.go +++ b/internal/plugin/generate.go @@ -40,6 +40,8 @@ func Generate(request *pluginpb.CodeGeneratorRequest) (*pluginpb.CodeGeneratorRe if err := (packageGenerator{pkg: pkg, files: files}).Generate(&index); err != nil { return nil, fmt.Errorf("generate package '%s': %w", pkg, err) } + index.P() + index.P("// @@protoc_insertion_point(typescript-http-eof)") res.File = append(res.File, &pluginpb.CodeGeneratorResponse_File{ Name: proto.String(path.Join(indexPathElems...)), Content: proto.String(string(index.Content())),