-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
blazew
executable file
·131 lines (100 loc) · 3.07 KB
/
blazew
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env sh
set -e
argv_0=$0
projectdir=$(dirname $0)
projectdir=$(readlink -f "$projectdir")
tmp_dir="$projectdir/.blaze"
bun_dir="$tmp_dir/bun"
bun="bun"
has_curl=$(command -v curl)
has_wget=$(command -v wget)
if [ -z "$has_curl" ] && [ -z "$has_wget" ]; then
echo "error: No curl or wget found. Please install one of them."
exit 1
fi
mkdir -p "$tmp_dir"
getprop() {
value=$(cat "$projectdir/blaze/wrapper/blaze_wrapper.properties" | grep "$1" | cut -d'=' -f2)
echo $value
}
print() {
printf "\033[${1}m$2\033[0m"
printf " $3\n"
}
blaze_srcpath=$(getprop "blaze.srcpath")
blaze_srcpath=$(readlink -f "$blaze_srcpath")
if [ -z "$blaze_srcpath" ]; then
print "31" "error" "blaze.srcpath is not set in blaze_wrapper.properties"
exit 1
fi
pushd() {
if [ -z "$1" ]; then
return 1
fi
if [ -z "$DIRSTACK" ]; then
DIRSTACK="$1"
else
DIRSTACK="$1:$DIRSTACK"
fi
cd "$1"
}
popd() {
if [ -z "$DIRSTACK" ]; then
return 1
fi
cd "$(echo "$DIRSTACK" | cut -d: -f1)"
DIRSTACK=$(echo "$DIRSTACK" | cut -d: -f2-)
}
summary() {
title=$1
if [ -z "$title" ]; then
title="Final"
fi
printf "\033[1m -- $title Configuration Summary -- \033[0m\n\n"
print "32" "info" "Project root directory: $projectdir"
print "32" "info" "BlazeBuild directory: $blaze_srcpath"
print "32" "info" "Temporary directory: $tmp_dir"
print "32" "info" "Bun executable: $bun"
printf "\n"
}
bun_run_installer() {
rm -rf "$bun_dir"
mkdir -p "$bun_dir"
if [ ! -z "$has_curl" ]; then
export BUN_INSTALL="$bun_dir" && export PATH="$BUN_INSTALL":"$PATH":"$BUN_INSTALL" && export SHELL=blazew && (curl -fsSL https://bun.sh/install | bash -s "bun-v$1") >"$tmp_dir/bun_install.log" 2>&1
else
export BUN_INSTALL="$bun_dir" && export PATH="$BUN_INSTALL":"$PATH":"$BUN_INSTALL" && export SHELL=blazew && (wget -qO- https://bun.sh/install | bash -s "bun-v$1") >"$tmp_dir/bun_install.log" 2>&1
fi
bun="$bun_dir/bin/bun"
}
install_bun() {
local bun_version=$(getprop "bun.version")
if [ -z "$bun_version" ]; then
print "31" "error" "bun.version is not set in blaze_wrapper.properties"
exit 1
fi
export PATH="$bun_dir/bin":"$PATH":"$bun_dir/bin"
if [ -z "$(command -v bun)" ]; then
print "33" "warn" "Could not find bun installation"
print "32" "info" "Installing bun"
bun_run_installer $bun_version
else
existing_version=$(bun --version)
if [ "$existing_version" != "$bun_version" ]; then
print "33" "warn" "Bun version mismatch in existing installation: required $bun_version, found $existing_version"
print "32" "info" "Installing bun version: $bun_version"
bun_run_installer $bun_version
else
bun="$(command -v bun)"
fi
fi
}
if [ "$BLAZEW_DEBUG" = "1" ]; then
summary "Initial"
fi
install_bun
if [ "$BLAZEW_DEBUG" = "1" ]; then
printf "\n"
summary
fi
$bun $projectdir/blaze/wrapper/blaze_wrapper.js $@