forked from ebhomengo/niki
1
0
Fork 0
niki/Makefile

66 lines
2.0 KiB
Makefile
Raw Normal View History

# TODO: add commands for build and run in dev/produciton mode
2023-12-20 15:39:25 +00:00
ROOT=$(realpath $(dir $(lastword $(MAKEFILE_LIST))))
.PHONY: help confirm lint test format build run docker swagger watch migrate/status migrate/new migrate/up migrate/down
confirm:
@echo -n 'Are you sure? [y/N] ' && read ans && [ $${ans:-N} = y ]
2023-12-20 15:39:25 +00:00
lint:
which golangci-lint || (go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.54.0)
golangci-lint run --config=$(ROOT)/.golangci.yml $(ROOT)/...
test:
go test -v ./...
format:
@which gofumpt || (go install mvdan.cc/gofumpt@latest)
@gofumpt -l -w $(ROOT)
@which gci || (go install github.com/daixiang0/gci@latest)
@gci write $(ROOT)
@which golangci-lint || (go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.54.0)
@golangci-lint run --fix
2024-01-11 07:13:37 +00:00
build:
2024-05-14 13:07:09 +00:00
go build main.go --migrate
run:
go run main.go --migrate
docker:
2024-05-20 17:37:44 +00:00
sudo docker compose up -d
swagger:
swag init
# Live Reload
watch:
@if command -v CompileDaemon > /dev/null; then \
CompileDaemon -exclude-dir=.git -exclude=".#*" -command="./niki"; \
else \
read -p "Go's 'CompileDaemon' is not installed on your machine. Do you want to install it? [Y/n] " choice; \
if [ "$$choice" != "n" ] && [ "$$choice" != "N" ]; then \
go install github.com/githubnemo/CompileDaemon@latest; \
CompileDaemon -exclude-dir=.git -exclude=".#*" -command="./niki"; \
else \
echo "You chose not to install CompileDaemon. Exiting..."; \
exit 1; \
fi; \
fi
migrate/status:
@sql-migrate status -env="production" -config=repository/mysql/dbconfig.yml
# Example: make migrate/new name=add_kindbox_permission
migrate/new:
@echo 'Creating migration file for ${name}...'
@sql-migrate new -env="production" -config=repository/mysql/dbconfig.yml ${name}
migrate/up: confirm
@echo 'Running all migrations...'
@sql-migrate up -env="production" -config=repository/mysql/dbconfig.yml
migrate/down: confirm
@echo 'Tearing down last migration...'
@sql-migrate down -env="production" -config=repository/mysql/dbconfig.yml -limit=1