-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·63 lines (54 loc) · 1.97 KB
/
build.sh
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
#!/bin/bash
# Определяем директории исходников и вывода
SRC_DIR="./src"
OUT_DIR="./dist"
# Создаем директорию вывода, если она не существует
mkdir -p "$OUT_DIR"
# Функция для компиляции файлов TypeScript
compile() {
echo "Компиляция файлов TypeScript из $SRC_DIR в $OUT_DIR..."
tsc --project tsconfig.json --outDir "$OUT_DIR" --target ESNext
# Проверяем, успешна ли компиляция
if [ $? -eq 0 ]; then
echo "Компиляция завершена успешно."
else
echo "Компиляция завершилась неудачно."
exit 1
fi
}
# Функция для запуска скомпилированных JavaScript файлов
run() {
# Запускаем сервер
if [ -f "$OUT_DIR/server.js" ]; then
echo "Запуск сервера..."
node "$OUT_DIR/server.js" &
SERVER_PID=$! # Сохраняем PID сервера
echo "Сервер запущен с PID $SERVER_PID."
# Ожидаем некоторое время, чтобы убедиться, что сервер запущен
sleep 2 # Задержка в 2 секунды
# Ожидаем завершения работы сервера
wait $SERVER_PID
else
echo "Ошибка: файл $OUT_DIR/server.js не найден."
exit 1
fi
}
# Функция для остановки сервера
stop() {
if [ -n "$SERVER_PID" ]; then
echo "Остановка сервера с PID $SERVER_PID..."
kill $SERVER_PID
echo "Сервер остановлен."
else
echo "Сервер не запущен."
fi
}
# Проверяем наличие аргумента --run
if [ "$1" == "--run" ]; then
compile
run
elif [ "$1" == "--stop" ]; then
stop
else
compile
fi