GOESBUILD ?= off
i f e q ( $( GOESBUILD ) , o n )
ESBUILD := esbuild
e l s e
ESBUILD := npx esbuild
e n d i f
GOBINARY ?= go
CSSVERSION ?= v3
VERSION ?= $( shell git describe --exact-match HEAD 2> /dev/null || echo vgit)
VERSION := $( shell echo $( VERSION) | sed 's/v//g' )
COMMIT ?= $( shell git rev-parse --short HEAD || echo unknown)
UPDATER ?= off
LDFLAGS := -X main.version= $( VERSION) -X main.commit= $( COMMIT) -X main.cssVersion= $( CSSVERSION)
i f e q ( $( UPDATER ) , o n )
LDFLAGS := $( LDFLAGS) -X main.updater= binary
e l s e i f n e q ( $( UPDATER ) , o f f )
LDFLAGS := $( LDFLAGS) -X main.updater= $( UPDATER)
e n d i f
INTERNAL ?= on
TRAY ?= off
E2EE ?= off
TAGS := -tags "
i f e q ( $( INTERNAL ) , o n )
DATA := data
e l s e
DATA := build/data
TAGS := $( TAGS) external
e n d i f
i f e q ( $( TRAY ) , o n )
TAGS := $( TAGS) tray
e n d i f
i f e q ( $( E 2EE ) , o n )
TAGS := $( TAGS) e2ee
e n d i f
TAGS := $( TAGS) "
OS := $( shell go env GOOS)
i f e q ( $( TRAY ) $( OS ) , o n w i n d o w s )
LDFLAGS := $( LDFLAGS) -H= windowsgui
e n d i f
DEBUG ?= off
i f e q ( $( DEBUG ) , o n )
SOURCEMAP := --sourcemap
TYPECHECK := npx tsc -noEmit --project ts/tsconfig.json
# jank
COPYTS := rm -r $( DATA) /web/js/ts; cp -r tempts $( DATA) /web/js/ts
UNCSS := cp $( DATA) /web/css/bundle.css $( DATA) /bundle.css
# TAILWIND := --content ""
e l s e
LDFLAGS := -s -w $( LDFLAGS)
SOURCEMAP :=
COPYTS :=
TYPECHECK :=
UNCSS := npx tailwindcss -i $( DATA) /web/css/bundle.css -o $( DATA) /bundle.css --content "html/crash.html"
# UNCSS := npx uncss $(DATA)/crash.html --csspath web/css --output $(DATA)/bundle.css
TAILWIND :=
e n d i f
RACE ?= off
i f e q ( $( RACE ) , o n )
RACEDETECTOR := -race
e l s e
RACEDETECTOR :=
e n d i f
npm :
$( info installing npm dependencies)
npm install
@if [ " $( GOESBUILD) " = "off" ] ; then \
npm install esbuild; \
else \
go install github.com/evanw/esbuild/cmd/esbuild@latest; \
fi
configuration :
$( info Fixing config-base)
-mkdir -p $( DATA)
python3 scripts/enumerate_config.py -i config/config-base.json -o $( DATA) /config-base.json
$( info Generating config-default.ini)
python3 scripts/generate_ini.py -i config/config-base.json -o $( DATA) /config-default.ini
email :
$( info Generating email html)
python3 scripts/compile_mjml.py -o $( DATA) /
typescript :
$( TYPECHECK)
$( adding dark variants to typescript)
rm -rf tempts
cp -r ts tempts
scripts/dark-variant.sh tempts
scripts/dark-variant.sh tempts/modules
$( info compiling typescript)
mkdir -p $( DATA) /web/js
$( ESBUILD) --target= es6 --bundle tempts/admin.ts $( SOURCEMAP) --outfile= ./$( DATA) /web/js/admin.js --minify
$( ESBUILD) --target= es6 --bundle tempts/user.ts $( SOURCEMAP) --outfile= ./$( DATA) /web/js/user.js --minify
$( ESBUILD) --target= es6 --bundle tempts/pwr.ts $( SOURCEMAP) --outfile= ./$( DATA) /web/js/pwr.js --minify
$( ESBUILD) --target= es6 --bundle tempts/form.ts $( SOURCEMAP) --outfile= ./$( DATA) /web/js/form.js --minify
$( ESBUILD) --target= es6 --bundle tempts/setup.ts $( SOURCEMAP) --outfile= ./$( DATA) /web/js/setup.js --minify
$( ESBUILD) --target= es6 --bundle tempts/crash.ts --outfile= ./$( DATA) /crash.js --minify
$( COPYTS)
swagger :
$( GOBINARY) install github.com/swaggo/swag/cmd/swag@latest
swag init -g main.go
compile :
$( info Downloading deps)
$( GOBINARY) mod download
$( info Building)
mkdir -p build
$( GOBINARY) build $( RACEDETECTOR) -ldflags= " $( LDFLAGS) " $( TAGS) -o build/jfa-go
compress :
upx --lzma build/jfa-go
bundle-css :
mkdir -p $( DATA) /web/css
$( info copying fonts)
cp -r node_modules/remixicon/fonts/remixicon.css node_modules/remixicon/fonts/remixicon.woff2 $( DATA) /web/css/
$( info bundling css)
$( ESBUILD) --bundle css/base.css --outfile= $( DATA) /web/css/bundle.css --external:remixicon.css --external:../fonts/hanken* --minify
npx tailwindcss -i $( DATA) /web/css/bundle.css -o $( DATA) /web/css/bundle.css $( TAILWIND)
# npx postcss -o $(DATA)/web/css/bundle.css $(DATA)/web/css/bundle.css
inline-css :
cp html/crash.html $( DATA) /crash.html
$( UNCSS)
node scripts/inline.js root $( DATA) $( DATA) /crash.html $( DATA) /crash.html
rm $( DATA) /bundle.css
variants-html :
$( info copying html)
cp -r html $( DATA) /
$( info adding dark variants to html)
node scripts/missing-colors.js html $( DATA) /html
copy :
$( info copying crash page)
mv $( DATA) /crash.html $( DATA) /html/
$( info copying static data)
mkdir -p $( DATA) /web
cp -r static/* $( DATA) /web/
$( info copying systemd service)
cp jfa-go.service $( DATA) /
$( info copying language files)
cp -r lang $( DATA) /
cp LICENSE $( DATA) /
mv $( DATA) /web/css/bundle.css $( DATA) /web/css/$( CSSVERSION) bundle.css
# 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/
install :
cp -r build $( DESTDIR) /jfa-go
clean :
-rm -r $( DATA)
-rm -r build
-rm mail/*.html
-rm docs/docs.go docs/swagger.json docs/swagger.yaml
go clean
quick : configuration typescript variants -html bundle -css inline -css copy compile
all : configuration npm email typescript variants -html bundle -css inline -css swagger copy compile