-
Notifications
You must be signed in to change notification settings - Fork 1
/
create_module.sh
58 lines (51 loc) · 1.89 KB
/
create_module.sh
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
#!/bin/bash
if [ -z "$1" ]; then
echo "No word provided. Please provide a word as an argument."
exit 1
fi
key=$1
mkdir "lib/src/modules/$key"
mkdir "lib/src/modules/$key/bindings"
touch "lib/src/modules/$key/bindings/${key}_bindings.dart"
mkdir "lib/src/modules/$key/controllers"
touch "lib/src/modules/$key/controllers/${key}_controller.dart"
mkdir "lib/src/modules/$key/views"
touch "lib/src/modules/$key/views/${key}_view.dart"
mkdir "lib/src/modules/$key/widgets"
camelCaseKey=$(echo "$1" | awk -F'_' '{for (i=2; i<=NF; i++) $i=toupper(substr($i,1,1)) substr($i,2)} 1' OFS='')
pascalCaseKey=$(echo "$1" | awk -F'_' '{for (i=1; i<=NF; i++) $i=toupper(substr($i,1,1)) tolower(substr($i,2))} 1' OFS='')
# write bindings
cat <<EOF > "lib/src/modules/$key/bindings/${key}_bindings.dart"
import 'package:get/get.dart';
import 'package:getx_template/src/modules/${key}/controllers/${key}_controller.dart';
class ${pascalCaseKey}Bindings extends Bindings {
@override
void dependencies() {
Get.lazyPut(() => ${pascalCaseKey}Controller());
}
}
EOF
# write controller
cat <<EOF > "lib/src/modules/$key/controllers/${key}_controller.dart"
import 'package:get/get.dart';
import 'package:getx_template/src/app/routes/router.dart';
import 'package:getx_template/src/base/base_get_controller.dart';
class ${pascalCaseKey}Controller extends BaseGetController<Null> with Router {
@override
void onReady() {
change(null, status: RxStatus.success());
super.onReady();
}
}
EOF
# write view
cat <<EOF > "lib/src/modules/$key/views/${key}_view.dart"
import 'package:flutter/material.dart';
import 'package:getx_template/src/base/base_get_view.dart';
import 'package:getx_template/src/modules/${key}/controllers/${key}_controller.dart';
class ${pascalCaseKey}View extends BaseGetView<${pascalCaseKey}Controller> {
const ${pascalCaseKey}View({super.key});
@override
Widget phoneBody(state) => const Text("Phone");
}
EOF