-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-project.sh
More file actions
577 lines (504 loc) · 17.1 KB
/
create-project.sh
File metadata and controls
577 lines (504 loc) · 17.1 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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
#!/bin/bash
# create-project.sh - A helper script to create a SpringWell project and navigate to it
# Default values
PROJECT_NAME="my-project"
TEMPLATE="basic"
DB="h2"
CLI_PATH="./build/springwell"
VERBOSE=false
FIX_STRUCTURE=true # Auto-fix is enabled by default
VERIFY_TEMPLATES=true # Verify templates before creating the project
# Display help
function show_help {
echo "SpringWell Project Creator"
echo ""
echo "Usage: $0 [options]"
echo ""
echo "Options:"
echo " -n, --name NAME Project name (default: my-project)"
echo " -t, --template NAME Project template (default: basic, options: basic, aws-temporal-auth0)"
echo " -d, --db TYPE Database type (default: h2, options: h2, postgres, mysql)"
echo " -p, --path PATH Path to the springwell CLI (default: ./build/springwell)"
echo " -v, --verbose Enable verbose output"
echo " -f, --fix Fix directory structure if some folders are missing (default: enabled)"
echo " --no-fix Disable auto-fixing of directory structure"
echo " --no-verify Disable template verification"
echo " -h, --help Show this help message"
echo ""
echo "Example:"
echo " $0 --name my-awesome-app --template aws-temporal-auth0 --db postgres"
echo ""
}
# Parse command line arguments
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-n|--name)
PROJECT_NAME="$2"
shift # past argument
shift # past value
;;
-t|--template)
TEMPLATE="$2"
shift # past argument
shift # past value
;;
-d|--db)
DB="$2"
shift # past argument
shift # past value
;;
-p|--path)
CLI_PATH="$2"
shift # past argument
shift # past value
;;
-v|--verbose)
VERBOSE=true
shift # past argument
;;
-f|--fix)
FIX_STRUCTURE=true
shift # past argument
;;
--no-fix)
FIX_STRUCTURE=false
shift # past argument
;;
--no-verify)
VERIFY_TEMPLATES=false
shift # past argument
;;
-h|--help)
show_help
exit 0
;;
*)
echo "Unknown option: $1"
show_help
exit 1
;;
esac
done
# Function to check if the CLI exists and is executable
check_cli() {
if [ ! -f "$CLI_PATH" ]; then
echo "Error: SpringWell CLI not found at $CLI_PATH"
echo "Please build the CLI first with 'make build' or specify the correct path with --path"
return 1
fi
if [ ! -x "$CLI_PATH" ]; then
echo "Warning: CLI file is not executable. Attempting to make it executable..."
chmod +x "$CLI_PATH"
if [ $? -ne 0 ]; then
echo "Error: Could not make CLI executable. Please check permissions."
return 1
fi
fi
return 0
}
# Function to verify template files existence
verify_templates() {
local template="$1"
echo "Verifying template files..."
# Check templates directory existence
if [ ! -d "$(dirname "$CLI_PATH")/pkg/templates" ]; then
echo "❌ Error: templates directory not found"
return 1
fi
echo "✅ Found templates directory"
# Check template directory existence
local template_dir="$(dirname "$CLI_PATH")/pkg/templates/project/$template"
if [ ! -d "$template_dir" ]; then
echo "❌ Error: Template directory for '$template' not found"
echo "Available templates:"
ls "$(dirname "$CLI_PATH")/pkg/templates/project/" 2>/dev/null || echo " None available"
return 1
fi
echo "✅ Found template directory for '$template'"
# For aws-temporal-auth0 template, check key files
if [ "$template" = "aws-temporal-auth0" ]; then
local missing=0
local required_files=(
"config/AwsConfig.java.tmpl"
"config/Auth0Config.java.tmpl"
"config/SecurityConfig.java.tmpl"
"config/TemporalConfig.java.tmpl"
"temporal/worker/TemporalWorkerRegistrar.java.tmpl"
"temporal/worker/TemporalWorkerService.java.tmpl"
"temporal/workflow/OrderProcessingWorkflow.java.tmpl"
)
for file in "${required_files[@]}"; do
if [ ! -f "$template_dir/$file" ]; then
echo "❌ Missing required template file: $file"
missing=1
else
echo "✅ Found template file: $file"
fi
done
if [ $missing -eq 1 ]; then
echo "Some required template files are missing!"
return 1
fi
fi
echo "✅ Template verification completed successfully."
return 0
}
# Verify project structure
verify_project_structure() {
local project="$1"
local template="$2"
echo "Verifying project structure..."
# Check base project directory
if [ ! -d "$project" ]; then
echo "❌ Project directory not created: $project"
return 1
fi
if [ "$template" = "aws-temporal-auth0" ]; then
# Check key directories for AWS template
local dirs=(
".github/workflows"
".mvn"
"charts/$project/templates"
"src/main/java"
"src/main/resources/db/migration"
"src/main/swagger"
"src/test/java"
"src/main/java/com/example/$project/config"
"src/main/java/com/example/$project/controller"
"src/main/java/com/example/$project/domain/dto"
"src/main/java/com/example/$project/domain/entity"
"src/main/java/com/example/$project/exception"
"src/main/java/com/example/$project/middleware"
"src/main/java/com/example/$project/messaging"
"src/main/java/com/example/$project/repository"
"src/main/java/com/example/$project/service"
"src/main/java/com/example/$project/temporal/activity"
"src/main/java/com/example/$project/temporal/worker"
"src/main/java/com/example/$project/temporal/workflow"
"src/main/java/com/example/$project/util"
)
local missing=false
for dir in "${dirs[@]}"; do
if [ ! -d "$project/$dir" ]; then
echo "❌ Missing directory: $dir"
missing=true
else
echo "✅ Found directory: $dir"
fi
done
# Check key files
local files=(
"pom.xml"
"README.md"
"Dockerfile"
"compose.yaml"
)
for file in "${files[@]}"; do
if [ ! -f "$project/$file" ]; then
echo "❌ Missing file: $file"
missing=true
else
echo "✅ Found file: $file"
fi
done
if [ "$missing" = true ]; then
return 1
fi
else
# Basic template checks
local dirs=(
"src/main/java"
"src/main/resources"
"src/test/java"
)
local missing=false
for dir in "${dirs[@]}"; do
if [ ! -d "$project/$dir" ]; then
echo "❌ Missing directory: $dir"
missing=true
else
echo "✅ Found directory: $dir"
fi
done
# Check key files
if [ ! -f "$project/pom.xml" ]; then
echo "❌ Missing file: pom.xml"
missing=true
else
echo "✅ Found file: pom.xml"
fi
if [ "$missing" = true ]; then
return 1
fi
fi
echo "✅ Project structure verified successfully."
return 0
}
# Fix project structure
fix_project_structure() {
local project="$1"
local template="$2"
echo "Fixing project structure..."
if [ "$template" = "aws-temporal-auth0" ]; then
# Create all required directories
mkdir -p "$project/.github/workflows"
mkdir -p "$project/.mvn"
mkdir -p "$project/charts/$project/templates"
mkdir -p "$project/src/main/java/com/example/$project/config"
mkdir -p "$project/src/main/java/com/example/$project/controller"
mkdir -p "$project/src/main/java/com/example/$project/domain/dto"
mkdir -p "$project/src/main/java/com/example/$project/domain/entity"
mkdir -p "$project/src/main/java/com/example/$project/exception"
mkdir -p "$project/src/main/java/com/example/$project/middleware"
mkdir -p "$project/src/main/java/com/example/$project/messaging"
mkdir -p "$project/src/main/java/com/example/$project/repository"
mkdir -p "$project/src/main/java/com/example/$project/service"
mkdir -p "$project/src/main/java/com/example/$project/temporal/activity/impl"
mkdir -p "$project/src/main/java/com/example/$project/temporal/worker"
mkdir -p "$project/src/main/java/com/example/$project/temporal/workflow/impl"
mkdir -p "$project/src/main/java/com/example/$project/util"
mkdir -p "$project/src/main/resources/db/migration"
mkdir -p "$project/src/main/swagger"
mkdir -p "$project/src/test/java/com/example/$project"
# Create key files if missing
if [ ! -f "$project/README.md" ]; then
echo "# $project" > "$project/README.md"
echo "" >> "$project/README.md"
echo "A Spring Boot project created with SpringWell CLI." >> "$project/README.md"
echo "" >> "$project/README.md"
echo "## Features" >> "$project/README.md"
echo "" >> "$project/README.md"
echo "- AWS Integration" >> "$project/README.md"
echo "- Temporal Workflow Engine" >> "$project/README.md"
echo "- Auth0 Authentication" >> "$project/README.md"
echo "- Kubernetes Helm Charts" >> "$project/README.md"
echo "- Docker Compose for local development" >> "$project/README.md"
fi
if [ ! -f "$project/Dockerfile" ]; then
cat > "$project/Dockerfile" << EOF
# Multi-stage build Dockerfile for SpringBoot application
FROM eclipse-temurin:17-jdk as build
WORKDIR /app
COPY . .
RUN ./mvnw clean package -DskipTests
FROM eclipse-temurin:17-jre
WORKDIR /app
COPY --from=build /app/target/*.jar app.jar
ENTRYPOINT ["java", "-jar", "app.jar"]
EOF
fi
if [ ! -f "$project/compose.yaml" ]; then
cat > "$project/compose.yaml" << EOF
version: '3.8'
services:
app:
build: .
ports:
- "8080:8080"
environment:
- SPRING_PROFILES_ACTIVE=dev
depends_on:
- postgres
- temporal
postgres:
image: postgres:15-alpine
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: ${project}
ports:
- "5432:5432"
volumes:
- postgres-data:/var/lib/postgresql/data
temporal:
image: temporalio/auto-setup:1.22.0
environment:
- DB=postgresql
- DB_PORT=5432
- POSTGRES_USER=postgres
- POSTGRES_PWD=postgres
- POSTGRES_SEEDS=postgres
ports:
- "7233:7233"
depends_on:
- postgres
volumes:
postgres-data:
EOF
fi
# Add placeholder files for key Java classes if they don't exist
local config_dir="$project/src/main/java/com/example/$project/config"
if [ ! -f "$config_dir/TemporalConfig.java" ]; then
mkdir -p "$config_dir"
cat > "$config_dir/TemporalConfig.java" << EOF
package com.example.$project.config;
import io.temporal.client.WorkflowClient;
import io.temporal.serviceclient.WorkflowServiceStubs;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class TemporalConfig {
@Value("\${temporal.service.address:localhost:7233}")
private String temporalServiceAddress;
@Value("\${temporal.namespace:default}")
private String namespace;
@Bean
public WorkflowServiceStubs workflowServiceStubs() {
return WorkflowServiceStubs.newServiceStubs(
WorkflowServiceStubs.newConnectivityOptions()
.setTargetEndpoint(temporalServiceAddress)
);
}
@Bean
public WorkflowClient workflowClient(WorkflowServiceStubs workflowServiceStubs) {
return WorkflowClient.newInstance(workflowServiceStubs,
WorkflowClient.newOptions().setNamespace(namespace));
}
}
EOF
fi
# Create application.yml if it doesn't exist
local resources_dir="$project/src/main/resources"
if [ ! -f "$resources_dir/application.yml" ]; then
mkdir -p "$resources_dir"
cat > "$resources_dir/application.yml" << EOF
spring:
application:
name: $project
profiles:
active: local
datasource:
url: jdbc:postgresql://localhost:5432/$project
username: postgres
password: postgres
driver-class-name: org.postgresql.Driver
jpa:
hibernate:
ddl-auto: validate
properties:
hibernate:
dialect: org.hibernate.dialect.PostgreSQLDialect
flyway:
locations: classpath:db/migration
baseline-on-migrate: true
server:
port: 8080
servlet:
context-path: /api
# Temporal configuration
temporal:
service:
address: localhost:7233
namespace: default
taskqueue:
default: $project-task-queue
# AWS Configuration
aws:
region: us-west-2
# Auth0 Configuration
auth0:
audience: https://api.$project.com
domain: $project.us.auth0.com
# Logging configuration
logging:
level:
root: INFO
com.example.$project: DEBUG
io.temporal: INFO
EOF
fi
else
# Basic template
mkdir -p "$project/src/main/java/com/example/$project"
mkdir -p "$project/src/main/resources"
mkdir -p "$project/src/test/java/com/example/$project"
if [ ! -f "$project/README.md" ]; then
echo "# $project" > "$project/README.md"
echo "" >> "$project/README.md"
echo "A Spring Boot project created with SpringWell CLI." >> "$project/README.md"
fi
# Create application.properties if it doesn't exist
local resources_dir="$project/src/main/resources"
if [ ! -f "$resources_dir/application.properties" ]; then
mkdir -p "$resources_dir"
cat > "$resources_dir/application.properties" << EOF
# Application properties
spring.application.name=$project
server.port=8080
# Database configuration
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=password
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.h2.console.enabled=true
# Logging configuration
logging.level.root=INFO
logging.level.com.example.$project=DEBUG
EOF
fi
fi
echo "✅ Project structure fixed."
}
# Main execution starts here
# Check if the CLI exists
check_cli
if [ $? -ne 0 ]; then
exit 1
fi
# Verify template files if enabled
if [ "$VERIFY_TEMPLATES" = true ]; then
verify_templates "$TEMPLATE"
if [ $? -ne 0 ]; then
echo "Template verification failed. Cannot proceed with project creation."
echo "Please ensure that all template files exist before creating a project."
exit 1
fi
fi
# Create the project
echo "Creating new SpringWell project: $PROJECT_NAME"
echo " Template: $TEMPLATE"
echo " Database: $DB"
echo ""
if [ "$VERBOSE" = true ]; then
"$CLI_PATH" new "$PROJECT_NAME" --template "$TEMPLATE" --db "$DB" --verbose
else
"$CLI_PATH" new "$PROJECT_NAME" --template "$TEMPLATE" --db "$DB"
fi
if [ $? -ne 0 ]; then
echo "Error: Failed to create project"
exit 1
fi
echo ""
echo "Project created successfully!"
# Verify the project structure
verify_project_structure "$PROJECT_NAME" "$TEMPLATE"
structure_ok=$?
# Fix structure if needed and requested
if [ $structure_ok -ne 0 ] && [ "$FIX_STRUCTURE" = true ]; then
echo "Some directories are missing. Fixing project structure..."
fix_project_structure "$PROJECT_NAME" "$TEMPLATE"
# Verify again after fixing
verify_project_structure "$PROJECT_NAME" "$TEMPLATE"
structure_ok=$?
if [ $structure_ok -ne 0 ]; then
echo "Warning: Project structure is still incomplete after fixing. There might be deeper issues."
else
echo "✅ Project structure has been successfully fixed!"
fi
elif [ $structure_ok -ne 0 ]; then
echo "Warning: Some project directories are missing."
echo "You can fix this by running this script with the --fix option."
fi
echo "Navigating to project directory..."
# Navigate to the project directory
cd "$PROJECT_NAME" || {
echo "Error: Failed to navigate to project directory"
exit 1
}
echo "You are now in the $PROJECT_NAME directory"
echo "Ready to start development!"
# Execute a new shell in the project directory
exec $SHELL