-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-feature.sh
More file actions
executable file
·90 lines (77 loc) · 3.44 KB
/
create-feature.sh
File metadata and controls
executable file
·90 lines (77 loc) · 3.44 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
#!/bin/bash
# Get feature name from command line argument
if [ -z "$1" ]; then
echo "Usage: $0 <FeatureName>"
echo "Example: $0 Orders"
exit 1
fi
FEATURE_NAME="$1"
FEATURE_NAME_LOWER=$(echo "$FEATURE_NAME" | tr '[:upper:]' '[:lower:]')
echo "🚀 Creating feature: $FEATURE_NAME"
# Check if template exists
if [ ! -d ".template/feature" ]; then
echo "❌ Error: Template directory not found at .template/feature"
exit 1
fi
# Check if target already exists
if [ -d "feature/$FEATURE_NAME_LOWER" ]; then
echo "❌ Error: Feature '$FEATURE_NAME_LOWER' already exists"
exit 1
fi
echo "📋 Step 1: Copying template..."
cp -r .template/feature feature/$FEATURE_NAME_LOWER
echo "📋 Step 2: Updating file contents..."
# Use different approach for sed on macOS vs Linux
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS
find feature/$FEATURE_NAME_LOWER -type f \( -name "*.kt" -o -name "*.kts" -o -name "*.xml" \) -exec sed -i '' "s/TemplateFeature/$FEATURE_NAME/g" {} +
find feature/$FEATURE_NAME_LOWER -type f \( -name "*.kt" -o -name "*.kts" -o -name "*.xml" \) -exec sed -i '' "s/templatefeature/$FEATURE_NAME_LOWER/g" {} +
else
# Linux
find feature/$FEATURE_NAME_LOWER -type f \( -name "*.kt" -o -name "*.kts" -o -name "*.xml" \) -exec sed -i "s/TemplateFeature/$FEATURE_NAME/g" {} +
find feature/$FEATURE_NAME_LOWER -type f \( -name "*.kt" -o -name "*.kts" -o -name "*.xml" \) -exec sed -i "s/templatefeature/$FEATURE_NAME_LOWER/g" {} +
fi
echo "📋 Step 3: Renaming directories and files..."
# Rename package directories
find feature/$FEATURE_NAME_LOWER -type d -name "*templatefeature*" | while read dir; do
newdir=$(echo "$dir" | sed "s/templatefeature/$FEATURE_NAME_LOWER/g")
if [ "$dir" != "$newdir" ]; then
mv "$dir" "$newdir" 2>/dev/null || true
fi
done
# Rename files
find feature/$FEATURE_NAME_LOWER -type f -name "*TemplateFeature*" | while read file; do
newfile=$(echo "$file" | sed "s/TemplateFeature/$FEATURE_NAME/g")
if [ "$file" != "$newfile" ]; then
mv "$file" "$newfile" 2>/dev/null || true
fi
done
find feature/$FEATURE_NAME_LOWER -type f -name "*templatefeature*" | while read file; do
newfile=$(echo "$file" | sed "s/templatefeature/$FEATURE_NAME_LOWER/g")
if [ "$file" != "$newfile" ]; then
mv "$file" "$newfile" 2>/dev/null || true
fi
done
echo "📋 Step 4: Updating settings.gradle.kts..."
if ! grep -q ":feature:$FEATURE_NAME_LOWER:" settings.gradle.kts; then
echo "" >> settings.gradle.kts
echo "// $FEATURE_NAME Feature" >> settings.gradle.kts
echo "include(\":feature:$FEATURE_NAME_LOWER:api\")" >> settings.gradle.kts
echo "include(\":feature:$FEATURE_NAME_LOWER:impl\")" >> settings.gradle.kts
echo "include(\":feature:$FEATURE_NAME_LOWER:wiring\")" >> settings.gradle.kts
echo "include(\":feature:$FEATURE_NAME_LOWER:demo\")" >> settings.gradle.kts
echo "✅ Added modules to settings.gradle.kts"
fi
echo "📋 Step 5: Cleaning build artifacts..."
./gradlew clean > /dev/null 2>&1 || true
echo ""
echo "🎉 Successfully created feature: $FEATURE_NAME"
echo "📦 Modules created:"
echo " • :feature:$FEATURE_NAME_LOWER:api"
echo " • :feature:$FEATURE_NAME_LOWER:impl"
echo " • :feature:$FEATURE_NAME_LOWER:wiring"
echo " • :feature:$FEATURE_NAME_LOWER:demo"
echo ""
echo "🏃♂️ Next steps:"
echo " 1. Sync project: ./gradlew build"
echo " 2. Run demo: ./gradlew :feature:$FEATURE_NAME_LOWER:demo:installDebug"