chore: Refactor Makefile and example config files

This commit is contained in:
Vikash Kothary 2022-01-16 21:58:25 +00:00
parent baa0610370
commit 62c6e1a5a1
2 changed files with 39 additions and 31 deletions

View File

@ -1,45 +1,44 @@
#/bin/make
#!/usr/bin/env make
ANKI_SERVER_NAME ?= "Anki Sync Server"
ANKI_SERVER_VERSION ?= "v0.1.0"
ANKI_SERVER_DESCRIPTION ?= "Self-hosted Anki Sync Server."
ANKISYNCD_NAME ?= Anki Sync Server
ANKISYNCD_VERSION ?= v2.2.0
ANKISYNCD_DESCRIPTION ?= Self-hosted Anki Sync Server.
ENV ?= local
-include config/.env.${ENV}
-include config/secrets/.env.*.${ENV}
export
.DEFAULT_GOAL := help
.PHONY: help #: Display list of command and exit.
help:
@awk 'BEGIN {FS = " ?#?: "; print ""${ANKI_SERVER_NAME}" "${ANKI_SERVER_VERSION}"\n"${ANKI_SERVER_DESCRIPTION}"\n\nUsage: make \033[36m<command>\033[0m\n\nCommands:"} /^.PHONY: ?[a-zA-Z_-]/ { printf " \033[36m%-10s\033[0m %s\n", $$2, $$3 }' $(MAKEFILE_LIST)
@${AWK} 'BEGIN {FS = " ?#?: "; print "${ANKISYNCD_NAME} ${ANKISYNCD_VERSION}\n${ANKISYNCD_DESCRIPTION}\n\nUsage: make \033[36m<command>\033[0m\n\nCommands:"} /^.PHONY: ?[a-zA-Z_-]/ { printf " \033[36m%-10s\033[0m %s\n", $$2, $$3 }' $(MAKEFILE_LIST)
.PHONY: docs #: Build and serve documentation.
docs: print-env
@${PYTHON} -m mkdocs ${MKDOCS_OPTION} -f docs/mkdocs.yml
docs:
@${MKDOCS} ${MKDOCS_CMD} -f docs/mkdocs.yml ${MKDOCS_OPTS}
.PHONY: tests #: Run unit tests.
tests:
@${PYTHON} -m unittest discover -s tests
@${UNITTEST} discover -s tests
.PHONY: run
run:
@${PYTHON} -m ankisyncd
@${PYTHON} src/ankisyncd/__main__.py
# Run scripts using make
%:
@test -f scripts/${*}.sh
@${BASH} scripts/${*}.sh
@if [[ -f "scripts/${*}.sh" ]]; then \
${BASH} "scripts/${*}.sh"; fi
.PHONY: init #: Download Python dependencies.
init:
@${POETRY} install
%:
@test -f scripts/${*}.sh
@${SHELL} scripts/${*}.sh
.PHONY: release #: Tag and deploy to PyPI.
.PHONY: release #: Create new Git release and tags.
release:
@${SHELL} scripts/release.sh
@${BASH} scripts/release.sh
.PHONY: open
open:
@${OPEN} http://127.0.0.1:27701
@${OPEN} ${ANKISYNCD_URL}

View File

@ -1,9 +1,5 @@
# .env.example (anki-sync-server)
## Make
POETRY=poetry
PYTHON=poetry run python
BASH=bash
# file: .env.example (ankisyncd)
# cp config/.env.example config/.env.local
## Ankisyncd
ANKISYNCD_HOST=0.0.0.0
@ -13,18 +9,31 @@ ANKISYNCD_BASE_URL=/sync/
ANKISYNCD_BASE_MEDIA_URL=/msync/
ANKISYNCD_AUTH_DB_PATH=./auth.db
ANKISYNCD_SESSION_DB_PATH=./session.db
# ANKISYNCD_FULL_SYNC_MANAGER
# ANKISYNCD_SESSION_MANAGER
# ANKISYNCD_USER_MANAGER
# ANKISYNCD_COLLECTION_WRAPPER
### ANKISYNCD_FULL_SYNC_MANAGER
### ANKISYNCD_SESSION_MANAGER
### ANKISYNCD_USER_MANAGER
### ANKISYNCD_COLLECTION_WRAPPER
ANKISYNCD_URL=http://${ANKISYNCD_HOST}:${ANKISYNCD_PORT}
## Mkdocs
MKDOCS_OPTION=serve
MKDOCS_HOST=localhost
MKDOCS_PORT=5000
MKDOCS_OPTS=-a ${MKDOCS_HOST}:${MKDOCS_PORT}
MKDOCS_CMD=serve
## Jupyter
### JUPYTER_CMD
### JUPYTER_NOTEBOOK_DIR
## Path
## Make
AWK=awk
BASH=bash
POETRY=poetry
PYTHON=python
MKDOCS=mkdocs
JUPYTER=jupyter
UNITTEST=python -m unittest
## Shell
SHELL=${BASH}
PATH:=.venv/bin:${PATH}