-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathentrypoint.sh
More file actions
85 lines (69 loc) · 2.22 KB
/
entrypoint.sh
File metadata and controls
85 lines (69 loc) · 2.22 KB
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
#!/usr/bin/env sh
set -e
APP_DIR="/opt/app"
SRC_LIB="$APP_DIR/src/lib"
DIST_LIB="$APP_DIR/dist/lib"
mkdir -p "$SRC_LIB"
mkdir -p "$DIST_LIB"
if [ -n "$MODULES" ]; then
echo "Requested modules: $MODULES"
IFS=','
for repo in $MODULES; do
CLEAN_REPO=$(echo "$repo" | cut -d'#' -f1)
NAME=$(basename "$CLEAN_REPO")
VERSION=$(echo "$repo" | grep -o '#.*' | sed 's/#//')
SRC_DEST="$SRC_LIB/$NAME"
DIST_DEST="$DIST_LIB/$NAME"
# -----------------------------
# 1️⃣ Download source if missing
# -----------------------------
if [ -d "$SRC_DEST" ]; then
echo "✔ Module $NAME already downloaded"
else
echo "⬇ Downloading module: $NAME"
git clone --depth=1 "https://github.com/$CLEAN_REPO.git" "$SRC_DEST"
if [ -n "$VERSION" ]; then
git -C "$SRC_DEST" fetch --tags
git -C "$SRC_DEST" checkout "$VERSION"
fi
fi
# -----------------------------
# 2️⃣ Install plugin dependencies (isolated)
# -----------------------------
if [ -f "$SRC_DEST/package.json" ] && [ ! -d "$SRC_DEST/node_modules" ]; then
echo "📦 Installing dependencies for $NAME (isolated)"
cd "$SRC_DEST"
npm install --production
cd "$APP_DIR"
fi
# -----------------------------
# 3️⃣ Build or copy plugin
# -----------------------------
if [ -f "$DIST_DEST/.built" ]; then
echo "🏁 Plugin $NAME already built"
continue
fi
echo "🔧 Building plugin: $NAME"
mkdir -p "$DIST_DEST"
# TypeScript project
if [ -f "$SRC_DEST/tsconfig.json" ]; then
npx tsc --project "$SRC_DEST/tsconfig.json" --outDir "$DIST_DEST"
# Single TS file
elif [ -f "$SRC_DEST/index.ts" ]; then
npx tsc "$SRC_DEST/index.ts" --outDir "$DIST_DEST"
# Plain JS project
else
cp -r "$SRC_DEST"/* "$DIST_DEST/"
fi
# -----------------------------
# 4️⃣ Copy plugin's node_modules to dist
# -----------------------------
if [ -d "$SRC_DEST/node_modules" ]; then
echo "📦 Copying isolated dependencies for $NAME"
cp -r "$SRC_DEST/node_modules" "$DIST_DEST/"
fi
# Mark as built to avoid rebuilding every restart
touch "$DIST_DEST/.built"
done
fi
exec "$@"