-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild-app.sh
More file actions
executable file
·72 lines (61 loc) · 2.62 KB
/
Copy pathbuild-app.sh
File metadata and controls
executable file
·72 lines (61 loc) · 2.62 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
#!/usr/bin/env bash
# Bundle the whole studio into one servable app:
# Mapr3D plugin -> GeoLibre app -> backend/mapr3d/static
# After this, `./run.sh` serves the UI and the API from a single process/port.
#
# GeoLibre is a build-time dependency only; set GEOLIBRE_DIR to use an existing
# checkout, otherwise it is cloned next to this repo.
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
GEOLIBRE="${GEOLIBRE_DIR:-$(dirname "$ROOT")/GeoLibre}"
STATIC="$ROOT/backend/mapr3d/static"
command -v npm >/dev/null 2>&1 || { echo "error: npm not found (install Node.js)"; exit 1; }
command -v git >/dev/null 2>&1 || { echo "error: git not found"; exit 1; }
echo "Mapr3D — bundling the app"
echo " GeoLibre: $GEOLIBRE"
if [ ! -d "$GEOLIBRE/.git" ]; then
echo "→ Cloning GeoLibre…"
git clone --depth 1 https://github.com/opengeos/GeoLibre.git "$GEOLIBRE"
fi
if [ ! -d "$GEOLIBRE/node_modules" ]; then
echo "→ Installing GeoLibre dependencies (this takes a few minutes)…"
(cd "$GEOLIBRE" && npm install --no-audit --no-fund)
fi
echo "→ Building the Mapr3D plugin…"
if [ ! -d "$ROOT/plugin/node_modules" ]; then
(cd "$ROOT/plugin" && npm install --no-audit --no-fund)
fi
(cd "$ROOT/plugin" && npm run build)
echo "→ Installing the plugin into GeoLibre…"
GEOLIBRE_DIR="$GEOLIBRE" "$ROOT/plugin/scripts/install-into-geolibre.sh"
echo "→ Building the GeoLibre app (this takes a few minutes)…"
(cd "$GEOLIBRE" && npm run build)
DIST="$GEOLIBRE/apps/geolibre-desktop/dist"
[ -f "$DIST/index.html" ] || { echo "error: GeoLibre build produced no index.html at $DIST"; exit 1; }
echo "→ Copying app into the backend…"
rm -rf "$STATIC"
mkdir -p "$STATIC"
cp -R "$DIST/." "$STATIC/"
# GeoLibre's web build ships a PWA service worker that precaches the app. That
# is wrong for Mapr3D: we serve locally from disk, so offline caching buys
# nothing but serves stale plugin bundles after a rebuild (and can wedge the app
# on a partial cache). Replace it with a stub that uninstalls itself and any
# caches a previous build left behind.
rm -f "$STATIC"/workbox-*.js
cat > "$STATIC/sw.js" <<'SW'
// Mapr3D: no-op service worker that removes any previously installed one.
self.addEventListener("install", () => self.skipWaiting());
self.addEventListener("activate", (event) => {
event.waitUntil(
(async () => {
for (const key of await caches.keys()) await caches.delete(key);
await self.registration.unregister();
for (const client of await self.clients.matchAll({ type: "window" })) {
client.navigate(client.url);
}
})(),
);
});
SW
echo ""
echo "Done. Start everything with: ./run.sh"