2024-08-06 19:34:28 +00:00
|
|
|
.PHONY: configuration email typescript swagger copy compile compress tailwind bundle-css inline-css variants-html install clean npm config-description config-default precompile
|
2024-08-05 17:46:21 +00:00
|
|
|
|
|
|
|
all: compile
|
|
|
|
|
2021-02-11 18:21:21 +00:00
|
|
|
GOESBUILD ?= off
|
|
|
|
ifeq ($(GOESBUILD), on)
|
|
|
|
ESBUILD := esbuild
|
|
|
|
else
|
|
|
|
ESBUILD := npx esbuild
|
|
|
|
endif
|
2021-02-01 20:55:17 +00:00
|
|
|
GOBINARY ?= go
|
2021-02-11 18:21:21 +00:00
|
|
|
|
2022-01-08 16:42:36 +00:00
|
|
|
CSSVERSION ?= v3
|
2024-08-05 17:46:21 +00:00
|
|
|
CSS_BUNDLE = $(DATA)/web/css/$(CSSVERSION)bundle.css
|
2022-01-08 16:42:36 +00:00
|
|
|
|
2021-02-22 01:26:07 +00:00
|
|
|
VERSION ?= $(shell git describe --exact-match HEAD 2> /dev/null || echo vgit)
|
2021-02-22 01:23:42 +00:00
|
|
|
VERSION := $(shell echo $(VERSION) | sed 's/v//g')
|
|
|
|
COMMIT ?= $(shell git rev-parse --short HEAD || echo unknown)
|
2023-06-23 13:16:36 +00:00
|
|
|
BUILDTIME ?= $(shell date +%s)
|
2021-02-22 01:23:42 +00:00
|
|
|
|
2021-03-07 15:23:44 +00:00
|
|
|
UPDATER ?= off
|
2023-06-23 20:31:33 +00:00
|
|
|
LDFLAGS := -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.cssVersion=$(CSSVERSION) -X main.buildTimeUnix=$(BUILDTIME) $(if $(BUILTBY),-X 'main.builtBy=$(BUILTBY)',)
|
2021-03-07 15:23:44 +00:00
|
|
|
ifeq ($(UPDATER), on)
|
2021-04-01 13:22:11 +00:00
|
|
|
LDFLAGS := $(LDFLAGS) -X main.updater=binary
|
2021-03-07 15:23:44 +00:00
|
|
|
else ifneq ($(UPDATER), off)
|
2021-04-01 13:22:11 +00:00
|
|
|
LDFLAGS := $(LDFLAGS) -X main.updater=$(UPDATER)
|
|
|
|
endif
|
|
|
|
|
2021-07-16 14:41:08 +00:00
|
|
|
|
|
|
|
|
2021-04-01 13:22:11 +00:00
|
|
|
INTERNAL ?= on
|
2021-07-16 14:41:08 +00:00
|
|
|
TRAY ?= off
|
|
|
|
E2EE ?= off
|
|
|
|
TAGS := -tags "
|
|
|
|
|
2021-04-01 13:22:11 +00:00
|
|
|
ifeq ($(INTERNAL), on)
|
|
|
|
DATA := data
|
|
|
|
else
|
|
|
|
DATA := build/data
|
2021-07-16 14:41:08 +00:00
|
|
|
TAGS := $(TAGS) external
|
2021-03-07 15:23:44 +00:00
|
|
|
endif
|
|
|
|
|
2021-07-16 14:41:08 +00:00
|
|
|
ifeq ($(TRAY), on)
|
2021-05-16 15:23:28 +00:00
|
|
|
TAGS := $(TAGS) tray
|
|
|
|
endif
|
|
|
|
|
2021-07-16 14:41:08 +00:00
|
|
|
ifeq ($(E2EE), on)
|
|
|
|
TAGS := $(TAGS) e2ee
|
|
|
|
endif
|
|
|
|
|
|
|
|
TAGS := $(TAGS)"
|
|
|
|
|
2021-05-16 15:23:28 +00:00
|
|
|
OS := $(shell go env GOOS)
|
|
|
|
ifeq ($(TRAY)$(OS), onwindows)
|
|
|
|
LDFLAGS := $(LDFLAGS) -H=windowsgui
|
|
|
|
endif
|
|
|
|
|
2021-04-01 13:33:57 +00:00
|
|
|
DEBUG ?= off
|
|
|
|
ifeq ($(DEBUG), on)
|
|
|
|
SOURCEMAP := --sourcemap
|
2024-08-04 20:57:07 +00:00
|
|
|
MINIFY :=
|
2023-06-11 14:11:00 +00:00
|
|
|
TYPECHECK := npx tsc -noEmit --project ts/tsconfig.json
|
2021-04-01 13:33:57 +00:00
|
|
|
# jank
|
2022-01-04 20:12:19 +00:00
|
|
|
COPYTS := rm -r $(DATA)/web/js/ts; cp -r tempts $(DATA)/web/js/ts
|
2024-08-05 17:46:21 +00:00
|
|
|
UNCSS := cp $(CSS_BUNDLE) $(DATA)/bundle.css
|
2023-06-12 17:44:10 +00:00
|
|
|
# TAILWIND := --content ""
|
2021-04-01 13:33:57 +00:00
|
|
|
else
|
2021-05-16 14:00:13 +00:00
|
|
|
LDFLAGS := -s -w $(LDFLAGS)
|
2021-04-01 13:33:57 +00:00
|
|
|
SOURCEMAP :=
|
2024-08-04 20:57:07 +00:00
|
|
|
MINIFY := --minify
|
2021-04-01 13:33:57 +00:00
|
|
|
COPYTS :=
|
2021-05-03 17:32:56 +00:00
|
|
|
TYPECHECK :=
|
2024-08-05 17:46:21 +00:00
|
|
|
UNCSS := npx tailwindcss -i $(CSS_BUNDLE) -o $(DATA)/bundle.css --content "html/crash.html"
|
2021-12-31 15:09:33 +00:00
|
|
|
# UNCSS := npx uncss $(DATA)/crash.html --csspath web/css --output $(DATA)/bundle.css
|
2021-12-30 23:52:53 +00:00
|
|
|
TAILWIND :=
|
2021-04-01 13:33:57 +00:00
|
|
|
endif
|
|
|
|
|
2021-05-23 21:26:56 +00:00
|
|
|
RACE ?= off
|
|
|
|
ifeq ($(RACE), on)
|
|
|
|
RACEDETECTOR := -race
|
|
|
|
else
|
|
|
|
RACEDETECTOR :=
|
|
|
|
endif
|
|
|
|
|
2023-06-23 20:31:33 +00:00
|
|
|
ifeq (, $(shell which esbuild))
|
|
|
|
ESBUILDINSTALL := go install github.com/evanw/esbuild/cmd/esbuild@latest
|
|
|
|
else
|
|
|
|
ESBUILDINSTALL :=
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(GOESBUILD), on)
|
|
|
|
NPMIGNOREOPTIONAL := --no-optional
|
|
|
|
NPMOPTS := $(NPMIGNOREOPTIONAL); $(ESBUILDINSTALL)
|
|
|
|
else
|
|
|
|
NPMOPTS :=
|
|
|
|
endif
|
|
|
|
|
2023-06-27 06:23:25 +00:00
|
|
|
ifeq (, $(shell which swag))
|
|
|
|
SWAGINSTALL := $(GOBINARY) install github.com/swaggo/swag/cmd/swag@latest
|
|
|
|
else
|
|
|
|
SWAGINSTALL :=
|
|
|
|
endif
|
2023-06-23 20:31:33 +00:00
|
|
|
|
2024-08-05 17:46:21 +00:00
|
|
|
CONFIG_BASE = config/config-base.json
|
2021-01-05 18:16:23 +00:00
|
|
|
|
2024-08-05 17:46:21 +00:00
|
|
|
CONFIG_DESCRIPTION = $(DATA)/config-base.json
|
|
|
|
CONFIG_DEFAULT = $(DATA)/config-default.ini
|
|
|
|
$(CONFIG_DESCRIPTION) &: $(CONFIG_BASE)
|
2020-09-21 21:03:20 +00:00
|
|
|
$(info Fixing config-base)
|
2021-04-01 13:22:11 +00:00
|
|
|
-mkdir -p $(DATA)
|
|
|
|
python3 scripts/enumerate_config.py -i config/config-base.json -o $(DATA)/config-base.json
|
2024-08-05 17:46:21 +00:00
|
|
|
|
|
|
|
$(CONFIG_DEFAULT) &: $(CONFIG_BASE)
|
2020-09-21 21:03:20 +00:00
|
|
|
$(info Generating config-default.ini)
|
2021-04-01 13:22:11 +00:00
|
|
|
python3 scripts/generate_ini.py -i config/config-base.json -o $(DATA)/config-default.ini
|
2020-08-03 17:00:54 +00:00
|
|
|
|
2024-08-05 17:46:21 +00:00
|
|
|
configuration: $(CONFIG_DESCRIPTION) $(CONFIG_DEFAULT)
|
|
|
|
|
|
|
|
EMAIL_SRC_MJML = $(wildcard mail/*.mjml)
|
|
|
|
EMAIL_SRC_TXT = $(wildcard mail/*.txt)
|
|
|
|
EMAIL_DATA_MJML = $(EMAIL_SRC_MJML:mail/%=data/%)
|
|
|
|
EMAIL_HTML = $(EMAIL_DATA_MJML:.mjml=.html)
|
|
|
|
EMAIL_TXT = $(EMAIL_SRC_TXT:mail/%=data/%)
|
|
|
|
EMAIL_ALL = $(EMAIL_HTML) $(EMAIL_TXT)
|
|
|
|
EMAIL_TARGET = mail/confirmation.html
|
|
|
|
$(EMAIL_TARGET): $(EMAIL_SRC_MJML) $(EMAIL_SRC_TXT)
|
2020-09-21 21:03:20 +00:00
|
|
|
$(info Generating email html)
|
2021-04-01 13:22:11 +00:00
|
|
|
python3 scripts/compile_mjml.py -o $(DATA)/
|
2020-08-03 17:00:54 +00:00
|
|
|
|
2024-08-05 17:46:21 +00:00
|
|
|
TYPESCRIPT_FULLSRC = $(shell find ts/ -type f -name "*.ts")
|
|
|
|
TYPESCRIPT_SRC = $(wildcard ts/*.ts)
|
|
|
|
TYPESCRIPT_TEMPSRC = $(TYPESCRIPT_SRC:ts/%=tempts/%)
|
|
|
|
# TYPESCRIPT_TARGET = $(patsubst %.ts,%.js,$(subst tempts/,./$(DATA)/web/js/,$(TYPESCRIPT_TEMPSRC)))
|
|
|
|
TYPESCRIPT_TARGET = $(DATA)/web/js/admin.js
|
|
|
|
$(TYPESCRIPT_TARGET): $(TYPESCRIPT_FULLSRC) ts/tsconfig.json
|
2021-05-03 17:32:56 +00:00
|
|
|
$(TYPECHECK)
|
2022-01-30 18:03:21 +00:00
|
|
|
rm -rf tempts
|
2021-12-30 02:45:29 +00:00
|
|
|
cp -r ts tempts
|
2024-08-05 17:46:21 +00:00
|
|
|
$(adding dark variants to typescript)
|
2022-01-04 20:12:19 +00:00
|
|
|
scripts/dark-variant.sh tempts
|
|
|
|
scripts/dark-variant.sh tempts/modules
|
2021-01-05 18:16:23 +00:00
|
|
|
$(info compiling typescript)
|
2022-01-30 18:03:21 +00:00
|
|
|
mkdir -p $(DATA)/web/js
|
2024-08-05 17:46:21 +00:00
|
|
|
$(foreach tempsrc,$(TYPESCRIPT_TEMPSRC),$(ESBUILD) --target=es6 --bundle $(tempsrc) $(SOURCEMAP) --outfile=$(patsubst %.ts,%.js,$(subst tempts/,./$(DATA)/web/js/,$(tempsrc))) $(MINIFY);)
|
|
|
|
mv $(DATA)/web/js/crash.js $(DATA)/
|
2021-04-01 13:33:57 +00:00
|
|
|
$(COPYTS)
|
2020-09-23 19:14:16 +00:00
|
|
|
|
2024-08-05 17:46:21 +00:00
|
|
|
SWAGGER_SRC = $(wildcard api*.go) $(wildcard *auth.go) views.go
|
|
|
|
SWAGGER_TARGET = docs/docs.go
|
|
|
|
$(SWAGGER_TARGET): $(SWAGGER_SRC)
|
2023-06-27 06:23:25 +00:00
|
|
|
$(SWAGINSTALL)
|
2020-09-24 16:51:13 +00:00
|
|
|
swag init -g main.go
|
|
|
|
|
2024-08-05 17:46:21 +00:00
|
|
|
VARIANTS_SRC = $(wildcard html/*.html)
|
|
|
|
VARIANTS_TARGET = $(DATA)/html/admin.html
|
|
|
|
$(VARIANTS_TARGET): $(VARIANTS_SRC)
|
|
|
|
$(info copying html)
|
|
|
|
cp -r html $(DATA)/
|
|
|
|
$(info adding dark variants to html)
|
|
|
|
node scripts/missing-colors.js html $(DATA)/html
|
2020-09-02 19:06:02 +00:00
|
|
|
|
2024-08-05 17:46:21 +00:00
|
|
|
ICON_SRC = node_modules/remixicon/fonts/remixicon.css node_modules/remixicon/fonts/remixicon.woff2
|
|
|
|
ICON_TARGET = $(ICON_SRC:node_modules/remixicon/fonts/%=$(DATA)/web/css/%)
|
|
|
|
CSS_SRC = $(wildcard css/*.css)
|
|
|
|
CSS_TARGET = $(DATA)/web/css/part-bundle.css
|
|
|
|
CSS_FULLTARGET = $(CSS_BUNDLE)
|
|
|
|
ALL_CSS_SRC = $(ICON_SRC) $(CSS_SRC)
|
|
|
|
ALL_CSS_TARGET = $(ICON_TARGET)
|
2020-08-03 17:00:54 +00:00
|
|
|
|
2024-08-05 17:46:21 +00:00
|
|
|
$(CSS_FULLTARGET): $(TYPESCRIPT_TARGET) $(VARIANTS_TARGET) $(ALL_CSS_SRC) $(wildcard html/*.html)
|
2022-01-30 18:03:21 +00:00
|
|
|
mkdir -p $(DATA)/web/css
|
2023-06-12 17:44:10 +00:00
|
|
|
$(info copying fonts)
|
|
|
|
cp -r node_modules/remixicon/fonts/remixicon.css node_modules/remixicon/fonts/remixicon.woff2 $(DATA)/web/css/
|
2021-01-23 18:53:14 +00:00
|
|
|
$(info bundling css)
|
2024-08-05 17:46:21 +00:00
|
|
|
$(ESBUILD) --bundle css/base.css --outfile=$(CSS_TARGET) --external:remixicon.css --external:../fonts/hanken* --minify
|
|
|
|
|
|
|
|
npx tailwindcss -i $(CSS_TARGET) -o $(CSS_FULLTARGET) $(TAILWIND)
|
|
|
|
rm $(CSS_TARGET)
|
|
|
|
# mv $(CSS_BUNDLE) $(DATA)/web/css/$(CSSVERSION)bundle.css
|
|
|
|
# npx postcss -o $(CSS_TARGET) $(CSS_TARGET)
|
2021-06-11 22:14:16 +00:00
|
|
|
|
2024-08-05 17:46:21 +00:00
|
|
|
bundle-css: tailwind
|
|
|
|
|
|
|
|
INLINE_SRC = html/crash.html
|
|
|
|
INLINE_TARGET = $(DATA)/crash.html
|
|
|
|
$(INLINE_TARGET): $(CSS_FULLTARGET) $(INLINE_SRC)
|
2021-06-11 20:56:53 +00:00
|
|
|
cp html/crash.html $(DATA)/crash.html
|
2024-08-05 17:46:21 +00:00
|
|
|
$(UNCSS) # generates $(DATA)/bundle.css for us
|
2021-11-14 14:50:40 +00:00
|
|
|
node scripts/inline.js root $(DATA) $(DATA)/crash.html $(DATA)/crash.html
|
2021-06-11 22:39:38 +00:00
|
|
|
rm $(DATA)/bundle.css
|
2021-01-23 18:53:14 +00:00
|
|
|
|
2024-08-05 17:46:21 +00:00
|
|
|
LANG_SRC = $(shell find ./lang)
|
|
|
|
LANG_TARGET = $(LANG_SRC:lang/%=$(DATA)/lang/%)
|
|
|
|
STATIC_SRC = $(wildcard static/*)
|
|
|
|
STATIC_TARGET = $(STATIC_SRC:static/%=$(DATA)/web/%)
|
|
|
|
COPY_SRC = images/banner.svg jfa-go.service LICENSE $(LANG_SRC) $(STATIC_SRC)
|
|
|
|
COPY_TARGET = $(DATA)/jfa-go.service
|
|
|
|
# $(DATA)/LICENSE $(LANG_TARGET) $(STATIC_TARGET) $(DATA)/web/css/$(CSSVERSION)bundle.css
|
|
|
|
$(COPY_TARGET): $(INLINE_TARGET) $(STATIC_SRC)
|
2021-12-30 00:49:43 +00:00
|
|
|
$(info copying crash page)
|
2024-08-05 17:46:21 +00:00
|
|
|
cp $(DATA)/crash.html $(DATA)/html/
|
2021-01-05 18:16:23 +00:00
|
|
|
$(info copying static data)
|
2022-01-30 18:03:21 +00:00
|
|
|
mkdir -p $(DATA)/web
|
2024-08-04 20:03:36 +00:00
|
|
|
cp images/banner.svg static/banner.svg
|
2021-04-01 13:22:11 +00:00
|
|
|
cp -r static/* $(DATA)/web/
|
2021-04-24 17:54:31 +00:00
|
|
|
$(info copying systemd service)
|
|
|
|
cp jfa-go.service $(DATA)/
|
2021-01-05 18:16:23 +00:00
|
|
|
$(info copying language files)
|
2021-04-01 13:22:11 +00:00
|
|
|
cp -r lang $(DATA)/
|
|
|
|
cp LICENSE $(DATA)/
|
2024-08-05 17:46:21 +00:00
|
|
|
|
2024-08-06 19:34:28 +00:00
|
|
|
precompile: $(CONFIG_DESCRIPTION) $(CONFIG_DEFAULT) $(EMAIL_TARGET) $(COPY_TARGET) $(SWAGGER_TARGET)
|
|
|
|
|
2024-08-05 17:46:21 +00:00
|
|
|
GO_SRC = $(shell find ./ -name "*.go")
|
|
|
|
GO_TARGET = build/jfa-go
|
2024-08-06 13:48:31 +00:00
|
|
|
$(GO_TARGET): $(CONFIG_DESCRIPTION) $(CONFIG_DEFAULT) $(EMAIL_TARGET) $(COPY_TARGET) $(SWAGGER_TARGET) $(GO_SRC) go.mod go.sum
|
2024-08-05 17:46:21 +00:00
|
|
|
$(info Downloading deps)
|
|
|
|
$(GOBINARY) mod download
|
|
|
|
$(info Building)
|
|
|
|
mkdir -p build
|
|
|
|
$(GOBINARY) build $(RACEDETECTOR) -ldflags="$(LDFLAGS)" $(TAGS) -o $(GO_TARGET)
|
|
|
|
|
|
|
|
compile: $(GO_TARGET)
|
|
|
|
|
|
|
|
compress:
|
|
|
|
upx --lzma build/jfa-go
|
2021-04-01 13:22:11 +00:00
|
|
|
|
|
|
|
# internal-files:
|
|
|
|
# python3 scripts/embed.py internal
|
|
|
|
#
|
|
|
|
# external-files:
|
|
|
|
# python3 scripts/embed.py external
|
|
|
|
# -mkdir -p build
|
|
|
|
# $(info copying internal data into build/)
|
|
|
|
# cp -r data build/
|
2020-08-03 17:00:54 +00:00
|
|
|
|
2020-08-19 11:10:34 +00:00
|
|
|
install:
|
|
|
|
cp -r build $(DESTDIR)/jfa-go
|
|
|
|
|
2021-04-01 13:22:11 +00:00
|
|
|
clean:
|
|
|
|
-rm -r $(DATA)
|
|
|
|
-rm -r build
|
|
|
|
-rm mail/*.html
|
|
|
|
-rm docs/docs.go docs/swagger.json docs/swagger.yaml
|
|
|
|
go clean
|
|
|
|
|
2024-08-05 17:46:21 +00:00
|
|
|
npm:
|
|
|
|
$(info installing npm dependencies)
|
|
|
|
npm install $(NPMOPTS)
|