From 7ed69e386fc8acdbbc7b69c1b2f580e1515ddde5 Mon Sep 17 00:00:00 2001 From: Mark Lee Date: Thu, 4 Apr 2024 09:42:32 -0700 Subject: [PATCH] fix(grpc): don't emit gRPC clients for libraries (#474) * chore: remove special scripts/.tool-versions --- scripts/.tool-versions | 2 -- templates/api/clients/node/src/client-helpers.spec.ts.tpl | 3 +++ templates/api/clients/node/src/client-helpers.ts.tpl | 3 +++ templates/api/clients/node/src/index.ts.tpl | 2 ++ templates/api/clients/ruby/lib/client.rb.tpl | 7 +++---- templates/api/clients/ruby/lib/client/client.rb.tpl | 6 +++++- 6 files changed, 16 insertions(+), 7 deletions(-) delete mode 100644 scripts/.tool-versions diff --git a/scripts/.tool-versions b/scripts/.tool-versions deleted file mode 100644 index 52d1821d..00000000 --- a/scripts/.tool-versions +++ /dev/null @@ -1,2 +0,0 @@ -# needed for CI -golang 1.17.9 diff --git a/templates/api/clients/node/src/client-helpers.spec.ts.tpl b/templates/api/clients/node/src/client-helpers.spec.ts.tpl index f0e08158..8f513112 100644 --- a/templates/api/clients/node/src/client-helpers.spec.ts.tpl +++ b/templates/api/clients/node/src/client-helpers.spec.ts.tpl @@ -1,4 +1,7 @@ {{- $_ := stencil.ApplyTemplate "skipGrpcClient" "node" -}} +{{- if not (stencil.Arg "service") }} +{{- $_ := file.Skip "No client generated for libraries" }} +{{- end }} describe('{{ .Config.Name }} client', () => { it('asserts true # please fill this test in with your own', () => { expect(true).toBeTruthy(); diff --git a/templates/api/clients/node/src/client-helpers.ts.tpl b/templates/api/clients/node/src/client-helpers.ts.tpl index afa82fc4..8174aaf4 100644 --- a/templates/api/clients/node/src/client-helpers.ts.tpl +++ b/templates/api/clients/node/src/client-helpers.ts.tpl @@ -1,4 +1,7 @@ {{- $_ := stencil.ApplyTemplate "skipGrpcClient" "node" -}} +{{- if not (stencil.Arg "service") }} +{{- $_ := file.Skip "No client generated for libraries" }} +{{- end }} import * as grpc from '@grpc/grpc-js'; import { {{ stencil.ApplyTemplate "serviceNameLanguageSafe" }}Client } from './grpc/{{ .Config.Name }}_grpc_pb'; import { createErrorLoggerInterceptor } from '@getoutreach/grpc-client'; diff --git a/templates/api/clients/node/src/index.ts.tpl b/templates/api/clients/node/src/index.ts.tpl index bc02e15a..4c44ef2a 100644 --- a/templates/api/clients/node/src/index.ts.tpl +++ b/templates/api/clients/node/src/index.ts.tpl @@ -1,6 +1,8 @@ {{- $_ := stencil.ApplyTemplate "skipGrpcClient" "node" -}} +{{- if stencil.Arg "service" }} export * as {{ stencil.ApplyTemplate "serviceNameLanguageSafe" }}Types from './grpc/{{ .Config.Name }}_pb'; export * from './client-helpers'; import { {{ stencil.ApplyTemplate "serviceNameLanguageSafe" }}Client } from './grpc/{{ .Config.Name }}_grpc_pb'; export default {{ stencil.ApplyTemplate "serviceNameLanguageSafe" }}Client; +{{- end }} diff --git a/templates/api/clients/ruby/lib/client.rb.tpl b/templates/api/clients/ruby/lib/client.rb.tpl index dbd63491..60b7eca0 100644 --- a/templates/api/clients/ruby/lib/client.rb.tpl +++ b/templates/api/clients/ruby/lib/client.rb.tpl @@ -1,11 +1,10 @@ -# {{ stencil.ApplyTemplate "copyright" }} -{{- if not (has "grpc" (stencil.Arg "serviceActivities")) }} -{{ file.Skip "Not a gRPC service" }} -{{- end }} +# {{ stencil.ApplyTemplate "copyright" }} {{- $_ := file.SetPath (printf "api/clients/ruby/lib/%s_client.rb" .Config.Name) }} {{- $_ := stencil.ApplyTemplate "skipGrpcClient" "ruby" }} require "{{ .Config.Name }}_client/client" require "{{ .Config.Name }}_client/version" +{{- if stencil.Arg "service" }} require "{{ .Config.Name }}_client/{{ .Config.Name }}_pb" require "{{ .Config.Name }}_client/{{ .Config.Name }}_services_pb" +{{- end }} diff --git a/templates/api/clients/ruby/lib/client/client.rb.tpl b/templates/api/clients/ruby/lib/client/client.rb.tpl index 839530bd..80711927 100644 --- a/templates/api/clients/ruby/lib/client/client.rb.tpl +++ b/templates/api/clients/ruby/lib/client/client.rb.tpl @@ -1,14 +1,17 @@ -# {{ stencil.ApplyTemplate "copyright" }} +# {{ stencil.ApplyTemplate "copyright" }} {{- $_ := stencil.ApplyTemplate "skipGrpcClient" "ruby" -}} {{- $_ := file.SetPath (printf "api/clients/ruby/lib/%s_client/%s" .Config.Name (base file.Path)) }} +{{- if stencil.Arg "service" }} require "{{ .Config.Name }}_client/{{ .Config.Name }}_pb" require "{{ .Config.Name }}_client/{{ .Config.Name }}_services_pb" +{{- end }} ## <> {{ file.Block "rubyModuleGlobalSpaceInclusions" }} ## <> +{{- if stencil.Arg "service" }} module {{ title .Config.Name }}Client class Client < {{ title .Config.Name }}::Stub class Interceptor < GRPC::ClientInterceptor @@ -69,3 +72,4 @@ module {{ title .Config.Name }}Client {{ file.Block "rubyModuleExtensions" }} ## <> end +{{- end }}