Skip to content

Commit

Permalink
fix: change templates to work for oats
Browse files Browse the repository at this point in the history
  • Loading branch information
Jared Allard committed Apr 28, 2022
1 parent a6f9ecb commit 04de967
Show file tree
Hide file tree
Showing 41 changed files with 101 additions and 6 deletions.
3 changes: 3 additions & 0 deletions templates/.air.toml.tpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{{- if not (has "library" (stencil.Arg "type")) }}
{{ file.Skip "Application is a library" }}
{{- end }}
# Config file for [Air](https://github.com/cosmtrek/air) in TOML format

# Working directory
Expand Down
3 changes: 3 additions & 0 deletions templates/.clang-format.tpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{{- if not (has "library" (stencil.Arg "type")) }}
{{ file.Skip "Application is a library" }}
{{- end }}
---
Language: Proto
BasedOnStyle: google
Expand Down
3 changes: 3 additions & 0 deletions templates/.dockerignore.tpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{{- if not (has "library" (stencil.Arg "type")) }}
{{ file.Skip "Application is a library" }}
{{- end }}
.git/

# Node modules
Expand Down
12 changes: 12 additions & 0 deletions templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@
{{- regexReplaceAll "\\W+" .Config.Name "_" }}
{{- end }}

# Skips the current file if a node client shouldn't be generated
# {{- $_ := stencil.ApplyTemplate "skipGrpcClient" "node" -}}
{{- define "skipGrpcClient" }}
{{- $grpcClient := . }}
{{- $serviceTypes := (stencil.Arg "type") }}
{{- $grpcClients := (stencil.Arg "grpcClients") }}
{{- if not (and (has "grpc" $serviceTypes) (has "node" $grpcClients)) }}
{{ file.Skip "Not a gRPC service, or node client not specified in grpcClients" }}
{{ file.Delete }}
{{- end }}
{{- end }}

# Returns the copyright string
{{- define "copyright" }}
{{- printf "Copyright %s Outreach Corporation. All Rights Reserved." (stencil.ApplyTemplate "currentYear") }}
Expand Down
5 changes: 5 additions & 0 deletions templates/api/api.go.tpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{{- if not (has "grpc" (stencil.Arg "type")) }}
{{- file.Skip "Not a gRPC service" }}
{{- end }}
{{- $_ := file.SetPath (printf "api/%s.go" .Config.Name) }}
{{- $_ := file.Static }}
// {{ stencil.ApplyTemplate "copyright" }}

// Description: This file defines the gRPC server service interface for
Expand Down
4 changes: 4 additions & 0 deletions templates/api/api.proto.tpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{{- if not (has "grpc" (stencil.Arg "type")) }}
{{- file.Skip "Not a gRPC service" }}
{{- end }}
{{- $_ := file.SetPath (printf "api/%s.proto" .Config.Name) }}
{{- $_ := file.Static }}
// {{ stencil.ApplyTemplate "copyright" }}
// Please modify this to match the interface specified in {{ .Config.Name }}.go
Expand Down
1 change: 1 addition & 0 deletions templates/api/clients/node/.eslintrc.js.tpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- $_ := stencil.ApplyTemplate "skipGrpcClient" "node" }}
module.exports = {
extends: ['@outreach/eslint-config/node', 'plugin:jsdoc/recommended'],
plugins: ['jsdoc', '@typescript-eslint'],
Expand Down
1 change: 1 addition & 0 deletions templates/api/clients/node/.gitignore.tpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- $_ := stencil.ApplyTemplate "skipGrpcClient" "node" -}}
# Logs
logs
*.log
Expand Down
1 change: 1 addition & 0 deletions templates/api/clients/node/.npmignore.tpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- $_ := stencil.ApplyTemplate "skipGrpcClient" "node" -}}
# Logs
logs
*.log
Expand Down
1 change: 1 addition & 0 deletions templates/api/clients/node/.prettierignore.tpl
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
{{- $_ := stencil.ApplyTemplate "skipGrpcClient" "node" -}}
src/grpc
5 changes: 4 additions & 1 deletion templates/api/clients/node/.tool-versions.tpl
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
nodejs {{ .Config.Versions.nodejs }}
# Contains asdf versions for a node.js gRPC client.
{{- $_ := stencil.ApplyTemplate "skipGrpcClient" "node" -}}
{{- /* TODO(jaredallard): We need a better solution for versions */}}
nodejs 14.17.6
1 change: 1 addition & 0 deletions templates/api/clients/node/README.md.tpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- $_ := stencil.ApplyTemplate "skipGrpcClient" "node" -}}
# `@outreach/{{ .Config.Name }}-client`

