-
Notifications
You must be signed in to change notification settings - Fork 1
/
task
executable file
·64 lines (52 loc) · 1.33 KB
/
task
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
#!/usr/bin/bash
set -e
# Set TASK_BINARY, i.e., the absolute path of this script
TASK_BINARY="$(realpath "$0")"
export TASK_BINARY
# Set TASK_ROOT_DIR, i.e., the absolute path of the root directory of the project
TASK_ROOT_DIR="$(dirname "$(realpath "$0")")"
export TASK_ROOT_DIR
# Set TASK_TASK_DIR, i.e., the absolute path of the directory in which the task is located
# Caution: Should not be used in transpiled JS
TASK_TASK_DIR="${TASK_ROOT_DIR}/tasks/${REPLACED}"
export TASK_TASK_DIR
# Set working directory
cd "$TASK_ROOT_DIR"
# Set PATH
PATH="${TASK_ROOT_DIR}/node_modules/.bin:$PATH"
export PATH
# Ensure that first argument exists
TASK="$1"
if [ -z "${TASK}" ]; then
echo "First argument must be the task to execute"
exit 1
fi
# Replace ":" with "/"
REPLACED="${TASK//://}"
# Run task.sh
TASK_SH=tasks/${REPLACED}/task.sh
if [ -f "${TASK_SH}" ]; then
bash -e ${TASK_SH} "${@:2}"
exit 0
fi
# Run task.js
TASK_JS=build-tasks/tasks/${REPLACED}/task.js
if [ -f "${TASK_JS}" ]; then
node ${TASK_JS} "${@:2}"
exit 0
fi
# Run task.ts
TASK_TS=tasks/${REPLACED}/task.ts
if [ -f "${TASK_TS}" ]; then
ts-node -r tsconfig-paths/register ${TASK_TS} "${@:2}"
exit 0
fi
# Run task.py
TASK_PY=tasks/${REPLACED}/task.py
if [ -f "${TASK_PY}" ]; then
python ${TASK_PY} "${@:2}"
exit 0
fi
# Throw
echo Did not find task "${TASK}"
exit 1