-
Notifications
You must be signed in to change notification settings - Fork 2
/
package_postinstall.sh
executable file
·66 lines (50 loc) · 2.52 KB
/
package_postinstall.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
#!/usr/bin/env bash
## package.json postinstall script
set -euo pipefail
## ag-grid css
src5=$(node -e 'console.log(require.resolve("ag-grid-community/styles/ag-grid.css"))')
src6=$(node -e 'console.log(require.resolve("ag-grid-community/styles/ag-grid-no-native-widgets.css"))')
YEL='\033[0;33m'
NOC='\033[0m'
yellow() {
printf "${YEL}${1:-}${NOC}\n"
}
yellow "$src5"
sed -i "s~height: min~height: Min~" $src5
sed -i "s~height: min~height: Min~" $src6
yellow "Done fixing css."
# move svgedit to public folder
yellow "Adding symbolic link to svg editor in public folder"
node_modules_folder="$(node -e 'const p = require.resolve("@svgedit/svgcanvas"); console.log(p.slice(0, p.indexOf("@svgedit/svgcanvas")))')"
rm -f ./public/svgedit && ln -s "$node_modules_folder"/svgedit/dist/editor ./public/svgedit
yellow "Finished adding symbolic link to svg editor in public folder"
# move molviewer to public folder
yellow "Adding symbolic link to jsmol in public folder"
node_modules_folder="$(node -e 'const p = require.resolve("react"); console.log(p.slice(0, p.indexOf("react")))')"
rm -rf ./public/jsmol && ln -s "$node_modules_folder"/react-molviewer/dist/jsmol ./public/jsmol
yellow "Finished adding symbolic link to jsmol in public folder"
# copy pdfjs worker to public folder
node_modules_folder_pdfjs="$(node -e 'const p = require.resolve("pdfjs-dist/build/pdf.worker"); console.log(p.slice(0, p.indexOf("pdfjs-dist/build/pdf.worker")))')"
rm -f ./public/pdf.worker.min.js && ln -s "$node_modules_folder_pdfjs"pdfjs-dist/build/pdf.worker.min.js ./public/pdf.worker.min.js
yellow "Finished adding symbolic link to pdf worker in public folder"
# d3js source files
src_d3=(
"@complat/react-spectra-editor/dist/components/common/draw.js"
"@complat/react-spectra-editor/dist/components/d3_line/line_focus.js"
"@complat/react-spectra-editor/dist/components/d3_multi/multi_focus.js"
"@complat/react-spectra-editor/dist/components/d3_rect/rect_focus.js"
"@complat/react-spectra-editor/dist/helpers/brush.js"
"@complat/react-spectra-editor/dist/helpers/compass.js"
"@complat/react-spectra-editor/dist/helpers/init.js"
"@complat/react-spectra-editor/dist/helpers/zoom.js"
)
# Rewrite import for d3.js
for src_file in "${src_d3[@]}"; do
src=$(node -e "console.log(require.resolve('$src_file'))")
yellow "Rewriting import for d3.js in $src"
sed -i "s~const d3 = require('d3');~import('d3').then(d3 => {~" "$src"
if ! tail -n1 "$src" | grep -q "});"; then
echo -e "\n});" >> "$src"
fi
yellow "Done rewriting import for d3.js in $src"
done