This is a Node.js gRPC client for the `{{ .Config.Name }}` service.
Expand Down
1 change: 1 addition & 0 deletions templates/api/clients/node/bootstrap.js.tpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- $_ := stencil.ApplyTemplate "skipGrpcClient" "node" -}}
const tsConfig = require('./tsconfig.json');
const tsConfigPaths = require('tsconfig-paths');

Expand Down
1 change: 1 addition & 0 deletions templates/api/clients/node/doc.go.tpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- $_ := stencil.ApplyTemplate "skipGrpcClient" "node" -}}
// {{ stencil.ApplyTemplate "copyright" }}

// Description: This file just serves as a doc for the client package.
Expand Down
1 change: 1 addition & 0 deletions templates/api/clients/node/generate.go.tpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- $_ := stencil.ApplyTemplate "skipGrpcClient" "node" -}}
// {{ stencil.ApplyTemplate "copyright" }}

// Description: This file generates the node gRPC client using a gogenerate directive.
Expand Down
1 change: 1 addition & 0 deletions templates/api/clients/node/jest.config.js.tpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- $_ := stencil.ApplyTemplate "skipGrpcClient" "node" -}}
module.exports = {
collectCoverage: true,
collectCoverageFrom: ['**/src/**'],
Expand Down
1 change: 1 addition & 0 deletions templates/api/clients/node/package.hjson.tpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- $_ := stencil.ApplyTemplate "skipGrpcClient" "node" -}}
{
// This file is not automatically turned into package.json
// In order to do so, run: `make gogenerate` in the root
Expand Down
1 change: 1 addition & 0 deletions templates/api/clients/node/scripts/copy-definitions.js.tpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- $_ := stencil.ApplyTemplate "skipGrpcClient" "node" -}}
const { build } = require('@outreach/grpc-client');
const path = require('path');

Expand Down
1 change: 1 addition & 0 deletions templates/api/clients/node/src/client-helpers.spec.ts.tpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- $_ := stencil.ApplyTemplate "skipGrpcClient" "node" -}}
describe('{{ .Config.Name }} client', () => {
it('asserts true # please fill this test in with your own', () => {
expect(true).toBeTruthy();
Expand Down
1 change: 1 addition & 0 deletions templates/api/clients/node/src/client-helpers.ts.tpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- $_ := stencil.ApplyTemplate "skipGrpcClient" "node" -}}
import * as grpc from '@grpc/grpc-js';
import { {{ title .Config.Name }}Client } from './grpc/{{ .Config.Name }}_grpc_pb';
import { createAuthenticationInterceptor, createErrorLoggerInterceptor } from '@outreach/grpc-client';
Expand Down
1 change: 1 addition & 0 deletions templates/api/clients/node/src/index.ts.tpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- $_ := stencil.ApplyTemplate "skipGrpcClient" "node" -}}
export * as {{ title .Config.Name }}Types from './grpc/{{ .Config.Name }}_pb';
export * from './client-helpers';

