mirror of
https://github.com/foomo/gotsrpc.git
synced 2025-10-16 12:35:35 +00:00
132 lines
3.1 KiB
Makefile
132 lines
3.1 KiB
Makefile
.DEFAULT_GOAL:=help
|
|
-include .makerc
|
|
|
|
# --- Config -----------------------------------------------------------------
|
|
|
|
# Newline hack for error output
|
|
define br
|
|
|
|
|
|
endef
|
|
|
|
# --- Targets -----------------------------------------------------------------
|
|
|
|
# This allows us to accept extra arguments
|
|
%: .mise .husky
|
|
@:
|
|
|
|
.PHONY: .mise
|
|
# Install dependencies
|
|
.mise: msg := $(br)$(br)Please ensure you have 'mise' installed and activated!$(br)$(br)$$ brew update$(br)$$ brew install mise$(br)$(br)See the documentation: https://mise.jdx.dev/getting-started.html$(br)$(br)
|
|
.mise:
|
|
ifeq (, $(shell command -v mise))
|
|
$(error ${msg})
|
|
endif
|
|
@mise install
|
|
|
|
.PHONY: .husky
|
|
# Configure git hooks for husky
|
|
.husky:
|
|
@git config core.hooksPath .husky
|
|
|
|
### Tasks
|
|
|
|
.PHONY: check
|
|
## Run lint & test
|
|
check: tidy examples lint test
|
|
|
|
.PHONY: tidy
|
|
## Run go mod tidy
|
|
tidy:
|
|
@find . -name go.mod -execdir go mod tidy \;
|
|
|
|
.PHONY: lint
|
|
## Run linter
|
|
lint:
|
|
@find . -name go.mod -execdir golangci-lint run \;
|
|
|
|
.PHONY: lint.fix
|
|
## Run linter and fix
|
|
lint.fix:
|
|
@find . -name go.mod -execdir golangci-lint run --fix \;
|
|
|
|
.PHONY: test
|
|
## Run go test
|
|
test:
|
|
@GO_TEST_TAGS=-skip find . -name go.mod -execdir go test -coverprofile=coverage.out --tags=safe -race ./... \;
|
|
|
|
.PHONY: build
|
|
## Build binary
|
|
build:
|
|
@rm -f bin/gotsrpc
|
|
@go build -o bin/gotsrpc cmd/gotsrpc/gotsrpc.go
|
|
|
|
.PHONY: build.debug
|
|
## Build binary in debug mode
|
|
build.debug:
|
|
@rm -f bin/gotsrpc
|
|
@go build -gcflags "all=-N -l" -o bin/gotsrpc cmd/gotsrpc/gotsrpc.go
|
|
|
|
.PHONY: install
|
|
## Run go install
|
|
install:
|
|
@go install cmd/gotsrpc/gotsrpc.go
|
|
|
|
.PHONY: install.debug
|
|
## Run go install with debug
|
|
install.debug:
|
|
@go install -gcflags "all=-N -l" cmd/gotsrpc/gotsrpc.go
|
|
|
|
EXAMPLES=basic errors monitor nullable union time types
|
|
define examples
|
|
.PHONY: example.$(1)
|
|
example.$(1):
|
|
cd example/${1} && go run ../../cmd/gotsrpc/gotsrpc.go gotsrpc.yml
|
|
cd example/${1}/client && ../../node_modules/.bin/tsc --build
|
|
|
|
.PHONY: example.$(1).run
|
|
example.$(1).run: example.${1}
|
|
cd example/${1} && go run main.go
|
|
|
|
.PHONY: example.$(1).debug
|
|
example.$(1).debug: build.debug
|
|
cd example/${1} && dlv --listen=:2345 --headless=true --api-version=2 --accept-multiclient exec ../../bin/gotsrpc gotsrpc.yml
|
|
|
|
.PHONY: example.$(1).lint
|
|
example.$(1).lint:
|
|
cd example/${1} && golangci-lint run
|
|
endef
|
|
$(foreach p,$(EXAMPLES),$(eval $(call examples,$(p))))
|
|
|
|
.PHONY: examples
|
|
## Generate examples
|
|
examples:
|
|
@for name in example/*/; do\
|
|
if [ $$name != "example/node_modules/" ]; then \
|
|
echo "-------- $${name} ------------";\
|
|
$(MAKE) example.`basename $${name}`;\
|
|
fi \
|
|
done
|
|
.PHONY: examples
|
|
|
|
### Utils
|
|
|
|
.PHONY: help
|
|
## Show help text
|
|
help:
|
|
@echo "gotsrpc\n"
|
|
@echo "Usage:\n make [task]"
|
|
@awk '{ \
|
|
if($$0 ~ /^### /){ \
|
|
if(help) printf "%-23s %s\n\n", cmd, help; help=""; \
|
|
printf "\n%s:\n", substr($$0,5); \
|
|
} else if($$0 ~ /^[a-zA-Z0-9._-]+:/){ \
|
|
cmd = substr($$0, 1, index($$0, ":")-1); \
|
|
if(help) printf " %-23s %s\n", cmd, help; help=""; \
|
|
} else if($$0 ~ /^##/){ \
|
|
help = help ? help "\n " substr($$0,3) : substr($$0,3); \
|
|
} else if(help){ \
|
|
print "\n " help "\n"; help=""; \
|
|
} \
|
|
}' $(MAKEFILE_LIST)
|