-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstaller.sh
More file actions
executable file
·271 lines (236 loc) · 8.33 KB
/
installer.sh
File metadata and controls
executable file
·271 lines (236 loc) · 8.33 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
#!/bin/bash
set -e
STARTER_REPO_BASE_URL="https://github.com/forge-engine/forge-starter/archive/refs/heads/main.zip"
STARTER_TEMPLATE_NAME="starter-blank"
STARTER_ZIP_FILENAME="starter-template.zip"
GITHUB_ARCHIVE_ROOT_FOLDER="forge-starter-main"
function getProjectNameInput() {
while true; do
read -p "Enter your project name (alphanumeric and dashes only): " projectName
projectName=$(echo "$projectName" | tr -d ' ')
if [ -z "$projectName" ]; then
echo "Project name cannot be empty. Please try again."
elif ! [[ "$projectName" =~ ^[a-zA-Z0-9-]+$ ]]; then
echo "Invalid project name. Use alphanumeric characters and dashes only."
elif [ -d "$projectName" ]; then
echo "Directory '$projectName' already exists. Please choose a different name or delete the existing directory."
else
echo "$projectName"
return 0
fi
done
}
function createProjectDirectory() {
local projectDir="$1"
mkdir -p "$projectDir"
if [ $? -ne 0 ]; then
echo "Error: Failed to create project directory '$projectDir'."
return 1
fi
return 0
}
function downloadFile() {
local url="$1"
local destinationPath="$2"
curl -sSL "$url" -o "$destinationPath"
if [ $? -ne 0 ]; then
echo "Error: Failed to download file from '$url' to '$destinationPath'."
return 1
fi
return 0
}
function extractZip() {
local zipFilePath="$1"
local destinationPath="$2"
unzip -qq "$zipFilePath" -d "$destinationPath"
if [ $? -ne 0 ]; then
echo "Error: Could not open or extract zip file: '$zipFilePath'."
return 1
fi
return 0
}
function executeCommand() {
local command="$1"
local workingDir="$2"
cd "$workingDir" || return 1
echo "Running: $command in $(pwd)"
eval "$command"
CMD_RESULT=$?
cd - >/dev/null || return 1
if [ $CMD_RESULT -ne 0 ]; then
echo "Error: Command '$command' failed with exit code: $CMD_RESULT"
return 1
fi
return 0
}
function deleteProjectDirectory() {
local projectDir="$1"
if [ ! -d "$projectDir" ]; then
return 0
fi
echo "Cleaning up project directory: $projectDir"
rm -rf "$projectDir"
if [ $? -ne 0 ]; then
echo "Error: Failed to delete project directory '$projectDir'."
return 1
fi
return 0
}
function deleteDirectory() {
local dir="$1"
if [ -d "$dir" ]; then
rm -rf "$dir"
if [ $? -ne 0 ]; then
echo "Error: Failed to delete directory '$dir'."
return 1
fi
fi
return 0
}
function moveExtractedFiles() {
local sourceDir="$1"
local destinationDir="$2"
if [ ! -d "$sourceDir" ]; then
return 1
fi
shopt -s dotglob
mv "$sourceDir"/* "$destinationDir"/
shopt -u dotglob
if [ $? -ne 0 ]; then
echo "Error moving files from '$sourceDir' to '$destinationDir'."
return 1
fi
return 0
}
# --- Main Scaffolding Function ---
function scaffoldNewProject() {
echo "Welcome to Forge Engine Project Scaffolder! (Shell Script)\n"
echo "---------------------------------------------------------\n\n"
# 1. Get Project Name
projectName=$(getProjectNameInput)
if [ -z "$projectName" ]; then
echo "\nProject scaffolding cancelled."
return 1
fi
projectDir="./$projectName"
if ! createProjectDirectory "$projectDir"; then
echo "\nProject scaffolding cancelled."
return 1
fi
echo "📁 Project directory created: $projectName"
starterZipUrl="$STARTER_REPO_BASE_URL"
starterZipPath="$projectDir/$STARTER_ZIP_FILENAME"
echo "📦 Downloading starter template..."
if ! downloadFile "$starterZipUrl" "$starterZipPath"; then
echo "Error: Failed to download starter template."
deleteProjectDirectory "$projectDir"
echo "\nProject scaffolding cancelled."
return 1
fi
echo "Starter template downloaded."
echo "Extracting starter template..."
if ! extractZip "$starterZipPath" "$projectDir"; then
echo "Error: Failed to extract starter template."
deleteProjectDirectory "$projectDir"
echo "\nProject scaffolding cancelled."
return 1
fi
rm -f "$starterZipPath"
extractedRootFolder="$projectDir/$GITHUB_ARCHIVE_ROOT_FOLDER"
if [ -d "$extractedRootFolder" ]; then
echo "📂 Extracted to: $extractedRootFolder"
if ! moveExtractedFiles "$extractedRootFolder" "$projectDir"; then
echo "Error: Failed to move files from extracted starter template."
deleteProjectDirectory "$projectDir"
echo "\nProject scaffolding cancelled."
return 1
fi
echo "Starter template extracted and files moved to project root."
deleteDirectory "$extractedRootFolder"
else
echo "Error: Extracted folder not found: $extractedRootFolder"
deleteProjectDirectory "$projectDir"
echo "\nProject scaffolding cancelled."
return 1
fi
echo "Removing .git directory from engine folder..."
rm -rf "$projectDir/engine/.git"
if [ $? -ne 0 ]; then
echo "Warning: Failed to remove .git directory from engine folder. This is not critical, but it's recommended to remove it manually."
else
echo ".git directory removed from engine folder."
fi
echo "Running install.php..."
if ! executeCommand "php install.php" "$projectDir"; then
echo "Error: install.php script failed."
deleteProjectDirectory "$projectDir"
echo "\nProject scaffolding cancelled."
return 1
fi
echo "install.php executed successfully."
echo "Running php forge.php package:install-project..."
if ! executeCommand "php forge.php package:install-project" "$projectDir"; then
echo "Error: php forge.php package:install-project command failed."
deleteProjectDirectory "$projectDir"
echo "\nProject scaffolding cancelled."
return 1
fi
echo "php forge.php package:install-project executed successfully."
echo "Running php forge.php key:generate..."
if ! executeCommand "php forge.php key:generate" "$projectDir"; then
echo "Error: php forge.php key:generate command failed."
deleteProjectDirectory "$projectDir"
echo "\nProject scaffolding cancelled."
return 1
fi
echo "php forge.php key:generate executed successfully."
echo "Running php forge.php package:install-module..."
if ! executeCommand "php forge.php package:install-module --module=forge-ui" "$projectDir"; then
echo "Error: php forge.php package:install-module --module=forge-ui command failed."
deleteProjectDirectory "$projectDir"
echo "\nProject scaffolding cancelled."
return 1
fi
echo "php forge.php package:install-module --module=forge-ui executed successfully."
echo "Running php forge.php cache:flush..."
if ! executeCommand "php forge.php cache:flush" "$projectDir"; then
echo "Error: php forge.php cache:flush command failed."
deleteProjectDirectory "$projectDir"
echo "\nProject scaffolding cancelled."
return 1
fi
echo "php forge.php cache:flush executed successfully."
echo "Running php forge.php cache:warm..."
if ! executeCommand "php forge.php cache:warm" "$projectDir"; then
echo "Error: php forge.php cache:warm command failed."
deleteProjectDirectory "$projectDir"
echo "\nProject scaffolding cancelled."
return 1
fi
echo "php forge.php cache:warm executed successfully."
echo "\n--------------------------------------------\n"
echo "Forge Engine project '$projectName' scaffolded successfully!"
echo "Project directory: $projectDir"
echo "Next steps:"
echo "1. cd $projectName"
echo "2. Start dev server:"
echo " php forge.php serve"
echo "Happy coding!"
return 0
}
if ! command -v curl &>/dev/null
then
echo "Error: curl is not installed. Please install curl to continue."
exit 1
fi
if ! command -v unzip &>/dev/null
then
echo "Error: unzip is not installed. Please install unzip to continue."
exit 1
fi
if ! command -v php &>/dev/null
then
echo "Error: php is not installed. Please install php-cli to continue."
exit 1
fi
scaffoldNewProject