2021-08-08 15:04:11 +08:00
|
|
|
# Try to get the commit hash from 1) git 2) the VERSION file 3) fallback.
|
|
|
|
LAST_COMMIT := $(or $(shell git rev-parse --short HEAD 2> /dev/null),$(shell head -n 1 VERSION | grep -oP -m 1 "^[a-z0-9]+$$"),"UNKNOWN")
|
|
|
|
|
|
|
|
# Try to get the semver from 1) git 2) the VERSION file 3) fallbakc.
|
|
|
|
VERSION := $(or $(shell git describe --tags --abbrev=0 2> /dev/null),$(shell grep -oP "tag: \K(.*)(?=,)" VERSION),"v0.0.0")
|
|
|
|
|
2020-10-19 01:29:22 +08:00
|
|
|
BUILDSTR := ${VERSION} (\#${LAST_COMMIT} $(shell date -u +"%Y-%m-%dT%H:%M:%S%z"))
|
2019-07-08 20:51:44 +08:00
|
|
|
|
2021-06-27 01:20:40 +08:00
|
|
|
YARN ?= yarn
|
2021-06-27 02:25:02 +08:00
|
|
|
GOPATH ?= $(HOME)/go
|
|
|
|
STUFFBIN ?= $(GOPATH)/bin/stuffbin
|
|
|
|
FRONTEND_YARN_MODULES = frontend/node_modules
|
|
|
|
FRONTEND_DIST = frontend/dist
|
|
|
|
FRONTEND_DEPS = \
|
|
|
|
$(FRONTEND_YARN_MODULES) \
|
|
|
|
frontend/package.json \
|
|
|
|
frontend/vue.config.js \
|
|
|
|
frontend/babel.config.js \
|
|
|
|
$(shell find frontend/fontello frontend/public frontend/src -type f)
|
2021-06-27 01:20:40 +08:00
|
|
|
|
2018-10-25 21:51:47 +08:00
|
|
|
BIN := listmonk
|
2020-06-07 02:03:55 +08:00
|
|
|
STATIC := config.toml.sample \
|
|
|
|
schema.sql queries.sql \
|
|
|
|
static/public:/public \
|
|
|
|
static/email-templates \
|
2020-12-19 18:55:52 +08:00
|
|
|
frontend/dist/frontend:/frontend \
|
|
|
|
i18n:/i18n
|
2018-10-25 21:51:47 +08:00
|
|
|
|
2021-06-27 02:25:02 +08:00
|
|
|
.PHONY: build
|
|
|
|
build: $(BIN)
|
|
|
|
|
|
|
|
$(STUFFBIN):
|
2019-06-26 14:29:03 +08:00
|
|
|
go get -u github.com/knadh/stuffbin/...
|
2021-06-27 02:25:02 +08:00
|
|
|
|
|
|
|
$(FRONTEND_YARN_MODULES): frontend/package.json frontend/yarn.lock
|
2021-06-27 01:20:40 +08:00
|
|
|
cd frontend && $(YARN) install
|
2021-06-27 02:25:02 +08:00
|
|
|
touch --no-create $(FRONTEND_YARN_MODULES)
|
2019-01-09 19:13:13 +08:00
|
|
|
|
2021-04-11 15:26:56 +08:00
|
|
|
# Build the backend to ./listmonk.
|
2021-06-30 00:53:52 +08:00
|
|
|
$(BIN): $(shell find . -type f -name "*.go")
|
2021-04-11 15:26:56 +08:00
|
|
|
CGO_ENABLED=0 go build -o ${BIN} -ldflags="-s -w -X 'main.buildString=${BUILDSTR}' -X 'main.versionString=${VERSION}'" cmd/*.go
|
2020-10-19 01:14:21 +08:00
|
|
|
|
2021-07-25 18:17:37 +08:00
|
|
|
# Run the backend in dev mode. The frontend assets in dev mode are loaded from disk from frontend/dist/frontend.
|
2021-02-20 16:19:14 +08:00
|
|
|
.PHONY: run
|
2021-07-25 18:17:37 +08:00
|
|
|
run:
|
|
|
|
CGO_ENABLED=0 go run -ldflags="-s -w -X 'main.buildString=${BUILDSTR}' -X 'main.versionString=${VERSION}' -X 'main.frontendDir=frontend/dist/frontend'" cmd/*.go
|
2019-07-08 20:51:44 +08:00
|
|
|
|
2021-04-11 15:26:56 +08:00
|
|
|
# Build the JS frontend into frontend/dist.
|
2021-06-27 02:25:02 +08:00
|
|
|
$(FRONTEND_DIST): $(FRONTEND_DEPS)
|
2021-07-11 13:03:00 +08:00
|
|
|
export VUE_APP_VERSION="${VERSION}" && cd frontend && $(YARN) build && mv dist/favicon.png dist/frontend/favicon.png
|
2021-06-27 02:25:02 +08:00
|
|
|
touch --no-create $(FRONTEND_DIST)
|
|
|
|
|
2021-07-11 13:03:00 +08:00
|
|
|
|
2021-06-27 02:25:02 +08:00
|
|
|
.PHONY: build-frontend
|
|
|
|
build-frontend: $(FRONTEND_DIST)
|
2019-07-08 20:51:44 +08:00
|
|
|
|
2021-04-11 15:26:56 +08:00
|
|
|
# Run the JS frontend server in dev mode.
|
|
|
|
.PHONY: run-frontend
|
|
|
|
run-frontend:
|
2021-06-27 01:20:40 +08:00
|
|
|
export VUE_APP_VERSION="${VERSION}" && cd frontend && $(YARN) serve
|
2021-04-11 15:26:56 +08:00
|
|
|
|
|
|
|
# Run Go tests.
|
|
|
|
.PHONY: test
|
|
|
|
test:
|
|
|
|
go test ./...
|
2020-10-19 01:14:21 +08:00
|
|
|
|
2021-02-20 16:19:14 +08:00
|
|
|
# Bundle all static assets including the JS frontend into the ./listmonk binary
|
|
|
|
# using stuffbin (installed with make deps).
|
|
|
|
.PHONY: dist
|
2021-06-27 02:25:02 +08:00
|
|
|
dist: $(STUFFBIN) build build-frontend
|
|
|
|
$(STUFFBIN) -a stuff -in ${BIN} -out ${BIN} ${STATIC}
|
2021-02-20 16:19:14 +08:00
|
|
|
|
2021-04-11 15:26:56 +08:00
|
|
|
# pack-releases runns stuffbin packing on the given binary. This is used
|
|
|
|
# in the .goreleaser post-build hook.
|
|
|
|
.PHONY: pack-bin
|
2021-06-27 02:25:02 +08:00
|
|
|
pack-bin: $(STUFFBIN)
|
|
|
|
$(STUFFBIN) -a stuff -in ${BIN} -out ${BIN} ${STATIC}
|
2021-04-11 15:26:56 +08:00
|
|
|
|
2020-10-19 01:14:21 +08:00
|
|
|
# Use goreleaser to do a dry run producing local builds.
|
|
|
|
.PHONY: release-dry
|
|
|
|
release-dry:
|
|
|
|
goreleaser --parallelism 1 --rm-dist --snapshot --skip-validate --skip-publish
|
2018-10-25 21:51:47 +08:00
|
|
|
|
2020-10-19 01:14:21 +08:00
|
|
|
# Use goreleaser to build production releases and publish them.
|
|
|
|
.PHONY: release
|
|
|
|
release:
|
|
|
|
goreleaser --parallelism 1 --rm-dist --skip-validate
|