-
Notifications
You must be signed in to change notification settings - Fork 13
/
chanterelle-bin.sh
executable file
·73 lines (65 loc) · 2.55 KB
/
chanterelle-bin.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
#!/bin/bash
# Borrowed with love from https://stackoverflow.com/a/246128/1763937
get_script_dir() {
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
echo "$DIR"
}
CHNTRL_DIR=$(get_script_dir);
CHNTRL_OUTPUT_DIR="$CHNTRL_DIR/output";
CHNTRL_MAIN_MODULE="ChanterelleMain/index.js"
CHNTRL_GLOBAL_MAIN="$CHNTRL_OUTPUT_DIR/$CHNTRL_MAIN_MODULE";
PURS_OUTPUT=${PURS_OUTPUT:-"./output"}
CHNTRL_LOCAL_MAIN="$PURS_OUTPUT/$CHNTRL_MAIN_MODULE";
run_chanterelle() {
CHANTERELLEMAIN_INDEX_JS="$1"; shift
exec node -e "import('$CHANTERELLEMAIN_INDEX_JS').then(chanterelle => chanterelle.main());" -- "chanterelle" $@
}
global_install_available() {
[ -f "$CHNTRL_GLOBAL_MAIN" ]
}
global_postinstall() {
cd "$CHNTRL_DIR"
if [ "$EUID" == "0" ]
then
npm install && npm run global-postinstall-root && npm run build
else
npm install && npm run global-postinstall-non-root && npm run build
fi
if ! global_install_available
then
echo '`chanterelle global-postinstall` did not complete successfully, see output above, correct the issue, and try again'
exit 1
fi
}
if [ "$1" == "global-postinstall" ]
then
if global_install_available && [ "$2" != "--force" ]
then
echo 'chanterelle global-postinstall appears to have already completed successfully. Rerun with --force if you want to run it again anyway'
else
global_postinstall
fi
else
if [ -f "$CHNTRL_LOCAL_MAIN" ]
then
run_chanterelle "$CHNTRL_LOCAL_MAIN" $@
else
echo "Did not detect a project-level Chanterelle version, will attempt to fall back to the system-wide installation." >&2
echo "Make sure you have purescript-chantrelle in your PureScript dependencies and it is compiled." >&2
if ! global_install_available
then
echo 'A global installation of chanterelle is not available, likely because `chanterelle global-postinstall` was never run or did not complete successfully' >&2
echo 'Please run `chanterelle global-postinstall` and try again' >&2
exit 1
else
export CHNTRL_IS_GLOBAL=yes
run_chanterelle "$CHNTRL_GLOBAL_MAIN" $@
fi
fi
fi