task.mk/Makefile

89 lines
2.8 KiB
Makefile
Raw Normal View History

2023-01-19 13:43:29 -06:00
VERSION ?= $(shell git describe --tags --always --dirty=dev)
2022-09-05 12:23:17 -05:00
TEMPLATES := $(shell find src/ -type f)
.DEFAULT_GOAL := help
msg = $(if $(tprint),$(call tprint,{a.bold}==> {a.magenta}$(1){a.end}),@echo '==> $(1)')
2022-09-05 12:23:17 -05:00
2023-01-19 12:54:57 -06:00
### task.mk development |> -d -ms b_green --align center
## bootstrap | generate local dev environment |> -ms b_magenta -gs b_cyan
2022-09-22 10:49:14 -05:00
.PHONY: bootstrap env hooks
bootstrap: env hooks
env:
$(call msg,Bootstrapping Environment)
@mamba create -p ./env python jinja2 black -y
@mamba run -p ./env pip install yartsu
2022-09-22 10:49:14 -05:00
hooks:
2022-09-07 15:48:46 -05:00
@git config core.hooksPath .githooks
2022-09-24 17:55:52 -05:00
docs-env:
@mamba run -p ./env pip install mkdocs-material mkdocs-git-revision-date-localized-plugin
2023-01-19 12:54:57 -06: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
## assets | generate assets
.PHONY: assets
assets:
2022-09-14 00:03:29 -05:00
@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)
2023-01-19 13:43:29 -06:00
@./generate.py $(subst v,,$(VERSION)) > task.mk
@sed -i 's/task.mk\/.*\/task.mk/task.mk\/$(VERSION)\/task.mk/g' README.md
@sed -i 's/task.mk\/.*\/task.mk/task.mk\/$(VERSION)\/task.mk/g' docs/index.md
2022-09-19 00:11:03 -05:00
@git add task.mk README.md docs/index.md
2023-01-19 13:43:29 -06:00
@git commit -m "release: $(VERSION)" --no-verify
2022-09-07 00:15:21 -05:00
@git tag v$(VERSION)
2022-09-05 12:23:17 -05:00
## c, clean | remove the generated files
2022-09-05 12:23:17 -05:00
.PHONY: clean
c clean:
2022-09-05 12:23:17 -05:00
@rm -f task.mk .task.mk
2022-09-14 00:03:29 -05:00
2023-01-19 13:43:29 -06:00
define version_check_sh
if [[ "${VERSION}" == *'-'* ]]; then
$(call tprint-sh,{a.red}VERSION INVALID! Uncommited or untagged work{a.end})
exit 1
elif [[ $(shell echo "${VERSION}" | awk -F. '{ print NF }') -lt 3 ]];then\
$(call tprint-sh,{a.red}VERSION INVALID! Uncommited or untagged work{a.end})
$(call tprint-sh,{a.red}VERSION INVALID! Expected CalVer string{a.end})
exit 1
fi
endef
2022-09-05 12:23:17 -05:00
.PHONY: version-check
version-check:
2023-01-19 13:43:29 -06:00
@$(call tprint,>> version: {a.green}$(VERSION){a.end})
@$(call tbash,version_check_sh)
@$(call tprint,>> {a.green}VERSION LOOKS GOOD!{a.end})
2022-09-05 12:23:17 -05:00
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-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
{a.style('usage','header')}:\n make <recipe>\n
2022-09-13 18:51:01 -05:00
Turn your {a.style('`Makefile`','b_magenta')} into
the {a.italic}{a.underline}task runner{a.end} you always needed.
2022-09-19 00:20:48 -05:00
See the example output below.\n
2022-09-05 12:23:17 -05:00
endef
2022-09-18 10:00:53 -05:00
EPILOG = \nfor more info: gh.dayl.in/task.mk
PRINT_VARS := VERSION SHELL
2022-09-05 12:23:17 -05:00
-include .task.mk
.task.mk: $(TEMPLATES) generate.py
$(call msg,re-jinjaing the local .task.mk)
2022-09-14 13:49:25 -05:00
@./generate.py $(VERSION) > .task.mk || (echo "generator failed!!" && rm .task.mk)