Skip to content

Commit 97522a4

Browse files
authored
update Makefile and README template (#95)
1 parent 2d0e190 commit 97522a4

3 files changed

Lines changed: 74 additions & 31 deletions

File tree

Makefile

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
VERSION ?= $(shell date +"%Y%m%d")
22
OUTPUT_DIR := _output
3+
ROOT_DIR := $(shell pwd)
34

45
.PHONY: typegen
56
typegen:
@@ -9,10 +10,32 @@ typegen:
910
format:
1011
gofmt -w -s .
1112

12-
.PHONY: test
13-
test:
13+
14+
.PHONY: test-sdk
15+
test-sdk:
1416
go test -v -race -timeout 3m ./...
1517

18+
.PHONY: test-hasura-ndc-go
19+
test-hasura-ndc-go:
20+
cd cmd/hasura-ndc-go && \
21+
go test -v -race ./...
22+
23+
.PHONY: test-example-codegen
24+
test-example-codegen:
25+
cd example/codegen && \
26+
go test -v -race ./...
27+
28+
.PHONY: test
29+
test: test-sdk test-hasura-ndc-go test-example-codegen
30+
31+
.PHONY: go-tidy
32+
go-tidy:
33+
go mod tidy
34+
cd $(ROOT_DIR)/cmd/hasura-ndc-go && go mod tidy
35+
cd $(ROOT_DIR)/cmd/hasura-ndc-go/testdata/basic/source && go mod tidy
36+
cd $(ROOT_DIR)/cmd/hasura-ndc-go/testdata/empty/source && go mod tidy
37+
cd $(ROOT_DIR)/example/codegen && go mod tidy
38+
1639
# Install golangci-lint tool to run lint locally
1740
# https://golangci-lint.run/usage/install
1841
.PHONY: lint
Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,34 @@
1+
.DEFAULT_GOAL := help
12
ROOT = $(shell pwd)
23

34
.PHONY: start
4-
start:
5+
start: ## Start the server with go run
56
cd .hasura-connector/scripts && \
67
HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH=$(ROOT) $(SHELL) ./start.sh
78

89
.PHONY: update
9-
update:
10+
update: ## Update schema and code generation
1011
cd .hasura-connector/scripts && \
1112
HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH=$(ROOT) $(SHELL) ./update.sh
1213

1314
.PHONY: watch
14-
watch:
15+
watch: ## Watch code changes and live reload
1516
cd .hasura-connector/scripts && \
1617
HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH=$(ROOT) $(SHELL) ./watch.sh
1718

1819
.PHONY: format
19-
format:
20+
format: ## Format go files
2021
gofmt -w -s .
2122

2223
.PHONY: test
23-
test:
24-
go test -v -race -timeout 3m ./...
24+
test: ## Run unit tests
25+
go test -v ./...
2526

26-
# Install golangci-lint tool to run lint locally
27-
# https://golangci-lint.run/usage/install
2827
.PHONY: lint
29-
lint:
30-
golangci-lint run
28+
lint: ## Install golangci-lint tool to run lint locally https://golangci-lint.run/usage/install
29+
golangci-lint run
30+
31+
help:
32+
@echo ""
33+
@echo "Usage:"
34+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?##"}; {printf " \033[36m%-30s\033[0m %s\n", $$1, $$2}'

cmd/hasura-ndc-go/templates/new/README.md.tmpl

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,56 @@
44

55
### DDN CLI
66

7-
DDN CLI automatically starts the connector with `ddn dev` command that uses Docker Compose internally.
8-
Docker Compose can watch changes in the source code and rebuild the connector. However, this connector limits the changes in the root folder only to avoid rebuild noises.
9-
After editing files in child folders, save any `*.go` file in the root folder to trigger the build.
7+
The boilerplate follows [Native Connector Packaging](https://github.com/hasura/ndc-hub/blob/main/rfcs/0004-native-packaging.md) with convenience shell scripts at [the connector definition folder](.hasura-connector/scripts). DDN CLI can automatically invoke those scripts when developing with DDN projects.
108

11-
### Native Go
9+
### Convenience scripts (Linux & MacOS)
1210

13-
Start the connector server at http://localhost:8080
11+
You can run the convenience script with `make`. Those commands reuse native scripts at [the connector definition folder](.hasura-connector/scripts).
1412

15-
```go
16-
go run . serve
13+
```sh
14+
Usage:
15+
start Start the server with go run
16+
update Update schema and code generation
17+
watch Watch code changes and live reload
1718
```
1819

19-
## Code generation
20+
### Manual installation
2021

21-
### Convenience script (Linux & MacOS only)
22+
Install following tools for development:
2223

23-
You can run the convenience script with `make` or with the bash file directly.
24-
The script automatically downloads the tool and runs the `generate` command.
24+
- [hasura-ndc-go](https://github.com/hasura/ndc-sdk-go/tree/main/cmd/hasura-ndc-go)
25+
- [air](https://github.com/cosmtrek/air) (optional, install if you want live reload)
2526

26-
```bash
27-
make generate
27+
```sh
28+
go install github.com/hasura/ndc-sdk-go/cmd/hasura-ndc-go@latest
29+
# downgrade lower version if you don't use the latest Go
30+
go install github.com/cosmtrek/air@latest
2831
```
2932

30-
```bash
31-
sh ./scripts/generate.sh
33+
#### Live reload
34+
35+
**Linux & MacOS**
36+
37+
```sh
38+
air -c air -c .air.toml
3239
```
3340

34-
### Manually download
41+
**Windows**
3542

36-
Download the `hasura-ndc-go` tool at the [release page](https://github.com/hasura/ndc-sdk-go/releases/tag/{{.Version}}) page.
37-
Navigate to the root project folder and run `generate` whenever there are new changes from NDC functions and types.
43+
```sh
44+
air -c air -c .air.windows.toml
45+
```
46+
47+
#### Manual
48+
49+
Whenever modifying NDC types and functions in the `functions` folder, you need to generate NDC schema and codes.
3850

3951
```sh
4052
hasura-ndc-go generate
4153
```
4254

43-
See [NDC Go SDK](https://github.com/hasura/ndc-sdk-go/tree/v0) for more information and [the generation tool](https://github.com/hasura/ndc-sdk-go/tree/v0/cmd/hasura-ndc-go) for command documentation.
55+
Start the connector server at http://localhost:8080
56+
57+
```go
58+
go run . serve
59+
```

0 commit comments

Comments
 (0)