-
Notifications
You must be signed in to change notification settings - Fork 0
/
structure.sh
executable file
·155 lines (104 loc) · 3.71 KB
/
structure.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
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
#!/bin/bash
# Maintainer by ThetMyoKhaing(https://github.com/tomari99)
echo "input your module name"
read module
mkdir $module
cd $module
make_folder() {
mkdir api
mkdir domain
mkdir presentation
mkdir domain/entities
mkdir domain/repositories
mkdir domain/use_cases
mkdir presentation/views
mkdir presentation/controllers
mkdir presentation/views/widgets
touch api/${module}_api_service.dart
touch presentation/controllers/${module}_controller.dart
touch domain/repositories/${module}_repositories.dart
touch domain/repositories/${module}_repositories_impl.dart
touch domain/entities/$module.dart
touch domain/entities/${module}_model.dart
touch domain/use_cases/${module}_usecase.dart
}
make_folder
uppercase=$(echo "$module" | awk '{print toupper(substr($0, 1, 1)) tolower(substr($0, 2))}')
api="class ${uppercase}ApiService {}"
echo "$api" >api/${module}_api_service.dart
entity="import 'package:equatable/equatable.dart';
// Business object $module
abstract class ${uppercase} extends Equatable {
const ${uppercase}();
@override
List<Object?> get props => [];
}"
echo "$entity" >domain/entities/$module.dart
model="import '../../domain/entities/${module}.dart';
class ${uppercase}Model extends ${uppercase} {
const ${uppercase}Model();
}"
echo "$model" >domain/entities/$module\_model.dart
repo="// Abstract Business logic methods
import '../entities/$module.dart';
abstract class ${uppercase}Repository {}"
echo "$repo" >domain/repositories/$module\_repositories.dart
repo_impl="import 'dart:async';
import '../../domain/entities/$module.dart';
import '../../api/${module}_api_service.dart';
import '../../domain/repositories/${module}_repositories.dart';
import '../../domain/repositories/${module}_repositories.dart';
import '../entities/${module}_model.dart';
// Implemented Business logic methods
class ${uppercase}RepositoryImpl implements ${uppercase}Repository {
late ${uppercase}ApiService _apiService;
${uppercase}RepositoryImpl() {
_apiService = ${uppercase}ApiService();
}
}
"
echo "$repo_impl" >domain/repositories/$module\_repositories_impl.dart
usecase="import '../entities/$module.dart';
import '../repositories/${module}_repositories.dart';
class ${uppercase}UseCase {
final ${uppercase}Repository _${module}Repository;
${uppercase}UseCase(this._${module}Repository);
}"
echo "$usecase" >domain/use_cases/$module\_usecase.dart
controller="import 'package:get/get.dart';
import '../../domain/repositories/${module}_repositories_impl.dart';
import '../../domain/entities/$module.dart';
import '../../domain/use_cases/${module}_usecase.dart';
class ${uppercase}Controller extends GetxController {
late ${uppercase}UseCase _${module}UseCase;
@override
onInit() {
super.onInit();
_${module}UseCase = ${uppercase}UseCase(${uppercase}RepositoryImpl());
}
}"
echo "$controller" >presentation/controllers/$module\_controller.dart
pwd
test="import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import '../../lib/$module/domain/entities/${module}_model.dart';
import '../../lib/$module/domain/repositories/${module}_repositories.dart';
import '../../lib/$module/domain/use_cases/${module}_usecase.dart';
@GenerateMocks([${uppercase}Repository])
void main() {
late Mock${uppercase}Repository repo;
late ${uppercase}UseCase usecase;
setUp(() {
repo = Mock${uppercase}Repository();
usecase = ${uppercase}UseCase(repo);
});
group(\"dummy\", () {
test(\"test description\", () async {
// arrange
// action
// assert
});
});
}"
cd ../../test && mkdir $module && cd $module && touch ${module}_test.dart && echo "$test" >${module}_test.dart