-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcreate.sh
More file actions
executable file
·225 lines (183 loc) · 4.09 KB
/
Copy pathcreate.sh
File metadata and controls
executable file
·225 lines (183 loc) · 4.09 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
#!/bin/bash
# Copyright (c) 2024 Singularity Indonesia (stefanus.ayudha@gmail.com)
# You are not allowed to remove the copyright. Unless you have a "free software" licence.
# Define the options and their default values
TYPE="main"
NAME=""
# Parse the command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
-t|--type)
TYPE="$2"
shift # past argument
shift # past value
;;
-n|--name)
NAME="$2"
shift # past argument
shift # past value
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
done
# Check if the target is unrecognized or not one of the allowed targets
if [[ ! "$TYPE" =~ ^(main|shared|system)$ ]]; then
echo "Unrecognized or invalid target"
exit 1
fi
# PRESENTATION SCRIPT
presentation_script_pt1=$(cat <<'EOF'
import plugin.convention.companion.Shared
import plugin.convention.companion.System
import plugin.convention.companion.model
import plugin.convention.companion.data
plugins {
id("LibraryConventionV1")
id("CompileIOS")
/*id("CompileWasm")*/
id("FeatureCoroutine")
id("FeaturePane")
id("FeatureSerialization")
id("FeatureHttpClient")
}
kotlin {
sourceSets {
commonMain.dependencies {
System("core")
Shared("common")
EOF
)
presentation_script_pt2="
data(\"$NAME\")
model(\"$NAME\")
}
}
}
android {
"
presentation_script_pt3="
namespace = \"$TYPE.$NAME.presentation\""
presentation_script_pt4=$(cat <<'EOF'
}
task("testClasses")
EOF
)
presentation_script="$presentation_script_pt1$presentation_script_pt2$presentation_script_pt3$presentation_script_pt4"
data_script_pt1=$(cat <<'EOF'
import plugin.convention.companion.model
import plugin.convention.companion.Shared
import plugin.convention.companion.System
plugins {
id("LibraryConventionV1")
id("CompileIOS")
/*id("CompileWasm")*/
id("FeatureCoroutine")
id("FeatureSerialization")
id("FeatureHttpClient")
}
kotlin {
sourceSets {
commonMain.dependencies {
System("core")
Shared("common")
EOF
)
data_script_pt2="
model(\"$NAME\")
}
}
}
android {
"
data_script_pt3="
namespace = \"$TYPE.$NAME.data\""
data_script_pt4=$(cat <<'EOF'
}
task("testClasses")
EOF
)
data_script="$data_script_pt1$data_script_pt2$data_script_pt3$data_script_pt4"
model_pt1=$(cat <<'EOF'
plugins {
id("LibraryConventionV1")
id("CompileIOS")
/*id("CompileWasm")*/
id("FeatureCoroutine")
id("FeatureSerialization")
}
android {
EOF
)
model_pt2="
namespace = \"$TYPE.$NAME.model\""
model_pt3=$(cat <<'EOF'
}
task("testClasses")
EOF
)
model_script="$model_pt1$model_pt2$model_pt3"
common_library_pt1=$(cat <<'EOF'
plugins {
id("LibraryConventionV1")
id("CompileIOS")
/*id("CompileWasm")*/
id("FeatureCoroutine")
}
android {
EOF
)
common_library_pt2="
namespace = \"$TYPE.$NAME\""
common_library_pt3=$(cat <<'EOF'
}
task("testClasses")
EOF
)
common_library_scipt="$common_library_pt1$common_library_pt2$common_library_pt3"
createMain() {
# shellcheck disable=SC2164
mkdir "Main/$NAME"
# shellcheck disable=SC2164
cd "Main/$NAME"
mkdir -p "presentation/common/$NAME"
echo "$presentation_script" > presentation/build.gradle.kts
mkdir -p "data/common/$NAME"
echo "$data_script" > data/build.gradle.kts
mkdir -p "model/common/$NAME"
echo "$model_script" > model/build.gradle.kts
cd ..
echo "
File(settingsDir, \"./$NAME\")
.listFiles()
?.asSequence()
?.filter { it.isDirectory }
?.filter { it.listFiles()?.map { it.name }?.contains(\"build.gradle.kts\") == true }
?.onEach { dir ->
include(\":$NAME:\${dir.name}\")
}
?.toList()" >> settings.gradle.kts
# back to root
cd ..
}
createCommonLibrary() {
cd "$TYPE"
mkdir -p "$NAME/common/$NAME"
echo "$common_library_scipt" > "$NAME/build.gradle.kts"
# back to root
cd ..
}
# Run the appropriate create function based on the target
case "$TYPE" in
"main")
createMain
;;
"shared")
createCommonLibrary
;;
"system")
createCommonLibrary
;;
esac