-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflutter_create.ps1
More file actions
180 lines (147 loc) · 6.15 KB
/
flutter_create.ps1
File metadata and controls
180 lines (147 loc) · 6.15 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
$SUCCESS_CODE = "Green"
$INFO_CODE = "Blue"
Write-Host "Creating Flutter Project..." -ForegroundColor $INFO_CODE
Write-Host -NoNewline "Project location (default: D:\Repositories\): " -ForegroundColor $INFO_CODE
$project_location = Read-Host
if ($project_location -eq "") {
$project_location = "D:\Repositories\"
}
if (-Not (Test-Path -Path $project_location)) {
New-Item -ItemType Directory -Path $project_location
Write-Host "Directory created at $project_location" -ForegroundColor $INFO_CODE
} else {
Write-Host "Directory already exists at $project_location" -ForegroundColor $INFO_CODE
}
Set-Location $project_location
$org = "com.snow"
do {
Write-Host -NoNewline "Project name: " -ForegroundColor $INFO_CODE
$project_name = Read-Host
if ($project_name -match "\s" -or $project_name -cne $project_name.ToLower()) {
Write-Host "Project name should not contain spaces or uppercase letters. Please try again." -ForegroundColor "Red"
}
} while ($project_name -match "\s" -or $project_name -cne $project_name.ToLower())
Write-Host -NoNewline "Project Description: " -ForegroundColor $INFO_CODE
$project_description = Read-Host
if ($project_description -eq "") {
$project_description = "A new Flutter project."
}
Write-Host -NoNewline "Is a game? [t/f]" -ForegroundColor $INFO_CODE
$is_game = Read-Host
if ($is_game -eq "t") {
$org = "$org.game"
Write-Host "Game project selected." -ForegroundColor $INFO_CODE
} else {
$org = "$org.app"
Write-Host "App project selected." -ForegroundColor $INFO_CODE
}
& flutter create $project_name --description="$project_description" -e --org=$org | Out-Null
Write-Host "Flutter project created." -ForegroundColor $SUCCESS_CODE
Set-Location $project_name
Remove-Item README.md -ErrorAction SilentlyContinue
Write-Host "Adding common flutter packages..." -ForegroundColor $INFO_CODE
& flutter pub add flutter_launcher_icons flutter_native_splash --dev | Out-Null
Write-Host "flutter_launcher_icons added." -ForegroundColor $SUCCESS_CODE
Write-Host "flutter_native_splash added." -ForegroundColor $SUCCESS_CODE
& flutter pub add logger go_router | Out-Null
Write-Host "logger added." -ForegroundColor $SUCCESS_CODE
Write-Host "go_router added." -ForegroundColor $SUCCESS_CODE
Write-Host -NoNewline "Is a firebase project? [t/f]" -ForegroundColor $INFO_CODE
$is_firebase = Read-Host
if ($is_firebase -eq "t") {
& flutter pub add firebase_core firebase_auth cloud_firestore firebase_storage | Out-Null
Write-Host "firebase_core, firebase_auth, cloud_firestore, firebase_storage packages added." -ForegroundColor $SUCCESS_CODE
}
$dict = @{
"1" = "native"
"2" = "get"
"3" = "provider"
"4" = "flutter_bloc"
"5" = "mobx"
"6" = "riverpod"
}
$options = [System.Management.Automation.Host.ChoiceDescription[]] @("&native", "&get", "&provider", "&flutter_bloc", "&mobx", "&riverpod")
$prompt = "Select a state manager"
$state_manager = $host.ui.PromptForChoice("", $prompt, $options, 0)
# Ahora, $state_manager contendrá el índice de la opción seleccionada (0 para la primera opción, 1 para la segunda, etc.)
# Puedes usar este índice para acceder al valor correspondiente en tu "diccionario":
$selected_manager = $dict[($state_manager + 1).ToString()]
if ($selected_manager -eq "native") {
Write-Host "Native state manager selected." -ForegroundColor $SUCCESS_CODE
} else {
if ($selected_manager -eq "mobx") {
& flutter pub add mobx flutter_mobx | Out-Null
& flutter pub add dev:build_runner | Out-Null
& flutter pub add dev:mobx_codegen | Out-Null
} elseif ($selected_manager -eq "riverpod") {
& flutter pub add flutter_riverpod riverpod_annotation | Out-Null
& flutter pub add dev:build_runner | Out-Null
& flutter pub add dev:custom_lint | Out-Null
& flutter pub add dev:riverpod_generator | Out-Null
& flutter pub add dev:riverpod_lint | Out-Null
} else {
# Instalar solo el paquete seleccionado
& flutter pub add $selected_manager | Out-Null
}
Write-Host "$selected_manager added." -ForegroundColor $SUCCESS_CODE
}
New-Item -ItemType Directory -Path assets, "assets\icons", "assets\images", "assets\fonts" -Force | Out-Null
Write-Host "assets folder structured." -ForegroundColor $INFO_CODE
New-Item -ItemType Directory -Path assets, "lib\models", "lib\screens", "lib\providers", "lib\services", "lib\styles", "lib\widgets" -Force | Out-Null
Write-Host "lib folder structured." -ForegroundColor $INFO_CODE
if ($is_firebase -eq "t") {
@"
import 'package:cloud_firestore/cloud_firestore.dart';
class DatabaseService {
final FirebaseFirestore _firestore;
DatabaseService() : _firestore = FirebaseFirestore.instance;
// Add your database service methods here
}
"@ | Out-File -Encoding utf8 "lib/services/database_service.dart"
Write-Host "database_service.dart created."
@"
import 'package:firebase_storage/firebase_storage.dart';
class CloudStorageService {
final FirebaseStorage _storage;
CloudStorageService() : _storage = FirebaseStorage.instance;
// Add your cloud storage service methods here
}
"@ | Out-File -Encoding utf8 "lib/services/cloud_storage_service.dart"
Write-Host "cloud_storage_service.dart created."
}
@"
assets:
- assets/icons/
- assets/images/
#dart run flutter_launcher_icons
flutter_launcher_icons:
android: "launcher_icon"
image_path: "assets/icons/launch-icon.png"
web:
generate: true
image_path: "assets/icons/launch-icon.png"
windows:
generate: true
image_path: "assets/icons/launch-icon.png"
#dart run flutter_native_splash:create
flutter_native_splash:
color: "#ffffff"
image: "assets/icons/splash-icon.png"
android: true
web: true
android_12:
color: "#ffffff"
image: "assets/icons/splash-icon.png"
"@ | Out-File -Append -Encoding utf8 pubspec.yaml
& flutter pub get | Out-Null
Write-Host "pubspec.yaml structured." -ForegroundColor $INFO_CODE
@"
# $project_name
## Description
$project_description
"@ | Out-File README.md
Write-Host "README.md created."
& git init | Out-Null
Write-Host -NoNewline "All ready, press any key to open the project..." -ForegroundColor $SUCCESS_CODE
Read-Host
& code . --profile Dart | Out-Null