flu-cli-core 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +84 -38
- package/dist/chunk-3RG5ZIWI.js +10 -0
- package/dist/{chunk-FOMWV2YP.js → chunk-ANN4MX7M.js} +25 -15
- package/dist/{factory-6DDXZYQP.js → factory-W73G7NBW.js} +2 -1
- package/dist/index.cjs +5268 -786
- package/dist/index.d.cts +122 -61
- package/dist/index.d.ts +122 -61
- package/dist/index.js +5171 -725
- package/dist/{upgrade_snippets-XFR7Q444.js → upgrade_snippets-J7SRI6M5.js} +1 -0
- package/locales/en-US.json +1 -1
- package/locales/zh-CN.json +2 -2
- package/package.json +56 -49
- package/templates/core_files/network/app_error_code.dart.template +6 -6
- package/templates/core_files/network/app_http.dart.template +4 -4
- package/templates/core_files/network/app_response.dart.template +2 -2
- package/templates/core_files/utils/loading_util.dart.template +13 -4
- package/templates/snippets/flu-cli.code-snippets +26 -36
- package/templates/request_helper.dart.template +0 -59
package/locales/en-US.json
CHANGED
|
@@ -56,4 +56,4 @@
|
|
|
56
56
|
"snippets.sync_success": "✅ Code snippets synced successfully!",
|
|
57
57
|
"snippets.detect_config": "ℹ️ Project config detected, filtering snippets...",
|
|
58
58
|
"snippets.applied_filter": "Architecture-aware filtering applied (BasePage: {basePage}, ViewModel: {viewModel})"
|
|
59
|
-
}
|
|
59
|
+
}
|
package/locales/zh-CN.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"cli.description": "🚀 Flutter
|
|
2
|
+
"cli.description": "🚀 Flutter 全流程效率工具链",
|
|
3
3
|
"cmd.new.desc": "创建 Flutter 项目(实时模板预览)",
|
|
4
4
|
"cmd.new.opt.template": "模板类型: lite, modular, clean",
|
|
5
5
|
"cmd.new.opt.state": "状态管理器: default, provider, getx",
|
|
@@ -56,4 +56,4 @@
|
|
|
56
56
|
"snippets.sync_success": "✅ 代码片段同步成功!",
|
|
57
57
|
"snippets.detect_config": "ℹ️ 检测到项目配置,正在按需过滤代码片段...",
|
|
58
58
|
"snippets.applied_filter": "已应用架构感知过滤 (BasePage: {basePage}, ViewModel: {viewModel})"
|
|
59
|
-
}
|
|
59
|
+
}
|
package/package.json
CHANGED
|
@@ -1,52 +1,59 @@
|
|
|
1
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
|
-
"scripts": {
|
|
27
|
-
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
28
|
-
"dev": "tsup src/index.ts --format cjs,esm --dts --watch"
|
|
29
|
-
},
|
|
30
|
-
"keywords": [
|
|
31
|
-
"flutter",
|
|
32
|
-
"cli",
|
|
33
|
-
"core"
|
|
34
|
-
],
|
|
35
|
-
"author": "火叶工作室",
|
|
36
|
-
"license": "MIT",
|
|
37
|
-
"dependencies": {
|
|
38
|
-
"chalk": "^4.1.2",
|
|
39
|
-
"fs-extra": "^11.2.0",
|
|
40
|
-
"handlebars": "^4.7.8",
|
|
41
|
-
"json5": "^2.2.3",
|
|
42
|
-
"simple-git": "^3.20.0"
|
|
43
|
-
},
|
|
44
|
-
"devDependencies": {
|
|
45
|
-
"@types/chalk": "^0.4.31",
|
|
46
|
-
"@types/fs-extra": "^11.0.4",
|
|
47
|
-
"@types/handlebars": "^4.0.40",
|
|
48
|
-
"@types/node": "^20.19.25",
|
|
49
|
-
"tsup": "^8.0.1",
|
|
50
|
-
"typescript": "^5.3.3"
|
|
2
|
+
"name": "flu-cli-core",
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "Core logic for flu-cli",
|
|
5
|
+
"main": "dist/index.cjs",
|
|
6
|
+
"module": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"templates",
|
|
12
|
+
"locales"
|
|
13
|
+
],
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"import": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
|
+
},
|
|
20
|
+
"require": {
|
|
21
|
+
"types": "./dist/index.d.cts",
|
|
22
|
+
"default": "./dist/index.cjs"
|
|
23
|
+
}
|
|
51
24
|
}
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsup",
|
|
28
|
+
"dev": "tsup --watch",
|
|
29
|
+
"smoke": "npm run build && node scripts/smoke.mjs"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"flutter",
|
|
33
|
+
"cli",
|
|
34
|
+
"core"
|
|
35
|
+
],
|
|
36
|
+
"author": "火叶工作室",
|
|
37
|
+
"license": "MIT",
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@huoye/app-ship": "^0.1.0",
|
|
40
|
+
"axios": "^1.13.2",
|
|
41
|
+
"chalk": "^4.1.2",
|
|
42
|
+
"form-data": "^4.0.5",
|
|
43
|
+
"fs-extra": "^11.2.0",
|
|
44
|
+
"handlebars": "^4.7.8",
|
|
45
|
+
"js-yaml": "^4.1.1",
|
|
46
|
+
"json5": "^2.2.3",
|
|
47
|
+
"simple-git": "^3.20.0"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@types/chalk": "^0.4.31",
|
|
51
|
+
"@types/form-data": "^2.2.1",
|
|
52
|
+
"@types/fs-extra": "^11.0.4",
|
|
53
|
+
"@types/handlebars": "^4.0.40",
|
|
54
|
+
"@types/js-yaml": "^4.0.9",
|
|
55
|
+
"@types/node": "^20.19.25",
|
|
56
|
+
"tsup": "^8.0.1",
|
|
57
|
+
"typescript": "^5.3.3"
|
|
58
|
+
}
|
|
52
59
|
}
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
///
|
|
3
3
|
/// 规范化所有网络请求和业务逻辑中的错误码,避免魔法数字
|
|
4
4
|
class AppErrorCode {
|
|
5
|
-
|
|
5
|
+
|
|
6
6
|
// 成功码
|
|
7
|
-
|
|
7
|
+
|
|
8
8
|
|
|
9
9
|
/// 标准成功码
|
|
10
10
|
static const int success = 200;
|
|
@@ -12,9 +12,9 @@ class AppErrorCode {
|
|
|
12
12
|
/// 备用成功码 (兼容某些后端使用 0 表示成功)
|
|
13
13
|
static const int successAlt = 0;
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
|
|
16
16
|
// HTTP 标准状态码
|
|
17
|
-
|
|
17
|
+
|
|
18
18
|
|
|
19
19
|
/// 未授权 - 需要登录
|
|
20
20
|
static const int unauthorized = 401;
|
|
@@ -28,9 +28,9 @@ class AppErrorCode {
|
|
|
28
28
|
/// 服务器内部错误
|
|
29
29
|
static const int serverError = 500;
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
|
|
32
32
|
// 自定义错误码 (负数区间)
|
|
33
|
-
|
|
33
|
+
|
|
34
34
|
|
|
35
35
|
/// 网络连接错误
|
|
36
36
|
static const int networkError = -1;
|
|
@@ -89,9 +89,9 @@ class AppHttp {
|
|
|
89
89
|
instance._initialized = true;
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
|
|
92
|
+
|
|
93
93
|
// 核心请求方法 - 统一返回 AppResponse,不抛异常
|
|
94
|
-
|
|
94
|
+
|
|
95
95
|
|
|
96
96
|
/// GET 请求
|
|
97
97
|
///
|
|
@@ -183,9 +183,9 @@ class AppHttp {
|
|
|
183
183
|
);
|
|
184
184
|
}
|
|
185
185
|
|
|
186
|
-
|
|
186
|
+
|
|
187
187
|
// 私有统一请求处理逻辑
|
|
188
|
-
|
|
188
|
+
|
|
189
189
|
|
|
190
190
|
Future<AppResponse<T>> _request<T>({
|
|
191
191
|
required String method,
|
|
@@ -52,9 +52,9 @@ class AppResponse<T> {
|
|
|
52
52
|
);
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
|
|
56
56
|
// 状态判断方法
|
|
57
|
-
|
|
57
|
+
|
|
58
58
|
|
|
59
59
|
/// 请求是否成功
|
|
60
60
|
bool get isSuccess => code == AppErrorCode.success || code == AppErrorCode.successAlt;
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import 'package:flutter/material.dart';
|
|
2
|
-
|
|
2
|
+
{{#if_getx}}
|
|
3
|
+
import 'package:get/get.dart';
|
|
4
|
+
{{else}}
|
|
5
|
+
import '../router/navigator_util.dart';
|
|
6
|
+
{{/if_getx}}
|
|
3
7
|
/// Loading 工具类 - 基于 Overlay 的原生实现
|
|
4
8
|
///
|
|
5
9
|
/// 优点:
|
|
@@ -13,7 +17,7 @@ class LoadingUtil {
|
|
|
13
17
|
///
|
|
14
18
|
/// [context] 上下文
|
|
15
19
|
/// [message] 加载提示文字
|
|
16
|
-
static void show(
|
|
20
|
+
static void show({String message = '加载中...'}) {
|
|
17
21
|
if (_overlayEntry != null) return;
|
|
18
22
|
|
|
19
23
|
_overlayEntry = OverlayEntry(
|
|
@@ -43,8 +47,13 @@ class LoadingUtil {
|
|
|
43
47
|
),
|
|
44
48
|
),
|
|
45
49
|
);
|
|
46
|
-
|
|
47
|
-
|
|
50
|
+
{{#if_getx}}
|
|
51
|
+
Get.context!.overlay.insert(_overlayEntry!);
|
|
52
|
+
{{else}}
|
|
53
|
+
if(NavigatorUtil.navigatorKey.currentContext != null){
|
|
54
|
+
Overlay.of(NavigatorUtil.navigatorKey.currentContext!).insert(_overlayEntry!);
|
|
55
|
+
}
|
|
56
|
+
{{/if_getx}}
|
|
48
57
|
}
|
|
49
58
|
|
|
50
59
|
/// 隐藏 Loading
|
|
@@ -1,21 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"InkWell": {
|
|
3
3
|
"prefix": "ik",
|
|
4
|
-
"body": [
|
|
5
|
-
"InkWell(",
|
|
6
|
-
"\tonTap: () {",
|
|
7
|
-
"\t\t$0",
|
|
8
|
-
"\t},",
|
|
9
|
-
"\tchild: ${1:child},",
|
|
10
|
-
");"
|
|
11
|
-
]
|
|
4
|
+
"body": ["InkWell(", "\tonTap: () {", "\t\t$0", "\t},", "\tchild: ${1:child},", ");"],
|
|
12
5
|
},
|
|
13
6
|
"by": {
|
|
14
7
|
"prefix": "by",
|
|
15
|
-
"body": [
|
|
16
|
-
"Widget body = Container();",
|
|
17
|
-
"return body;"
|
|
18
|
-
]
|
|
8
|
+
"body": ["Widget body = Container();", "return body;"],
|
|
19
9
|
},
|
|
20
10
|
"flu.stPage": {
|
|
21
11
|
"prefix": "stPage",
|
|
@@ -49,8 +39,8 @@
|
|
|
49
39
|
" );",
|
|
50
40
|
" }",
|
|
51
41
|
"}",
|
|
52
|
-
""
|
|
53
|
-
]
|
|
42
|
+
"",
|
|
43
|
+
],
|
|
54
44
|
},
|
|
55
45
|
"flu.lessPage": {
|
|
56
46
|
"prefix": "lessPage",
|
|
@@ -73,8 +63,8 @@
|
|
|
73
63
|
" );",
|
|
74
64
|
" }",
|
|
75
65
|
"}",
|
|
76
|
-
""
|
|
77
|
-
]
|
|
66
|
+
"",
|
|
67
|
+
],
|
|
78
68
|
},
|
|
79
69
|
"flu.stWidget": {
|
|
80
70
|
"prefix": "stWidget",
|
|
@@ -95,8 +85,8 @@
|
|
|
95
85
|
" return Container();",
|
|
96
86
|
" }",
|
|
97
87
|
"}",
|
|
98
|
-
""
|
|
99
|
-
]
|
|
88
|
+
"",
|
|
89
|
+
],
|
|
100
90
|
},
|
|
101
91
|
"flu.lessWidget": {
|
|
102
92
|
"prefix": "lessWidget",
|
|
@@ -112,8 +102,8 @@
|
|
|
112
102
|
" return Container();",
|
|
113
103
|
" }",
|
|
114
104
|
"}",
|
|
115
|
-
""
|
|
116
|
-
]
|
|
105
|
+
"",
|
|
106
|
+
],
|
|
117
107
|
},
|
|
118
108
|
"flu.viewmodel": {
|
|
119
109
|
"prefix": "viewmodel",
|
|
@@ -135,8 +125,8 @@
|
|
|
135
125
|
" // TODO: 刷新逻辑",
|
|
136
126
|
" }",
|
|
137
127
|
"}",
|
|
138
|
-
""
|
|
139
|
-
]
|
|
128
|
+
"",
|
|
129
|
+
],
|
|
140
130
|
},
|
|
141
131
|
"flu.model": {
|
|
142
132
|
"prefix": "model",
|
|
@@ -165,8 +155,8 @@
|
|
|
165
155
|
" };",
|
|
166
156
|
" }",
|
|
167
157
|
"}",
|
|
168
|
-
""
|
|
169
|
-
]
|
|
158
|
+
"",
|
|
159
|
+
],
|
|
170
160
|
},
|
|
171
161
|
"flu.listPage": {
|
|
172
162
|
"prefix": "listPage",
|
|
@@ -198,8 +188,8 @@
|
|
|
198
188
|
" );",
|
|
199
189
|
" }",
|
|
200
190
|
"}",
|
|
201
|
-
""
|
|
202
|
-
]
|
|
191
|
+
"",
|
|
192
|
+
],
|
|
203
193
|
},
|
|
204
194
|
"flu.listViewModel": {
|
|
205
195
|
"prefix": "listViewModel",
|
|
@@ -216,8 +206,8 @@
|
|
|
216
206
|
" return [];",
|
|
217
207
|
" }",
|
|
218
208
|
"}",
|
|
219
|
-
""
|
|
220
|
-
]
|
|
209
|
+
"",
|
|
210
|
+
],
|
|
221
211
|
},
|
|
222
212
|
"flu.service": {
|
|
223
213
|
"prefix": "service",
|
|
@@ -242,8 +232,8 @@
|
|
|
242
232
|
" return null;",
|
|
243
233
|
" }",
|
|
244
234
|
"}",
|
|
245
|
-
""
|
|
246
|
-
]
|
|
235
|
+
"",
|
|
236
|
+
],
|
|
247
237
|
},
|
|
248
238
|
"flu.service.network": {
|
|
249
239
|
"prefix": "serviceNetwork",
|
|
@@ -294,8 +284,8 @@
|
|
|
294
284
|
" return [];",
|
|
295
285
|
" }",
|
|
296
286
|
"}",
|
|
297
|
-
""
|
|
298
|
-
]
|
|
287
|
+
"",
|
|
288
|
+
],
|
|
299
289
|
},
|
|
300
290
|
"flu.component": {
|
|
301
291
|
"prefix": "component",
|
|
@@ -314,7 +304,7 @@
|
|
|
314
304
|
" );",
|
|
315
305
|
" }",
|
|
316
306
|
"}",
|
|
317
|
-
""
|
|
318
|
-
]
|
|
319
|
-
}
|
|
320
|
-
}
|
|
307
|
+
"",
|
|
308
|
+
],
|
|
309
|
+
},
|
|
310
|
+
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import 'package:flutter/material.dart';
|
|
2
|
-
import '../network/http_util.dart';
|
|
3
|
-
import 'loading_util.dart';
|
|
4
|
-
import 'toast_util.dart';
|
|
5
|
-
|
|
6
|
-
/// 网络请求辅助工具
|
|
7
|
-
///
|
|
8
|
-
/// 职责:
|
|
9
|
-
/// 1. 封装通用的网络请求交互逻辑(Loading、错误提示)。
|
|
10
|
-
/// 2. 解耦业务层与 UI 工具层。
|
|
11
|
-
class RequestHelper {
|
|
12
|
-
/// 带 Loading 和自动错误提示的请求包装
|
|
13
|
-
///
|
|
14
|
-
/// [context] 必传,用于展示弹窗和 Toast
|
|
15
|
-
/// [request] 具体的网络请求闭包
|
|
16
|
-
/// [loadingMessage] 自定义加载提示语
|
|
17
|
-
/// [showError] 是否在失败时自动展示 Toast
|
|
18
|
-
/// [showSuccess] 是否在成功时展示 Toast
|
|
19
|
-
/// [successMessage] 成功提示语
|
|
20
|
-
static Future<T> withLoading<T>({
|
|
21
|
-
required BuildContext context,
|
|
22
|
-
required Future<T> Function() request,
|
|
23
|
-
String? loadingMessage,
|
|
24
|
-
bool showError = true,
|
|
25
|
-
bool showSuccess = false,
|
|
26
|
-
String? successMessage,
|
|
27
|
-
}) async {
|
|
28
|
-
LoadingUtil.show(context, message: loadingMessage ?? '加载中...');
|
|
29
|
-
|
|
30
|
-
try {
|
|
31
|
-
final result = await request();
|
|
32
|
-
LoadingUtil.dismiss();
|
|
33
|
-
|
|
34
|
-
// 在 await 之后使用 context 前检查 mounted
|
|
35
|
-
if (showSuccess && context.mounted) {
|
|
36
|
-
ToastUtil.show(context, successMessage ?? '操作成功');
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return result;
|
|
40
|
-
} catch (e) {
|
|
41
|
-
LoadingUtil.dismiss();
|
|
42
|
-
|
|
43
|
-
// 在 await 之后使用 context 前检查 mounted
|
|
44
|
-
if (showError && context.mounted) {
|
|
45
|
-
ToastUtil.show(context, _getErrorMessage(e));
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
rethrow;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/// 集中解析错误信息
|
|
53
|
-
static String _getErrorMessage(dynamic error) {
|
|
54
|
-
if (error is ServerException) return error.message;
|
|
55
|
-
if (error is NetworkException) return error.message;
|
|
56
|
-
if (error is Exception) return error.toString();
|
|
57
|
-
return '请求遇到了点问题,请重试';
|
|
58
|
-
}
|
|
59
|
-
}
|