2022-09-05 12:23:17 -05:00
|
|
|
VERSION ?= $(shell git describe --tags --always --dirty | sed s'/dirty/dev/')
|
|
|
|
TEMPLATES := $(shell find src/ -type f)
|
|
|
|
.DEFAULT_GOAL := help
|
|
|
|
|
2022-09-07 00:11:26 -05:00
|
|
|
msg = $(call tprint,{a.bold}==>{a.end} {a.magenta}$(1){a.end} {a.bold}<=={a.end})
|
2022-09-05 12:23:17 -05:00
|
|
|
|
2022-09-13 16:40:07 -05:00
|
|
|
### task.mk development | args: --divider --align center
|
|
|
|
|
2022-09-05 18:02:16 -05:00
|
|
|
## bootstrap | generate local dev environment
|
2022-09-05 12:23:17 -05:00
|
|
|
.PHONY: bootstrap
|
|
|
|
bootstrap:
|
2022-09-07 00:11:26 -05:00
|
|
|
$(call msg,Bootstrap Environment)
|
2022-09-05 18:02:16 -05:00
|
|
|
@mamba create -p ./env python jinja2 black -y
|
|
|
|
@mamba run -p ./env pip install yartsu
|
2022-09-07 15:48:46 -05:00
|
|
|
@git config core.hooksPath .githooks
|
2022-09-05 12:23:17 -05:00
|
|
|
|
2022-09-13 16:40:07 -05:00
|
|
|
## l, lint | lint the python
|
|
|
|
.PHONY: l lint
|
|
|
|
l lint:
|
|
|
|
$(call msg,Linting)
|
2022-09-05 12:23:17 -05:00
|
|
|
@black generate.py
|
|
|
|
@black src/*.py --fast
|
|
|
|
|
2022-09-05 18:02:16 -05:00
|
|
|
## assets | generate assets
|
|
|
|
.PHONY: assets
|
|
|
|
assets:
|
|
|
|
yartsu -o assets/help.svg -t "make help" -- make --no-print-directory help
|
|
|
|
|
|
|
|
## release | release new version of task.mk
|
2022-09-05 12:23:17 -05:00
|
|
|
.PHONY: release
|
|
|
|
release: version-check
|
2022-09-07 00:11:26 -05:00
|
|
|
$(call msg,Release Project)
|
2022-09-12 00:16:25 -05:00
|
|
|
@./generate.py $(VERSION) > task.mk
|
2022-09-05 12:23:17 -05:00
|
|
|
@sed -i 's/task.mk\/.*\/task.mk/task.mk\/v$(VERSION)\/task.mk/g' README.md
|
|
|
|
@git add task.mk README.md
|
2022-09-07 15:48:46 -05:00
|
|
|
@git commit -m "release: v$(VERSION)" --no-verify
|
2022-09-07 00:15:21 -05:00
|
|
|
@git tag v$(VERSION)
|
2022-09-05 12:23:17 -05:00
|
|
|
|
2022-09-05 18:02:16 -05:00
|
|
|
## c, clean | remove the generated files
|
2022-09-05 12:23:17 -05:00
|
|
|
.PHONY: clean
|
2022-09-05 18:02:16 -05:00
|
|
|
c clean:
|
2022-09-05 12:23:17 -05:00
|
|
|
@rm -f task.mk .task.mk
|
2022-09-13 16:40:07 -05:00
|
|
|
### | args: --divider
|
|
|
|
###
|
|
|
|
### examples of task.mk features | args: --divider --align center
|
|
|
|
define list_files_py
|
|
|
|
from pathlib import Path
|
|
|
|
print("files in $(2)")
|
|
|
|
print([f.name for f in (Path("$(2)").iterdir())])
|
|
|
|
endef
|
|
|
|
|
|
|
|
## list-% | use pathlib.Path to list files
|
|
|
|
### name the directory in rule (make list-src) | args: --align sep
|
|
|
|
list-%:
|
|
|
|
$(call py,list_files_py,$*)
|
2022-09-05 12:23:17 -05:00
|
|
|
|
|
|
|
.PHONY: version-check
|
|
|
|
version-check:
|
|
|
|
@if [[ "${VERSION}" == *'-'* ]]; then\
|
2022-09-05 18:02:16 -05:00
|
|
|
$(call tprint-sh,{a.red}VERSION INVALID! Uncommited Work{a.end});\
|
2022-09-05 12:23:17 -05:00
|
|
|
echo ">> version: $(VERSION)"; exit 1;\
|
|
|
|
elif [[ $(shell echo "${VERSION}" | awk -F. '{ print NF }') -lt 3 ]];then\
|
2022-09-05 18:02:16 -05:00
|
|
|
$(call tprint-sh,{a.red}VERSION INVALID! Expected CalVer string{a.end});\
|
2022-09-05 12:23:17 -05:00
|
|
|
echo ">> version: $(VERSION)"; exit 1;\
|
|
|
|
else \
|
2022-09-05 18:02:16 -05:00
|
|
|
$(call tprint-sh,{a.green}VERSION LOOKS GOOD!{a.end});\
|
2022-09-05 12:23:17 -05:00
|
|
|
fi
|
|
|
|
|
2022-09-05 18:11:37 -05:00
|
|
|
|
|
|
|
define bash_script
|
|
|
|
echo "This is from bash"
|
|
|
|
cat /etc/hostname
|
|
|
|
printf "%s\n" "$(2)"
|
|
|
|
endef
|
|
|
|
.PHONY: test-bash
|
|
|
|
test-bash:
|
|
|
|
$(call tbash,bash_script,test bash multiline)
|
|
|
|
|
2022-09-07 00:11:26 -05:00
|
|
|
define mlmsg
|
2022-09-05 18:02:16 -05:00
|
|
|
{a.b_yellow}
|
|
|
|
It can even be multiline!{a.end}
|
|
|
|
and styles can be defined{a.end}
|
|
|
|
as python {a.bold}f-string{a.end} literals
|
|
|
|
{a.end}
|
2022-09-05 12:23:17 -05:00
|
|
|
endef
|
|
|
|
|
2022-09-05 20:20:10 -05:00
|
|
|
## info | demonstrate usage of tprint
|
2022-09-05 12:23:17 -05:00
|
|
|
.PHONY: task
|
|
|
|
info:
|
2022-09-12 00:16:25 -05:00
|
|
|
$(call msg,Info Message)
|
2022-09-05 23:48:32 -05:00
|
|
|
$(call tprint,{a.black_on_cyan}This is task-print output:{a.end})
|
2022-09-07 00:11:26 -05:00
|
|
|
$(call tprint,$(mlmsg))
|
|
|
|
$(call tprint,{a.custom(fg=(148, 255, 15),bg=(103, 2, 15))}Custom Colors TOO!{a.end})
|
2022-09-05 12:23:17 -05:00
|
|
|
|
2022-09-13 16:40:07 -05:00
|
|
|
### | args: --divider
|
|
|
|
|
2022-09-07 15:48:46 -05:00
|
|
|
task.mk: $(TEMPLATES) generate.py
|
|
|
|
./generate.py $(VERSION) > task.mk
|
2022-09-05 12:23:17 -05:00
|
|
|
|
|
|
|
define USAGE
|
2022-09-05 18:02:16 -05:00
|
|
|
{a.$(HEADER_COLOR)}usage:{a.end}
|
2022-09-05 12:23:17 -05:00
|
|
|
make <recipe>
|
|
|
|
|
2022-09-05 18:02:16 -05:00
|
|
|
Turn your {a.b_magenta}`Makefile`{a.end} into
|
|
|
|
the {a.italic}{a.underline}task runner{a.end} you always needed.
|
|
|
|
See the example output below.
|
2022-09-05 12:23:17 -05:00
|
|
|
|
|
|
|
endef
|
|
|
|
|
2022-09-07 16:24:20 -05:00
|
|
|
EPILOG = \nfor more info: github.com/daylinmorgan/task.mk
|
2022-09-05 12:23:17 -05:00
|
|
|
PRINT_VARS := VERSION
|
|
|
|
|
|
|
|
-include .task.mk
|
|
|
|
.task.mk: $(TEMPLATES) generate.py
|
|
|
|
./generate.py $(VERSION) > .task.mk
|