1
+ SHELL := /bin/bash
2
+ BASE_PATH := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST ) ) ) )
3
+ VERSION ?= $(shell git describe --tags --always --match=v* 2> /dev/null || \
4
+ cat $(CURDIR ) /.version 2> /dev/null || echo v0)
5
+ VERSION_HASH = $(shell git rev-parse HEAD)
6
+
7
+ BIN = $(BASE_PATH ) /bin
8
+ PATH := $(BIN ) :$(PATH )
9
+ export PATH
10
+
11
+ # printing
12
+ V = 0
13
+ Q = $(if $(filter 1,$V) ,,@)
14
+ M = $(shell printf "\033[34;1m▶\033[0m")
15
+
16
+ GO = GOGC=off go
17
+ # go module
18
+ MODULE = $(shell env GO111MODULE=on $(GO ) list -m)
19
+
20
+ DATE ?= $(shell date +% FT% T% z)
21
+ VERSION ?= $(shell git describe --tags --always --match=v* 2> /dev/null || \
22
+ cat $(CURDIR ) /.version 2> /dev/null || echo v0)
23
+ VERSION_HASH = $(shell git rev-parse HEAD)
24
+ BRANCH = $(shell git rev-parse --abbrev-ref HEAD)
25
+
26
+ LDFLAGS += -X "$(MODULE ) /varsion.Version=$(VERSION ) " -X "$(MODULE ) /varsion.CommitSHA=$(VERSION_HASH ) "
27
+
28
+ # tools
29
+ $(BIN ) :
30
+ @mkdir -p $@
31
+ $(BIN ) /% : | $(BIN ) ; $(info $(M ) installing $(PACKAGE ) …)
32
+ $Q env GOBIN=$(BIN ) $(GO ) install $(PACKAGE )
33
+
34
+ GOLANGCI_LINT = $(BIN ) /golangci-lint
35
+ $(BIN ) /golangci-lint : PACKAGE=github.com/golangci/golangci-lint/cmd/golangci-lint@v1.37.1
36
+
37
+ GOIMPORTS = $(BIN ) /goimports
38
+ $(BIN ) /goimports : PACKAGE=golang.org/x/tools/cmd/goimports@v0.1.0
39
+
40
+ RICE = $(BIN ) /rice
41
+ $(BIN ) /rice : PACKAGE=github.com/GeertJohan/go.rice/rice@v1.0.2
42
+
43
+ # # build: Build
44
+ .PHONY : build
45
+ build : | build-frontend build-backend ; $(info $(M ) building…)
46
+
47
+ # # build-frontend: Build frontend
48
+ .PHONY : build-frontend
49
+ build-frontend : | ; $(info $(M ) building frontend…)
50
+ $Q cd frontend && npm ci && npm run build
51
+
52
+ # # build-backend: Build backend
53
+ .PHONY : build-backend
54
+ build-backend : | $(RICE ) ; $(info $(M ) building backend…)
55
+ $Q cd ./http && rm -rf rice-box.go && $(RICE ) embed-go
56
+ $Q $(GO ) build -ldflags ' $(LDFLAGS)' -o filebrowser
57
+
58
+ # # test: Run all tests
59
+ .PHONY : test
60
+ test : | test-frontend test-backend ; $(info $(M ) running tests…)
61
+
62
+ # # test-frontend: Run frontend tests
63
+ .PHONY : test-frontend
64
+ test-frontend : | ; $(info $(M ) running frontend tests…)
65
+
66
+ # # test-backend: Run backend tests
67
+ .PHONY : test-backend
68
+ test-backend : | $(RICE ) ; $(info $(M ) running backend tests…)
69
+ $Q $(GO ) test -v ./...
70
+
71
+ # # lint: Lint
72
+ .PHONY : lint
73
+ lint : lint-frontend lint-backend lint-commits | ; $(info $(M ) running all linters…)
74
+
75
+ # # lint-frontend: Lint frontend
76
+ .PHONY : lint-frontend
77
+ lint-frontend : | ; $(info $(M ) running frontend linters…)
78
+ $Q cd frontend && npm ci && npm run lint
79
+
80
+ # # lint-backend: Lint backend
81
+ .PHONY : lint-backend
82
+ lint-backend : | $(GOLANGCI_LINT ) ; $(info $(M ) running backend linters…)
83
+ $Q $(GOLANGCI_LINT ) run
84
+
85
+ # # lint-commits: Lint commits
86
+ .PHONY : lint-commits
87
+ lint-commits : | ; $(info $(M ) running commitlint…)
88
+ $Q ./scripts/commitlint.sh
89
+
90
+ # # bump-version: Bump app version
91
+ .PHONY : bump-version
92
+ bump-version : | ; $(info $(M ) creating a new release…)
93
+ $Q ./scripts/bump_version.sh
94
+
95
+ # # help: Show this help
96
+ .PHONY : help
97
+ help :
98
+ @sed -n ' s/^## //p' $(MAKEFILE_LIST ) | column -t -s ' :' | sed -e ' s/^/ /' | sort
0 commit comments