Files
Odoo-Wiki/task
T

115 lines
2.9 KiB
Bash
Executable File

#!/bin/bash
set -e
if [[ -a ".env" ]]; then
export $(cat .env | sed 's/^#.*//g' | xargs)
fi
function help() {
echo
echo "task <command> [options]"
echo
echo "commands:"
echo
CMD_WIDTH=20
OPT_WIDTH=6
DESC_WIDTH=40
COLUMN="| %-${CMD_WIDTH}s | %-${OPT_WIDTH}s | %-${DESC_WIDTH}s |\n"
# Print table header
printf "$COLUMN" "Command" "Option" "Description"
echo "|$(printf '%*s' $((CMD_WIDTH + 2)) '' | tr ' ' '-')|$(printf '%*s' $((OPT_WIDTH + 2)) '' | tr ' ' '-')|$(printf '%*s' $((DESC_WIDTH + 2)) '' | tr ' ' '-')|"
# Print table rows
printf "$COLUMN" "install" "" "Install build dependencies."
printf "$COLUMN" "build" "" "Build project."
printf "$COLUMN" "dev-vuepress" "" "Start vuepress development server."
printf "$COLUMN" "build-vuepress" "" "Create vuepress build."
printf "$COLUMN" "serve-vuepress" "" "Serve vuepress build."
printf "$COLUMN" "download-icons" "" "Download module icons from Odoo assets."
printf "$COLUMN" "update-repo-url" "" "Check and update repository urls."
echo
}
function update-repo-url() {
VERSIONS=("14.0" "15.0" "16.0" "17.0")
TOTAL_FILES=$(find . -maxdepth 1 -name "*.md" -type f | wc -l)
FILE_COUNT=0
find . -maxdepth 1 -name "*.md" -type f -print0 | while IFS= read -r -d '' FILE; do
FILE_COUNT=$((FILE_COUNT+1))
echo "Processing file '$FILE' ($FILE_COUNT/$TOTAL_FILES)"
LINK=$(grep -Eom 1 'Repository: <https://github.com/[^>]*>' "$FILE" || echo "")
if [[ -n "$LINK" ]]; then
REPO_URL=$(echo "$LINK" | grep -oP 'https://github.com/\K[^>]*')
NEWEST_URL=""
for VERSION in "${VERSIONS[@]}"; do
NEW_URL="https://github.com/$(echo "$REPO_URL" | sed -E "s|tree/[0-9]+\.[0-9]+|tree/$VERSION|")"
HTTP_STATUS=$(curl -o /dev/null -s -w "%{http_code}" "$NEW_URL")
# echo "Response for version $VERSION is $HTTP_STATUS"
if [[ "$HTTP_STATUS" == "200" ]]; then
NEWEST_URL="$NEW_URL"
fi
done
if [[ -n "$NEWEST_URL" ]]; then
echo "Update file '$FILE' with url: '$NEWEST_URL"
UPDATED_LINE="Repository: <$NEWEST_URL>"
sed -i "s|$LINK|$UPDATED_LINE|" "$FILE"
fi
fi
done
}
function install() {
pnpm install
}
function build() {
node build.js
}
function dev-vuepress() {
pnpm run dev
}
function build-vuepress() {
pnpm run vuepress-build
}
function serve-vuepress() {
cd ./src/.vuepress/dist
npx serve
}
function download-icons() {
pnpm run download-icons
}
if declare -f "$1" > /dev/null; then
"$1" "${@:2}"
else
case "$1" in
*)
echo "Unknown command: $1"
help
exit 1
;;
esac
fi