Expand Down
1 change: 1 addition & 0 deletions templates/api/clients/node/tsconfig.json.tpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- $_ := stencil.ApplyTemplate "skipGrpcClient" "node" -}}
{
"compilerOptions": {
"module": "commonjs",
Expand Down
1 change: 1 addition & 0 deletions templates/api/clients/node/tsconfig.production.json.tpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- $_ := stencil.ApplyTemplate "skipGrpcClient" "node" -}}
{
"extends": "./tsconfig.json",
"exclude": ["node_modules", "codegen-templates", "**/*.spec.ts", "**/spec.ts"]
Expand Down
8 changes: 6 additions & 2 deletions templates/api/clients/ruby/.tool-versions.tpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
ruby {{ .Config.Versions.ruby }}
# Contains asdf versions for a ruby gRPC client.
{{- $_ := stencil.ApplyTemplate "skipGrpcClient" "ruby" -}}
ruby 2.6.6
###Block(rubyToolVersions)
{{ file.Block "rubyToolVersions" }}
{{- if file.Block "rubyToolVersions" }}
{{ file.Block "rubyToolVersions" | stencil.Render "ruby" }}
{{- end }}
###EndBlock(rubyToolVersions)
1 change: 1 addition & 0 deletions templates/api/clients/ruby/Gemfile.lock.tpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- $_ := stencil.ApplyTemplate "skipGrpcClient" "ruby" -}}
PATH
remote: .
specs:
Expand Down
1 change: 1 addition & 0 deletions templates/api/clients/ruby/Gemfile.tpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- $_ := stencil.ApplyTemplate "skipGrpcClient" "ruby" -}}
source 'https://rubygems.org'

# Declare your gem's dependencies in github_stats.gemspec.
Expand Down
1 change: 1 addition & 0 deletions templates/api/clients/ruby/Rakefile.tpl
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
{{- $_ := stencil.ApplyTemplate "skipGrpcClient" "ruby" -}}
require "bundler/gem_tasks"
3 changes: 2 additions & 1 deletion templates/api/clients/ruby/client.gemspec.tpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- $_ := stencil.ApplyTemplate "skipGrpcClient" "ruby" -}}
require_relative 'lib/{{ .Config.Name }}_client/version'

Gem::Specification.new do |spec|
Expand All @@ -10,7 +11,7 @@ Gem::Specification.new do |spec|
spec.metadata["source_code_uri"] = spec.homepage
spec.metadata["github_repo"] = "ssh://github.com/getoutreach/{{ .Config.Name }}"

spec.required_ruby_version = Gem::Requirement.new(">= {{ .Config.Versions.ruby }}")
spec.required_ruby_version = Gem::Requirement.new(">= 2.6.6")
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
end
Expand Down
6 changes: 6 additions & 0 deletions templates/api/clients/ruby/lib/client.rb.tpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# {{ stencil.ApplyTemplate "copyright" }}
{{- if not (has "grpc" (stencil.Arg "type")) }}
{{ file.Skip "Not a gRPC service" }}
{{- end }}
{{- $_ := file.SetPath (printf "api/clients/ruby/lib/%s_client.rb" .Config.Name) }}

require "{{ .Config.Name }}_client/client"
require "{{ .Config.Name }}_client/version"
require "{{ .Config.Name }}_client/{{ .Config.Name }}_pb"
Expand Down
4 changes: 4 additions & 0 deletions templates/api/clients/ruby/lib/client/client.rb.tpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# {{ stencil.ApplyTemplate "copyright" }}
{{- $_ := stencil.ApplyTemplate "skipGrpcClient" "ruby" -}}
{{- $_ := file.SetPath (printf "api/clients/ruby/lib/%s_client/%s" .Config.Name (base file.Path)) }}

require "{{ .Config.Name }}_client/{{ .Config.Name }}_pb"
require "{{ .Config.Name }}_client/{{ .Config.Name }}_services_pb"

Expand Down
4 changes: 4 additions & 0 deletions templates/api/clients/ruby/lib/client/version.rb.tpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# {{ stencil.ApplyTemplate "copyright" }}
{{- $_ := stencil.ApplyTemplate "skipGrpcClient" "ruby" }}
{{- $_ := file.SetPath (printf "api/clients/ruby/lib/%s_client/%s" .Config.Name (base file.Path)) }}
{{- $_ := file.Static }}
module {{ title .Config.Name }}Client
VERSION = "1.0.0"
end
3 changes: 3 additions & 0 deletions templates/api/doc.go.tpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{{- if not (has "grpc" (stencil.Arg "type")) }}
{{- file.Skip "Not a gRPC service" }}
{{- end }}
// {{ stencil.ApplyTemplate "copyright" }}

