-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sh
98 lines (77 loc) · 1.98 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/bash
set -e
BUILD_DIR="./build"
ZIP_FILE="./build.zip"
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Install git if not present
if ! command_exists git; then
sudo apt-get update
sudo apt-get install -y git
fi
git submodule init
git submodule update --init --recursive
# Install nvm and Node.js
install_nvm_and_node() {
echo "Installing NVM..."
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
export NVM_DIR="$HOME/.nvm"
if [ -s "$NVM_DIR/nvm.sh" ]; then
source "$NVM_DIR/nvm.sh"
else
echo "nvm.sh not found. Exiting."
exit 1
fi
if [ -s "$NVM_DIR/bash_completion" ]; then
source "$NVM_DIR/bash_completion"
fi
echo "Installing Node.js version 23..."
nvm install 23
nvm use 23
# Verify installations
echo "NVM version:"
nvm --version
echo "Node version:"
node --version
echo "NPM version:"
npm --version
}
# Check if Node.js and NPM are installed
if command_exists node && command_exists npm; then
echo "Node and NPM are already installed."
node --version
npm --version
else
echo "Node or NPM not found. Attempting to install via NVM."
install_nvm_and_node
fi
# Clean build directory and zip file if they exist from previous run
if [ -d "$BUILD_DIR" ]; then
rm -rf "$BUILD_DIR"
fi
if [ -f "$ZIP_FILE" ]; then
rm -f "$ZIP_FILE"
fi
# Install npm dependencies and build the project
npm install
# npm run test # TODO: Enable when destamatic tests are working
npx vite build
# Prepare build directory
mkdir -p "$BUILD_DIR"
# Copy files to build directory
cp -r ./backend "$BUILD_DIR"
cp -r ./destam-web-core "$BUILD_DIR"
cp -r ./destamatic-ui "$BUILD_DIR"
cp -r ./node_modules "$BUILD_DIR"
cp ./package.json "$BUILD_DIR"
cp ./package-lock.json "$BUILD_DIR"
# Create the run script the service will use
cat << 'EOF' > "$BUILD_DIR/run.sh"
#!/bin/bash
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
. ~/.nvm/nvm.sh use 23
node "$SCRIPT_DIR/backend/index.js"
EOF
chmod +x "$BUILD_DIR/run.sh"
zip -r "$ZIP_FILE" "$BUILD_DIR"