This repository has been archived by the owner on Apr 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli
66 lines (53 loc) · 1.64 KB
/
cli
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
PACKAGE_FOLDER=packages
SEPERATOR="------------------------"
trap trap_int INT
function trap_int() {
echo -e "${SEPERATOR}\n[interrupt] ${PACKAGE_INFO}"
}
echo "[monorepo] Run in Docker"
echo "${SEPERATOR}"
# throw default error
if [ -z "$1" ]; then
echo "Please state a package folder relative to '${PACKAGE_FOLDER}'."
exit 127
fi
# ls command
if [ "$1" == "ls" ]; then
npx lerna la
exit 0
fi
# check command
PACKAGES=$(npx lerna la)
PACKAGE=($(echo ${PACKAGES} | grep $1 | sed -r 's/^([^ ]*).*$/\1/'))
IS_WORKSPACE=$([[ "$1" == "root" || "$1" == "ws" ]] && echo true)
IS_FORALL=$([[ "$1" == "all" ]] && echo true)
IS_LERNA=$([[ "$1" == "lerna" ]] && echo true)
if [[ -z "${PACKAGE}" && -z "${IS_WORKSPACE}" && -z "${IS_FORALL}" && -z "${IS_LERNA}" ]]; then
echo "Can not find package in directory."
echo "${SEPERATOR}"
echo "Available packages are:"
echo "${PACKAGES}"
exit 127
fi
# where to run
if [[ ! -z "${IS_WORKSPACE}" || ! -z "${IS_FORALL}" || ! -z "${IS_LERNA}" ]]; then
PACKAGE="workspace"
WORKDIR="."
else
WORKDIR="${PACKAGE_FOLDER}/$1"
fi
# command
if [ ! -z "${IS_FORALL}" ]; then
RUN_COMMAND="npx lerna exec -- ${*:2}"
elif [ ! -z "${IS_LERNA}" ]; then
RUN_COMMAND="npx lerna ${*:2}"
else
RUN_COMMAND="${*:2}"
fi
if [ -z "${RUN_COMMAND}" ]; then
echo "Please state a command to run in '${PACKAGE}'."
exit 127
fi
PACKAGE_INFO="${PACKAGE} in ${WORKDIR} | \$ ${RUN_COMMAND}"
docker-compose exec monorepo /bin/bash -c "echo -e '[started] ${PACKAGE_INFO}\n${SEPERATOR}' && cd ${WORKDIR} && ${RUN_COMMAND} && echo -e '${SEPERATOR}\n[success] ${PACKAGE_INFO}' || echo -e '${SEPERATOR}\n[failed] ${PACKAGE_INFO}'"