-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·70 lines (54 loc) · 2.75 KB
/
install.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
#!/bin/bash
set -exuo pipefail
# Select which Cornerstone3D release to download
# Defaults to the version listed in package.json
CORNERSTONE_VERSION="${CORNERSTONE_VERSION:-v$(grep -o '@cornerstonejs/core[^,]*' package.json | grep -o '[0-9.]*')}"
##
## Required dependencies (apt install):
##
## - build-essential (yarn install uses node-gyp which will require make)
## - curl
## - nodejs & yarn (corepack enable)
##
# Build in a temp directory
OUTDIR=$PWD/build
BUILDDIR=/tmp/cnsbuilder
cd /tmp
mkdir -p $BUILDDIR
cd $BUILDDIR
rm -rf cornerstone
# Download and extract the Cornerstone3D library
curl -L "https://github.com/cornerstonejs/cornerstone3D/archive/refs/tags/$CORNERSTONE_VERSION.tar.gz" | \
tar -xz --one-top-level=cornerstone --strip-components=1
# Install dependencies
cd cornerstone
# Ensure we have yarn classic installed
corepack enable && corepack prepare [email protected] --activate
# Remove the docs package completely, saving us a "yarn workspace docs remove puppeteer"
# but also because otherwise the shallow install with --non-interactive will fail complaining about versions
rm -rf packages/docs
# Remove non-essential dependencies that cause CI build failures on arm64
# - `puppeteer` tries to install Chrome
# - `resemblejs` pulls in `canvas` on node which has native deps not available for arm64
# - `netlify-cli` pulls in `unix-dgram` which also fails the gyp build
# - `lerna` pulls in `@parcel/watcher` which doesn't seem to fail the build but worth removing still just in case
yarn remove -W resemblejs puppeteer netlify-cli lerna
# The --focus parameter lets us install only this one workspace
cd packages/dicomImageLoader
yarn install --focus --non-interactive --ignore-scripts
# Patches the `decodeImageFrame` import in `createImage` to load the `noWorkers` version
sed -i.old -e "s|from './decodeImageFrame'|from './decodeImageFrame-noWorkers'|" ./src/imageLoader/createImage.ts
# Patches `decodeJPEGBaseline8BitColor.ts` to not use the `this` object inside the `onload` handler
# Node-canvas' Image polyfill does not attach the correct context to the callback function when it calls it
sed -i.old -e "s|drawImage(this as any|drawImage(img as any|" ./src/imageLoader/decodeJPEGBaseline8BitColor.ts
# We patch to remove the workered bundle entrypoint from the default build
# to avoid split chunks and reduce build time
sed -i -e "s|cornerstoneDICOMImageLoader: './imageLoader/index.ts',||" ./.webpack/webpack-bundle.js
# This means we don't have to run a custom command either
yarn run webpack:bundle
# Copy the built asset back into the app directory
mkdir -p $OUTDIR
echo '*' > $OUTDIR/.gitignore
cp $BUILDDIR/cornerstone/packages/dicomImageLoader/dist/cornerstoneDICOMImageLoaderNoWebWorkers.bundle.min.js $OUTDIR/cornerstoneImageLoader.js
# Cleanup
rm -rf $BUILDDIR