2.9 KB109 lines
Blame
1#!/usr/bin/env bash
2RUN="docker compose run --rm"
3
4ansi() { echo -e "\e[${1}m${*:2}\e[0m"; }
5bold() { ansi 1 "$@"; }
6# italic() { ansi 3 "$@"; }
7underline() { ansi 4 "$@"; }
8# strikethrough() { ansi 9 "$@"; }
9red() { ansi 31 "$@"; }
10
11name=$(basename $0)
12command=$1
13args=${@:2}
14
15case $command in
16
17build)
18docker compose build $args
19;;
20
21sh)
22$RUN mermaid sh
23;;
24
25pnpm)
26$RUN mermaid sh -c "pnpm $args"
27;;
28
29dev)
30$RUN --service-ports mermaid sh -c "pnpm run dev"
31;;
32
33docs:dev)
34$RUN --service-ports mermaid sh -c "pnpm run --filter mermaid docs:dev:docker"
35;;
36
37cypress)
38$RUN cypress $args
39;;
40
41help|"")
42
43# Alignment of help message must be as it is, it will be nice looking when printed
44usage=$(
45cat <<EOF
46
47$(bold MERMAID LOCAL DOCKER DEVELOPMENT)
48
49Welcome! Thank you for joining the development.
50This is a script for running commands within docker containers at ease.
51__________________________________________________________________________________________
52
53Development 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
64Commands:
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
75Examples 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
95EOF
96)
97
98echo -n -e "$usage"
99;;
100
101*)
102message="$(red Unknown command: $command). See $(bold ./$name help) for available commands."
103echo -n -e "$message\n" >&2
104$0 help
105exit 1
106;;
107
108esac
109