Files
Odoo-Build/templates/task
T

111 lines
2.8 KiB
Bash
Executable File

#!/bin/bash
set -e
if [[ -a ".env" ]]; then
source .env
fi
function help-table() {
CMD_WIDTH=10
OPT_WIDTH=6
DESC_WIDTH=40
COLUMN="| %-${CMD_WIDTH}s | %-${OPT_WIDTH}s | %-${DESC_WIDTH}s |\n"
printf "$COLUMN" "Command" "Option" "Description"
echo "|$(printf '%*s' $((CMD_WIDTH + 2)) '' | tr ' ' '-')|$(printf '%*s' $((OPT_WIDTH + 2)) '' | tr ' ' '-')|$(printf '%*s' $((DESC_WIDTH + 2)) '' | tr ' ' '-')|"
printf "$COLUMN" "all" "" "Run all tasks."
printf "$COLUMN" "install" "" "Setup the local environment."
printf "$COLUMN" "lint" "" "Run pre-commit."
printf "$COLUMN" "docs" "" "Update index.html."
printf "$COLUMN" "source" "" "Source the Python virtual env."
printf "$COLUMN" "version" "" "Show version of required tools."
}
function help() {
echo
if [ -n "$1" ]; then
help-table | grep -i "$1" | column -t -s'|'
else
echo "task <command> [options]"
echo
echo "commands:"
echo
help-table
fi
echo
}
if [ -d "$HOME/taskfile.build/bin" ]; then
for file in "$HOME/taskfile.build/bin/"*; do
if [ -f "$file" ]; then
source "$file"
fi
done
fi
function version() {
uv --version
}
function install() {
echo "Setup venv and install python dependencies"
uv venv env
source env/bin/activate
uv pip install pre-commit rst2html5
}
function lint() {
source env/bin/activate
echo "Run pre-commit"
pre-commit run --all-files --show-diff-on-failure --color=always
}
function docs() {
source env/bin/activate
echo "Update index.html for all modules"
for MODULE in ./*; do
if [ -f "$MODULE/README.rst" ]; then
cd "$MODULE" || exit
rst2html5 README.rst static/description/index.html
cd .. || exit
fi
done
# Find marker in readme and clear content after
echo "Clear modules table in README.md"
MARKER="## Available modules"
sed -i "/$MARKER/Q" "README.md"
echo "$MARKER" >> "README.md"
echo "" >> "README.md"
echo "| Module | Summary |" >> "README.md"
echo "| --- | --- |" >> "README.md"
MANIFEST_FILES="./*/__manifest__.py"
for MANIFEST_FILE in $MANIFEST_FILES; do
MODULE_DIR=$(dirname "$MANIFEST_FILE")
MODULE_NAME=$(basename "$MODULE_DIR")
echo "Add summary of $MODULE_NAME to readme file."
SUMMARY=$(grep 'summary' "$MANIFEST_FILE" -A 1 | tail -1)
echo "| [$MODULE_NAME]($MODULE_NAME) | $SUMMARY |" >> "README.md"
done
}
if declare -f "$1" > /dev/null; then
"$1" "${@:2}"
else
case "$1" in
all)
install
lint
docs
;;
*)
echo "Unknown command: $1"
help task
exit 1
;;
esac
fi