| 1 | #!/usr/bin/env bash |
| 2 | RUN="docker compose run --rm" |
| 3 | |
| 4 | ansi() { echo -e "\e[${1}m${*:2}\e[0m"; } |
| 5 | bold() { ansi 1 "$@"; } |
| 6 | # italic() { ansi 3 "$@"; } |
| 7 | underline() { ansi 4 "$@"; } |
| 8 | # strikethrough() { ansi 9 "$@"; } |
| 9 | red() { ansi 31 "$@"; } |
| 10 | |
| 11 | name=$(basename $0) |
| 12 | command=$1 |
| 13 | args=${@:2} |
| 14 | |
| 15 | case $command in |
| 16 | |
| 17 | build) |
| 18 | docker compose build $args |
| 19 | ;; |
| 20 | |
| 21 | sh) |
| 22 | $RUN mermaid sh |
| 23 | ;; |
| 24 | |
| 25 | pnpm) |
| 26 | $RUN mermaid sh -c "pnpm $args" |
| 27 | ;; |
| 28 | |
| 29 | dev) |
| 30 | $RUN --service-ports mermaid sh -c "pnpm run dev" |
| 31 | ;; |
| 32 | |
| 33 | docs:dev) |
| 34 | $RUN --service-ports mermaid sh -c "pnpm run --filter mermaid docs:dev:docker" |
| 35 | ;; |
| 36 | |
| 37 | cypress) |
| 38 | $RUN cypress $args |
| 39 | ;; |
| 40 | |
| 41 | help|"") |
| 42 | |
| 43 | # Alignment of help message must be as it is, it will be nice looking when printed |
| 44 | usage=$( |
| 45 | cat <<EOF |
| 46 | |
| 47 | $(bold MERMAID LOCAL DOCKER DEVELOPMENT) |
| 48 | |
| 49 | Welcome! Thank you for joining the development. |
| 50 | This is a script for running commands within docker containers at ease. |
| 51 | __________________________________________________________________________________________ |
| 52 | |
| 53 | Development Quick Start Guide: |
| 54 | |
| 55 | $(bold ./$name pnpm install) # Install packages |
| 56 | $(bold ./$name dev) # Launch dev server with examples, open http://localhost:9000 |
| 57 | $(bold ./$name docs:dev) # Launch official website, open http://localhost:3333 |
| 58 | |
| 59 | $(bold ./$name pnpm vitest) # Run watcher for unit tests |
| 60 | $(bold ./$name cypress) # Run integration tests (after starting dev server) |
| 61 | $(bold ./$name pnpm build) # Prepare it for production |
| 62 | __________________________________________________________________________________________ |
| 63 | |
| 64 | Commands: |
| 65 | |
| 66 | $(bold ./$name build) # Build image |
| 67 | $(bold ./$name cypress) # Run integration tests |
| 68 | $(bold ./$name dev) # Run dev server with examples, open http://localhost:9000 |
| 69 | $(bold ./$name docs:dev) # For docs contributions, open http://localhost:3333 |
| 70 | $(bold ./$name help) # Show this help |
| 71 | $(bold ./$name pnpm) # Run any 'pnpm' command |
| 72 | $(bold ./$name sh) # Open 'sh' inside docker container for development |
| 73 | __________________________________________________________________________________________ |
| 74 | |
| 75 | Examples of frequently used commands: |
| 76 | |
| 77 | $(bold ./$name pnpm add --filter mermaid) $(underline package) |
| 78 | Add package to mermaid |
| 79 | |
| 80 | $(bold ./$name pnpm -w run lint:fix) |
| 81 | Run prettier and ES lint |
| 82 | |
| 83 | $(bold git diff --name-only develop \| xargs ./$name pnpm prettier --write) |
| 84 | Prettify everything you added so far |
| 85 | |
| 86 | $(bold ./$name cypress open --project .) |
| 87 | Open cypress interactive GUI |
| 88 | |
| 89 | $(bold ./$name cypress run --spec cypress/integration/rendering/)$(underline test.spec.ts) |
| 90 | Run specific test in cypress |
| 91 | |
| 92 | $(bold xhost +local:) |
| 93 | Allow local connections for x11 server |
| 94 | |
| 95 | EOF |
| 96 | ) |
| 97 | |
| 98 | echo -n -e "$usage" |
| 99 | ;; |
| 100 | |
| 101 | *) |
| 102 | message="$(red Unknown command: $command). See $(bold ./$name help) for available commands." |
| 103 | echo -n -e "$message\n" >&2 |
| 104 | $0 help |
| 105 | exit 1 |
| 106 | ;; |
| 107 | |
| 108 | esac |
| 109 | |