// Description: This file serves as package documentation for the api
Expand Down
5 changes: 5 additions & 0 deletions templates/api/rpc/client.go.tpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{{- if not (has "grpc" (stencil.Arg "type")) }}
{{- file.Skip "Not a gRPC service" }}
{{- end }}
{{- $_ := file.SetPath (printf "api/%s/%s" .Config.Name (base file.Path)) }}
{{- $_ := file.Static }}
// {{ stencil.ApplyTemplate "copyright" }}

// Description: This file contains the gRPC client implementation for the
Expand Down
4 changes: 4 additions & 0 deletions templates/api/rpc/doc.go.tpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{{- if not (has "grpc" (stencil.Arg "type")) }}
{{- file.Skip "Not a gRPC service" }}
{{- end }}
{{- $_ := file.SetPath (printf "api/%s/%s" .Config.Name (base file.Path)) }}
// {{ stencil.ApplyTemplate "copyright" }}

// Description: This file contains the package documentation for the gRPC
Expand Down
4 changes: 4 additions & 0 deletions templates/api/rpc/test_client.go.tpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{{- if not (has "grpc" (stencil.Arg "type")) }}
{{- file.Skip "Not a gRPC service" }}
{{- end }}
{{- $_ := file.SetPath (printf "api/%s/%s" .Config.Name (base file.Path)) }}
// {{ stencil.ApplyTemplate "copyright" }}

// Description: This file contains test for the gRPC client for {{ .Config.Name }} service.
Expand Down
3 changes: 3 additions & 0 deletions templates/api/rpc_helpers.go.tpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{{- if not (has "grpc" (stencil.Arg "type")) }}
{{- file.Skip "Not a gRPC service" }}
{{- end }}
// {{ stencil.ApplyTemplate "copyright" }}

// Package api is a helper package which defines the ping API
Expand Down
2 changes: 1 addition & 1 deletion templates/cmd/main_cli.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{{- define "main-cli" }}
// {{ stencil.ApplyTemplate "copyright" }}

// Description: This file is the entrypoint for the {{ .Config.Name }} CLI
// Description: This file is the entrypoint for the {{ .cmdName }} CLI
// command for {{ .Config.Name }}.
// Managed: true

Expand Down
3 changes: 3 additions & 0 deletions templates/devspace.yaml.tpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{{- if not (has "library" (stencil.Arg "type")) }}
{{ file.Skip "Application is a library" }}
{{- end }}
version: v1beta11

# `vars` specifies variables which may be used as ${VAR_NAME} in devspace.yaml
Expand Down
1 change: 1 addition & 0 deletions templates/internal/appName/rpc/example_test.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{{ file.Skip "Not a gRPC service" }}
{{- end }}
{{- $_ := file.SetPath (printf "internal/%s/%s" .Config.Name (base file.Path)) }}
{{- $_ := file.Static }}
// {{ stencil.ApplyTemplate "copyright" }}

// go:build or_int
Expand Down
1 change: 1 addition & 0 deletions templates/internal/appName/rpc/server.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{{ file.Skip "Not a gRPC service" }}
{{- end }}
{{- $_ := file.SetPath (printf "internal/%s/%s" .Config.Name (base file.Path)) }}
{{- $_ := file.Static }}
// {{ stencil.ApplyTemplate "copyright" }}

// Description: This file contains the gRPC server implementation for the {{ .Config.Name }}
Expand Down
2 changes: 1 addition & 1 deletion templates/internal/appName/rpctest/suite.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

// go:build or_int

// Package {{ .Config.Name }}test implements the test suite for the {{ .Config.Name }} service.
// Package {{ stencil.ApplyTemplate "goPackageSafeName" }}test implements the test suite for the {{ .Config.Name }} service.
package {{ stencil.ApplyTemplate "goPackageSafeName" }}test //nolint:revive // Why: We allow [-_].


Expand Down

0 comments on commit 04de967

Please sign in to comment.