mermaid/run

109 lines
2.9 KiB
Plaintext
Raw Permalink Normal View History

2024-02-04 18:30:51 +01:00
#!/usr/bin/env bash
RUN="docker compose run --rm"
2023-06-18 00:32:45 +02:00
ansi() { echo -e "\e[${1}m${*:2}\e[0m"; }
bold() { ansi 1 "$@"; }
# italic() { ansi 3 "$@"; }
underline() { ansi 4 "$@"; }
# strikethrough() { ansi 9 "$@"; }
2024-02-04 18:30:51 +01:00
red() { ansi 31 "$@"; }
2023-06-18 00:32:45 +02:00
name=$(basename $0)
command=$1
args=${@:2}
case $command in
build)
docker compose build $args
;;
sh)
2024-01-13 23:05:47 +01:00
$RUN mermaid sh
;;
2023-06-27 13:11:06 +02:00
pnpm)
$RUN mermaid sh -c "pnpm $args"
;;
2023-06-18 00:32:45 +02:00
dev)
$RUN --service-ports mermaid sh -c "pnpm run dev"
2023-06-25 00:18:38 +02:00
;;
docs:dev)
2024-01-13 23:07:37 +01:00
$RUN --service-ports mermaid sh -c "pnpm run --filter mermaid docs:dev:docker"
2023-06-18 00:32:45 +02:00
;;
cypress)
$RUN cypress $args
;;
2024-02-04 18:30:51 +01:00
help|"")
2023-06-29 18:51:46 +02:00
# Alignment of help message must be as it is, it will be nice looking when printed
2023-06-18 00:32:45 +02:00
usage=$(
cat <<EOF
2023-06-27 13:11:06 +02:00
$(bold MERMAID LOCAL DOCKER DEVELOPMENT)
Welcome! Thank you for joining the development.
This is a script for running commands within docker containers at ease.
__________________________________________________________________________________________
Development Quick Start Guide:
$(bold ./$name pnpm install) # Install packages
$(bold ./$name dev) # Launch dev server with examples, open http://localhost:9000
$(bold ./$name docs:dev) # Launch official website, open http://localhost:3333
$(bold ./$name pnpm vitest) # Run watcher for unit tests
$(bold ./$name cypress) # Run integration tests (after starting dev server)
$(bold ./$name pnpm build) # Prepare it for production
__________________________________________________________________________________________
2023-06-18 00:32:45 +02:00
2023-06-27 13:11:06 +02:00
Commands:
$(bold ./$name build) # Build image
$(bold ./$name cypress) # Run integration tests
$(bold ./$name dev) # Run dev server with examples, open http://localhost:9000
$(bold ./$name docs:dev) # For docs contributions, open http://localhost:3333
$(bold ./$name help) # Show this help
$(bold ./$name pnpm) # Run any 'pnpm' command
$(bold ./$name sh) # Open 'sh' inside docker container for development
__________________________________________________________________________________________
2023-06-27 13:11:06 +02:00
Examples of frequently used commands:
2023-06-27 13:11:06 +02:00
$(bold ./$name pnpm add --filter mermaid) $(underline package)
Add package to mermaid
2024-01-05 19:05:10 +01:00
$(bold ./$name pnpm -w run lint:fix)
Run prettier and ES lint
$(bold git diff --name-only develop \| xargs ./$name pnpm prettier --write)
Prettify everything you added so far
$(bold ./$name cypress open --project .)
Open cypress interactive GUI
$(bold ./$name cypress run --spec cypress/integration/rendering/)$(underline test.spec.ts)
Run specific test in cypress
$(bold xhost +local:)
Allow local connections for x11 server
EOF
2023-06-18 00:32:45 +02:00
)
echo -n -e "$usage"
;;
*)
2024-02-04 18:30:51 +01:00
message="$(red Unknown command: $command). See $(bold ./$name help) for available commands."
echo -n -e "$message\n" >&2
$0 help
exit 1
;;
2023-06-19 03:34:41 +02:00
esac