-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_feature.sh
executable file
·167 lines (130 loc) · 4.32 KB
/
create_feature.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
156
157
158
159
160
161
162
163
164
165
166
167
#!/bin/bash
# Check if package name is provided
if [ -z "$1" ]; then
echo "Usage: $0 package_name"
exit 1
fi
PACKAGE_NAME=$1
# Function to convert snake_case to PascalCase
to_pascal_case() {
IFS='_' read -ra WORDS <<< "$1"
PASCAL_CASE=""
for WORD in "${WORDS[@]}"; do
PASCAL_WORD="$(tr '[:lower:]' '[:upper:]' <<< ${WORD:0:1})${WORD:1}"
PASCAL_CASE="${PASCAL_CASE}${PASCAL_WORD}"
done
echo "$PASCAL_CASE"
}
PASCAL_CASE_PACKAGE_NAME=$(to_pascal_case "$PACKAGE_NAME")
# Create directories inside packages/features
mkdir -p "packages/features/$PACKAGE_NAME/lib/src/l10n"
# Create the state Dart file with the initial code
cat <<EOF > "packages/features/$PACKAGE_NAME/lib/src/${PACKAGE_NAME}_state.dart"
part of '${PACKAGE_NAME}_cubit.dart';
abstract class ${PASCAL_CASE_PACKAGE_NAME}State extends Equatable {
const ${PASCAL_CASE_PACKAGE_NAME}State();
@override
List<Object?> get props => [];
}
class ${PASCAL_CASE_PACKAGE_NAME}InProgress extends ${PASCAL_CASE_PACKAGE_NAME}State {}
class ${PASCAL_CASE_PACKAGE_NAME}Loaded extends ${PASCAL_CASE_PACKAGE_NAME}State {}
class ${PASCAL_CASE_PACKAGE_NAME}Failure extends ${PASCAL_CASE_PACKAGE_NAME}State {}
EOF
# Create the cubit Dart file with the provided initial code
cat <<EOF > "packages/features/$PACKAGE_NAME/lib/src/${PACKAGE_NAME}_cubit.dart"
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:equatable/equatable.dart';
part '${PACKAGE_NAME}_state.dart';
class ${PASCAL_CASE_PACKAGE_NAME}Cubit extends Cubit<${PASCAL_CASE_PACKAGE_NAME}State> {
${PASCAL_CASE_PACKAGE_NAME}Cubit() : super(${PASCAL_CASE_PACKAGE_NAME}InProgress()) {
onInit();
}
void onInit() {}
}
EOF
# Create the screen Dart file with the provided content
cat <<EOF > "packages/features/$PACKAGE_NAME/lib/src/${PACKAGE_NAME}_screen.dart"
import 'package:$PACKAGE_NAME/src/${PACKAGE_NAME}_cubit.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class ${PASCAL_CASE_PACKAGE_NAME}Screen extends StatelessWidget {
const ${PASCAL_CASE_PACKAGE_NAME}Screen({super.key});
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (_) => ${PASCAL_CASE_PACKAGE_NAME}Cubit(),
child: const ${PASCAL_CASE_PACKAGE_NAME}View(),
);
}
}
class ${PASCAL_CASE_PACKAGE_NAME}View extends StatelessWidget {
const ${PASCAL_CASE_PACKAGE_NAME}View({super.key});
@override
Widget build(BuildContext context) {
return BlocBuilder<${PASCAL_CASE_PACKAGE_NAME}Cubit, ${PASCAL_CASE_PACKAGE_NAME}State>(
builder: (context, state) {
return Container();
},
);
}
}
EOF
# Create the main export Dart file under lib
cat <<EOF > "packages/features/$PACKAGE_NAME/lib/${PACKAGE_NAME}.dart"
export 'src/${PACKAGE_NAME}_screen.dart';
export 'src/l10n/${PACKAGE_NAME}_localizations.dart';
EOF
# Create l10n.yaml file with the specified configuration
cat <<EOF > "packages/features/$PACKAGE_NAME/l10n.yaml"
arb-dir: lib/src/l10n
template-arb-file: messages_en.arb
output-localization-file: ${PACKAGE_NAME}_localizations.dart
output-class: ${PASCAL_CASE_PACKAGE_NAME}Localizations
synthetic-package: false
nullable-getter: false
EOF
# Write JSON content to messages_en.arb file
cat <<EOF > "packages/features/$PACKAGE_NAME/lib/src/l10n/messages_en.arb"
{
"greeting": "Hello"
}
EOF
# Write JSON content to messages_ar.arb file (Arabic version)
cat <<EOF > "packages/features/$PACKAGE_NAME/lib/src/l10n/messages_ar.arb"
{
"greeting": "مرحبا"
}
EOF
# Create a default pubspec.yaml for the feature package
cat <<EOF > "packages/features/$PACKAGE_NAME/pubspec.yaml"
name: $PACKAGE_NAME
publish_to: none
environment:
sdk: ">=3.0.5 <4.0.0"
dependencies:
component_library:
path: ../../component_library
flutter_bloc: ^8.1.5
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
smooth_page_indicator: ^1.1.0
intl: ^0.19.0
equatable: ^2.0.5
dev_dependencies:
flutter_test:
sdk: flutter
mocktail: ^1.0.3
test: ^1.16.8
flutter_lints: ^4.0.0
flutter:
uses-material-design: true
EOF
# Create analysis_options.yaml file
cat <<EOF > "packages/features/$PACKAGE_NAME/analysis_options.yaml"
include: package:flutter_lints/flutter.yaml
EOF
echo "Feature package $PACKAGE_NAME created successfully!"
##usage : chmod +x create_feature.sh
## ./create_feature.sh test_pack_yo