-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap
More file actions
executable file
·161 lines (133 loc) · 3.9 KB
/
Copy pathbootstrap
File metadata and controls
executable file
·161 lines (133 loc) · 3.9 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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/bin/sh
set -eu
## To learn more, visit https://stacksjs.com/docs/guide/bootstrap
## Usage:
## ./bootstrap
## curl -fsSL https://stacksjs.com/install | sh
## curl -fsSL https://stacksjs.com/install | sh -s -- my-project
ASSUME_YES=0
PROJECT_NAME=""
while [ "$#" -gt 0 ]; do
case "$1" in
-y|--yes) ASSUME_YES=1 ;;
-h|--help)
echo "Usage: ./bootstrap [--yes] [project-name]"
exit 0
;;
-*)
echo "Unknown option: $1"
exit 1
;;
*)
if [ -n "$PROJECT_NAME" ]; then
echo "Only one project name may be supplied."
exit 1
fi
PROJECT_NAME="$1"
;;
esac
shift
done
TEMP_DIR=""
cleanup() {
if [ -n "$TEMP_DIR" ] && [ -d "$TEMP_DIR" ]; then
rm -rf "$TEMP_DIR"
fi
}
trap cleanup EXIT INT TERM
confirm_install() {
if [ "$ASSUME_YES" -eq 1 ]; then
return 0
fi
if [ ! -r /dev/tty ]; then
echo "Pantry is required to provision Bun and the local toolchain."
echo "Run again with --yes to approve its installation."
return 1
fi
printf "Pantry will install Bun and the local development toolchain. Continue? [Y/n] " > /dev/tty
IFS= read -r answer < /dev/tty || answer=""
case "$answer" in
""|y|Y|yes|YES|Yes) return 0 ;;
*) echo "Installation cancelled."; return 1 ;;
esac
}
# --- Pantry installer (inlined so it works via curl-pipe-bash before clone) ---
ensure_pantry() {
if command -v pantry >/dev/null 2>&1; then
return
fi
confirm_install || exit 1
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
case "$ARCH" in
x86_64|amd64) ARCH="x64" ;;
arm64|aarch64) ARCH="arm64" ;;
esac
INSTALL_DIR="${HOME}/.local/bin"
mkdir -p "$INSTALL_DIR"
ZIP="pantry-${OS}-${ARCH}.zip"
URL="https://github.com/home-lang/pantry/releases/latest/download/${ZIP}"
echo "Downloading Pantry from ${URL}..."
TEMP_DIR=$(mktemp -d)
curl -fsSL -o "${TEMP_DIR}/${ZIP}" "$URL"
unzip -oq "${TEMP_DIR}/${ZIP}" -d "$INSTALL_DIR"
chmod +x "${INSTALL_DIR}/pantry"
rm -rf "$TEMP_DIR"
TEMP_DIR=""
export PATH="${INSTALL_DIR}:${PATH}"
echo "Pantry installed to ${INSTALL_DIR}/pantry"
}
# --- Main ---
# If we are outside a project, create one from the latest stable release.
if [ ! -d "storage/framework/core" ]; then
if [ -z "$PROJECT_NAME" ]; then
PROJECT_NAME="${STACKS_PROJECT:-stacks}"
if [ -r /dev/tty ]; then
printf "Project directory [%s]: " "$PROJECT_NAME" > /dev/tty
IFS= read -r requested_name < /dev/tty || requested_name=""
if [ -n "$requested_name" ]; then
PROJECT_NAME="$requested_name"
fi
fi
fi
if [ -e "$PROJECT_NAME" ]; then
echo "Path '$PROJECT_NAME' already exists. Please use a different name."
exit 1
fi
RELEASE_TAG="${STACKS_VERSION:-}"
if [ -z "$RELEASE_TAG" ]; then
RELEASE_URL=$(curl -fsSL -o /dev/null -w '%{url_effective}' "https://github.com/stacksjs/stacks/releases/latest")
RELEASE_TAG=${RELEASE_URL##*/}
fi
case "$RELEASE_TAG" in
v*) ;;
*) RELEASE_TAG="v${RELEASE_TAG}" ;;
esac
echo "Downloading Stacks ${RELEASE_TAG}..."
TEMP_DIR=$(mktemp -d)
curl -fsSL -o "${TEMP_DIR}/stacks.zip" "https://github.com/stacksjs/stacks/archive/refs/tags/${RELEASE_TAG}.zip"
unzip -q "${TEMP_DIR}/stacks.zip" -d "$TEMP_DIR"
ARCHIVE_DIR="${TEMP_DIR}/stacks-${RELEASE_TAG#v}"
if [ ! -d "$ARCHIVE_DIR" ]; then
echo "The Stacks release archive had an unexpected layout."
exit 1
fi
mv "$ARCHIVE_DIR" "$PROJECT_NAME"
rm -rf "$TEMP_DIR"
TEMP_DIR=""
cd "$PROJECT_NAME"
fi
# Detect if we're in a Stacks project
if [ ! -d "storage/framework/core" ]; then
echo "Error: not inside a Stacks project."
exit 1
fi
PROJECT_ROOT=$(pwd)
ensure_pantry
echo "Bootstrapping Stacks project..."
"${PROJECT_ROOT}/buddy" setup --skip-aws
echo ""
echo "Project bootstrapped successfully!"
if [ -n "$PROJECT_NAME" ]; then
echo "Run 'cd $PROJECT_NAME && ./buddy dev' to start the dev server."
fi