flu-cli 2.0.5 → 2.1.0

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.
Files changed (45) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +17 -4
  3. package/config/dev.config.js +11 -11
  4. package/config/templates.js +10 -10
  5. package/index.js +554 -102
  6. package/lib/commands/add.js +365 -266
  7. package/lib/commands/assets.js +77 -78
  8. package/lib/commands/cache.js +29 -52
  9. package/lib/commands/completion.js +13 -11
  10. package/lib/commands/config.js +150 -44
  11. package/lib/commands/init-ai-base.js +89 -0
  12. package/lib/commands/newClack.js +269 -178
  13. package/lib/commands/snippets.js +58 -43
  14. package/lib/commands/template.js +98 -58
  15. package/lib/commands/templates.js +101 -57
  16. package/lib/commands/upload.js +313 -0
  17. package/lib/commands/vnext-options.js +206 -0
  18. package/lib/generators/model_generator.js +91 -88
  19. package/lib/generators/page_generator.js +100 -93
  20. package/lib/generators/service_generator.js +44 -39
  21. package/lib/generators/viewmodel_generator.js +25 -29
  22. package/lib/generators/widget_generator.js +30 -35
  23. package/lib/templates/templateCopier.js +14 -15
  24. package/lib/templates/templateManager.js +22 -21
  25. package/lib/utils/config.js +37 -20
  26. package/lib/utils/flutterHelper.js +2 -2
  27. package/lib/utils/i18n.js +3 -3
  28. package/lib/utils/index_updater.js +22 -23
  29. package/lib/utils/json-output.js +59 -0
  30. package/lib/utils/logger.js +17 -17
  31. package/lib/utils/project_detector.js +66 -66
  32. package/lib/utils/snippet_loader.js +21 -19
  33. package/lib/utils/string_helper.js +13 -13
  34. package/lib/utils/templateSelectorEnquirer.js +94 -108
  35. package/locales/en-US.json +1 -1
  36. package/locales/zh-CN.json +2 -2
  37. package/package.json +60 -57
  38. package/scripts/smoke-vnext-generate.mjs +1934 -0
  39. package/scripts/smoke-vnext-params.mjs +92 -0
  40. package/CLI.md +0 -513
  41. package/release.sh +0 -529
  42. package/scripts/e2e-state-tests.js +0 -116
  43. package/scripts/sync-base-to-templates.js +0 -108
  44. package/scripts/workspace-clone-all.sh +0 -101
  45. package/scripts/workspace-status-all.sh +0 -112
@@ -0,0 +1,92 @@
1
+ import { buildVNextProjectOptions } from '../lib/commands/vnext-options.js'
2
+
3
+ function assert(condition, message) {
4
+ if (!condition) {
5
+ throw new Error(message)
6
+ }
7
+ }
8
+
9
+ const options = buildVNextProjectOptions({
10
+ auth: true,
11
+ helpers: 'payment,webview,permission,imagePicker',
12
+ examples: 'commonListHome,networkRequest,networkGallery',
13
+ platforms: 'android,ios,harmony',
14
+ architectureMode: 'native',
15
+ compositionProfile: 'base_mixins',
16
+ enableMixinOptions: 'true',
17
+ serialization: 'freezed',
18
+ flutterSdk: 'custom',
19
+ flutterBin: '/opt/flutter/bin/flutter',
20
+ })
21
+
22
+ assert(options.capabilities.auth.enabled === true, 'auth should enable auth capability')
23
+ assert(options.capabilities.serialization.enabled === true, 'serialization should be enabled')
24
+ assert(options.capabilities.serialization.strategy === 'freezed', 'serialization strategy mismatch')
25
+ assert(
26
+ options.capabilities.serialization.buildRunner === true,
27
+ 'freezed serialization should enable build_runner',
28
+ )
29
+ assert(options.helpers.payment === true, 'payment helper should be enabled')
30
+ assert(options.helpers.webview === true, 'webview helper should be enabled')
31
+ assert(options.helpers.permission === true, 'permission helper should be enabled')
32
+ assert(options.helpers.imagePicker === true, 'imagePicker helper should be enabled')
33
+ assert(
34
+ options.examples.join(',') === 'networkGallery',
35
+ 'default list example should be ignored and network request alias should normalize to gallery',
36
+ )
37
+ assert(options.architectureMode === 'native', 'architecture mode should normalize to native')
38
+ assert(options.enableMixinOptions === true, 'enableMixinOptions should normalize to true')
39
+ assert(
40
+ options.composition.profile === 'base_mixins',
41
+ 'composition profile should preserve base_mixins',
42
+ )
43
+ assert(
44
+ options.composition.architectureMode === 'native',
45
+ 'composition architecture mode should be preserved',
46
+ )
47
+ assert(
48
+ options.composition.enableMixinOptions === true,
49
+ 'composition mixin option flag should be preserved',
50
+ )
51
+ assert(options.platforms.join(',') === 'android,ios,harmony', 'platforms should preserve CLI order')
52
+ assert(options.flutterSdk.mode === 'custom', 'flutter SDK mode mismatch')
53
+ assert(options.flutterSdk.flutterBin === '/opt/flutter/bin/flutter', 'custom flutter bin mismatch')
54
+
55
+ const fvmOptions = buildVNextProjectOptions({
56
+ helpers: 'image-picker',
57
+ examples: 'gallery,request,webview,permission,image-picker,payment',
58
+ platforms: 'harmonyos',
59
+ compositionProfile: 'pure_mixins',
60
+ serialization: 'manual',
61
+ flutterSdk: 'fvm',
62
+ flutterSdkVersion: '3.22.0',
63
+ })
64
+
65
+ assert(fvmOptions.helpers.imagePicker === true, 'image-picker alias should map to imagePicker')
66
+ assert(
67
+ fvmOptions.examples.join(',') ===
68
+ 'networkGallery,webviewBasic,permissionBasic,imagePickerBasic,paymentShell',
69
+ 'example aliases should normalize to official example ids',
70
+ )
71
+ assert(fvmOptions.platforms[0] === 'harmony', 'harmonyos should normalize to harmony')
72
+ assert(fvmOptions.flutterSdk.mode === 'fvm', 'fvm Flutter SDK mode mismatch')
73
+ assert(fvmOptions.flutterSdk.version === '3.22.0', 'fvm Flutter SDK version mismatch')
74
+ assert(
75
+ fvmOptions.architectureMode === 'native',
76
+ 'pure profile should default architecture mode to native',
77
+ )
78
+ assert(
79
+ fvmOptions.enableMixinOptions === true,
80
+ 'pure_mixins should default enableMixinOptions to true',
81
+ )
82
+ assert(fvmOptions.composition.profile === 'pure', 'pure_mixins should normalize to pure profile')
83
+ assert(
84
+ fvmOptions.capabilities.serialization.enabled === true,
85
+ 'manual serialization should be enabled',
86
+ )
87
+ assert(
88
+ fvmOptions.capabilities.serialization.buildRunner === false,
89
+ 'manual serialization should not enable build_runner',
90
+ )
91
+
92
+ console.log('cli vNext params smoke: ok')
package/CLI.md DELETED
@@ -1,513 +0,0 @@
1
- # Flu-CLI v2 命令参考
2
-
3
- > Flutter MVVM 脚手架工具 - 快速生成项目和代码
4
-
5
- ## 快速开始
6
-
7
- ```bash
8
- # 创建新项目
9
- flu-cli new my_app
10
-
11
- # 添加页面
12
- flu-cli add page home
13
-
14
- # 查看帮助
15
- flu-cli --help
16
- ```
17
-
18
- ## 新增特性(v2)
19
-
20
- - 自定义模板管理:支持从本地目录或 Git 仓库添加模板,并在交互式创建时与内置模板一起选择。
21
- - 项目生成配置:支持在项目根使用 `.flu-cli.json` 配置生成器默认行为(路径、页面类型、是否绑定 ViewModel 等)。
22
- - 生成联动:CLI 与 VSCode 扩展均会读取 `.flu-cli.json`,保持生成路径与风格一致。
23
- - Riverpod 原生支持:可选择 Riverpod 状态管理并生成原生风格的 VM/页面(如果模板包含入口片段会自动包裹 `ProviderScope`)。
24
-
25
- ## 命令列表
26
-
27
- ### 1. `new` - 创建项目
28
-
29
- 创建一个新的 Flutter 项目,支持多种模板和状态管理器。
30
-
31
- **选项:**
32
-
33
- ```bash
34
- flu-cli new [项目名称] [选项]
35
- flu-cli n [项目名称] # 简写
36
- ```
37
-
38
- **选项:**
39
-
40
- - `-t, --template <type>` - 模板类型: `lite`, `modular`, `clean`
41
- - `-s, --state <type>` - 状态管理器: `default`, `provider`, `getx`, `riverpod`
42
- - `-d, --dir <path>` - 项目存放目录(默认:当前目录)
43
- - `--no-cache` - 不使用缓存,强制从 Git 拉取
44
- - `--no-network` - 不包含网络层(默认包含)
45
- - `--remote` - 使用远程 Gitee 模板(默认使用本地模板)
46
-
47
- **说明:**
48
-
49
- - 交互式创建时会展示“内置模板 + 你通过 `template add` 保存的自定义模板”,可直接选择。
50
- - 模板复制后会执行占位符替换(如 `{{projectName}}`、`{{package_name}}`)并校正 `pubspec.yaml` 的 `name`。
51
- - 已存在 `.flu-cli.json` 的项目中再次生成文件时,会遵循其中的路径与风格设置。
52
-
53
- **示例:**
54
-
55
- ```bash
56
- # 交互式创建(推荐)
57
- flu-cli new
58
-
59
- # 指定项目名和模板
60
- flu-cli new my_app -t lite
61
-
62
- # 指定状态管理器
63
- flu-cli new my_app -s getx
64
-
65
- # 完整配置
66
- flu-cli new my_app -t modular -s provider -d ~/projects
67
- ```
68
-
69
- ---
70
-
71
- ### 2. `add` - 添加组件
72
-
73
- 在当前项目中添加各种代码组件。
74
-
75
- **用法:**
76
-
77
- ```bash
78
- flu-cli add <类型> <名称> [选项]
79
- flu-cli a <类型> <名称> # 简写
80
- ```
81
-
82
- **支持的类型及别名:**
83
-
84
- | 类型 | 别名 | 说明 |
85
- | ----------- | ----- | ------------ |
86
- | `page` | `p` | 页面组件 |
87
- | `widget` | `w` | 通用组件 |
88
- | `component` | `c` | 业务组件 |
89
- | `viewmodel` | `v` | ViewModel |
90
- | `service` | `s` | 服务层 |
91
- | `model` | `m` | 数据模型 |
92
- | `module` | `mod` | 完整功能模块 |
93
-
94
- **选项:**
95
-
96
- - `-f, --feature <name>` - 所属功能模块(仅 modular/clean 模式)
97
- - `--stateful` - 创建 StatefulWidget
98
- - `--stateless` - 强制创建 StatelessWidget
99
- - `--list-page` - 创建列表页 (BaseListPage)
100
- - `--no-vm` - 不生成 ViewModel(仅 page 类型)
101
- - `--type <type>` - Service 类型: `api`, `storage`, `auth`(仅 service 类型)
102
- - `--json <file>` - 从 JSON 文件生成(仅 model 类型)
103
- - `--list` - 查看支持的类型列表
104
-
105
- **说明:**
106
-
107
- - 若项目根存在 `.flu-cli.json`,`add` 会遵循其中的路径与默认类型(如 `generators.page.path`、`defaultType`、`withViewModel`)。
108
- - 在 `modular/clean` 模板下可用 `-f <feature>` 指定模块以生成到模块目录结构(如 `lib/features/user/...`)。
109
-
110
- **示例:**
111
-
112
- ```bash
113
- # 添加页面(自动生成 ViewModel)
114
- flu-cli add page home
115
- flu-cli add p home # 简写
116
-
117
- # 添加列表页
118
- flu-cli add page user_list --list-page
119
-
120
- # 添加无状态页面
121
- flu-cli add page about --stateless --no-vm
122
-
123
- # 添加组件
124
- flu-cli add widget custom_button
125
- flu-cli add w custom_button # 简写
126
-
127
- # 添加 Service
128
- flu-cli add service api --type api
129
- flu-cli add s auth --type auth # 简写 + 指定类型
130
-
131
- # 添加 Model
132
- flu-cli add model user
133
- flu-cli add m user # 简写
134
-
135
- # 在功能模块下添加(modular/clean 模式)
136
- flu-cli add page product -f shop
137
- ```
138
-
139
- ### 2.5 `service` - 服务层
140
-
141
- 生成 API、存储等服务。
142
-
143
- **选项:**
144
-
145
- - `-f, --feature <name>` - 指定功能模块
146
- - `--type <type>` - 服务类型: api, storage, auth (默认: api) [**已废弃**: 默认生成基础 Service 结构]
147
-
148
- **示例:**
149
-
150
- ```bash
151
- # 生成 User 服务
152
- flu-cli add service user
153
-
154
- # 在 auth 模块中生成 AuthService
155
- flu-cli add service auth --feature auth
156
- ```
157
-
158
- ---
159
-
160
- ### 3. `templates` - 模板管理
161
-
162
- 查看可用模板列表或指定模板的详细信息。
163
-
164
- **用法:**
165
-
166
- ```bash
167
- flu-cli templates [模板名称]
168
- flu-cli t [模板名称] # 简写
169
- ```
170
-
171
- **示例:**
172
-
173
- ```bash
174
- # 查看所有模板
175
- flu-cli templates
176
-
177
- # 查看指定模板详情
178
- flu-cli templates lite
179
- flu-cli t modular # 简写
180
- ```
181
-
182
- ---
183
-
184
- ### 9. `template` - 自定义模板管理(新增)
185
-
186
- 用于管理你自己的项目模板,支持从本地目录或 Git 仓库新增模板,并持久化到 `~/.flu-cli/config.json`。在交互式创建项目时,这些模板会与内置模板一起展示并可直接选择。
187
-
188
- **用法:**
189
-
190
- ```bash
191
- flu-cli template # 查看所有自定义模板(同 list)
192
- flu-cli template list # 列出所有模板
193
- flu-cli template add <id> <source> [选项]
194
- flu-cli template remove <id>
195
- ```
196
-
197
- **选项:**
198
-
199
- - `--local` 使用本地目录作为模板(`source` 为路径)
200
- - `-n, --name <name>` 显示名称(可选)
201
- - `-b, --branch <branch>` Git 模板分支(默认 `main`)
202
- - `-d, --description <text>` 模板描述
203
- - `-f, --force` 覆盖已存在的同名模板
204
-
205
- **示例:**
206
-
207
- ```bash
208
- # 添加本地模板
209
- flu-cli template add my-lite /path/to/my-template --local -n "我的 Lite 模板" -d "带业务框架的轻量模板"
210
-
211
- # 添加 Git 模板
212
- flu-cli template add company-clean https://github.com/org/clean-template.git -b main -n "公司 Clean 模板"
213
-
214
- # 列出/移除模板
215
- flu-cli template list
216
- flu-cli template remove my-lite
217
- ```
218
-
219
- **说明:**
220
-
221
- - 模板会缓存到 `~/.flu-cli/templates/<id>/`,创建项目时会从缓存复制。
222
- - 交互式 `flu-cli new` 会把自定义模板和内置模板一起展示,并支持预览说明。
223
- - 选择 Git 模板时会从远端克隆到缓存目录;选择本地模板时会直接复制到缓存目录。
224
-
225
- ---
226
-
227
- ### 10. `config` - 项目生成配置(新增)
228
-
229
- 初始化并管理项目根目录下的 `.flu-cli.json`,用于声明生成器的默认行为(路径、页面类型、是否绑定 ViewModel 等)。VSCode 扩展与 v2 的生成命令都会读取该文件。
230
-
231
- **用法:**
232
-
233
- ```bash
234
- flu-cli config init [选项]
235
- ```
236
-
237
- **选项:**
238
-
239
- - `-d, --dir <path>` 目标项目目录(默认当前目录)
240
- - `-f, --force` 覆盖已存在的配置文件
241
-
242
- **示例:**
243
-
244
- ```bash
245
- # 在当前项目生成配置
246
- flu-cli config init
247
-
248
- # 指定项目目录并覆盖旧配置
249
- flu-cli config init -d ~/projects/my_app -f
250
- ```
251
-
252
- **.flu-cli.json 示例(简化):**
253
-
254
- ```json
255
- {
256
- "generators": {
257
- "page": {
258
- "path": "lib/pages",
259
- "defaultType": "stateful",
260
- "withViewModel": true
261
- },
262
- "viewModel": {
263
- "path": "lib/viewmodels"
264
- },
265
- "model": {
266
- "path": "lib/models"
267
- }
268
- }
269
- }
270
- ```
271
-
272
- **说明:**
273
-
274
- - 初始化时会根据项目模板(lite/modular/clean)生成匹配的默认路径。
275
- - VSCode 插件的“生成文件”命令会优先使用 `.flu-cli.json` 中的设置,无需每次选择类型。
276
- - 可在自定义模板中提供示例 `.flu-cli.json`,在创建后运行 `flu-cli config init -f` 以覆盖为团队约定。
277
-
278
- ---
279
-
280
- ### 5. `update-templates` - 更新模板缓存
281
-
282
- 更新本地模板缓存到最新版本。
283
-
284
- **用法:**
285
-
286
- ```bash
287
- flu-cli update-templates [模板名称]
288
- flu-cli u [模板名称] # 简写
289
- ```
290
-
291
- **选项:**
292
-
293
- - `--force` - 强制刷新并清理未跟踪文件
294
-
295
- **示例:**
296
-
297
- ```bash
298
- # 更新所有模板
299
- flu-cli update-templates
300
-
301
- # 更新指定模板
302
- flu-cli u lite # 简写
303
-
304
- # 强制刷新
305
- flu-cli update-templates --force
306
- ```
307
-
308
- ---
309
-
310
- ### 6. `cache` - 缓存管理
311
-
312
- 管理本地模板缓存。
313
-
314
- **用法:**
315
-
316
- ```bash
317
- flu-cli cache <action>
318
- flu-cli c <action> # 简写
319
- ```
320
-
321
- **支持的操作:**
322
-
323
- - `clean` - 清理缓存
324
-
325
- **示例:**
326
-
327
- ```bash
328
- # 清理缓存
329
- flu-cli cache clean
330
- flu-cli c clean # 简写
331
- ```
332
-
333
- ---
334
-
335
- ### 7. `completion` - 自动补全
336
-
337
- 生成 Shell 自动补全脚本(支持 Bash/Zsh)。
338
-
339
- **用法:**
340
-
341
- ```bash
342
- flu-cli completion
343
- flu-cli comp # 简写
344
- ```
345
-
346
- **安装方法:**
347
-
348
- ```bash
349
- # Zsh
350
- flu-cli completion >> ~/.zshrc
351
- source ~/.zshrc
352
-
353
- # Bash
354
- flu-cli completion >> ~/.bashrc
355
- source ~/.bashrc
356
- ```
357
-
358
- ---
359
-
360
- ## 常见问题 (FAQ)
361
-
362
- **Q: `add page` 默认生成的代码不符合我的项目结构怎么办?**
363
-
364
- A: Flu CLI 是为特定架构(MVVM + Provider)设计的。如果您使用完全自定义的架构,建议:
365
-
366
- 1. 使用 `--no-vm` 仅生成页面。
367
- 2. 或者,Fork 本项目并修改模板代码以适配您的团队规范。
368
- 3. 利用 VSCode 插件自带的代码片段 (Snippets) 快速编写代码,而不是依赖 CLI 生成。
369
-
370
- **Q: 为什么生成的 Service 很简单?**
371
-
372
- A: 我们移除了原来复杂的 Service 模板,只生成最基础的类结构。这样您可以自由选择使用 `http`, `dio` 还是其他网络库,而不受 CLI 预设逻辑的限制。
373
-
374
- ---
375
-
376
- ## 常见工作流
377
-
378
- ### 创建新项目
379
-
380
- ```bash
381
- flu-cli new my_app
382
- cd my_app
383
- flutter pub get
384
- flu-cli add page home
385
- flu-cli add page user_list --list-page
386
- ```
387
-
388
- ### 使用自定义模板创建项目
389
-
390
- ````bash
391
- # 添加模板(本地或 Git)
392
- flu-cli template add my-lite /path/to/my-template --local
393
- # 或
394
- flu-cli template add company-clean https://github.com/org/clean-template.git -b main
395
-
396
- # 交互式选择自定义模板并创建
397
- flu-cli new
398
-
399
- # 初始化项目生成配置(让 VSCode/CLI 生成遵循你的路径约定)
400
- flu-cli config init
401
-
402
- ### 基于配置快速生成页面/VM
403
- ```bash
404
- # 初始化配置后:
405
- flu-cli add page home # 路径/类型按 .flu-cli.json 生效
406
- flu-cli add viewmodel home # VM 路径按配置生效
407
- flu-cli add model user # Model 路径按配置生效
408
- ````
409
-
410
- ### 更新模板缓存与故障排除
411
-
412
- ```bash
413
- # 更新缓存到最新
414
- flu-cli update-templates [模板ID]
415
-
416
- # 模板拉取失败或缓存异常
417
- flu-cli cache clean
418
- flu-cli new my_app --no-cache
419
- ```
420
-
421
- ````
422
-
423
- ### 在现有项目中使用
424
-
425
- ```bash
426
- cd existing_project
427
-
428
- # 初始化配置文件
429
- flu-cli config init
430
-
431
- # 添加组件
432
- flu-cli add page settings
433
- flu-cli add service api
434
- ````
435
-
436
- ### Modular 架构项目
437
-
438
- ```bash
439
- flu-cli new my_app -t modular
440
- cd my_app
441
-
442
- # 在 shop 模块下添加页面
443
- flu-cli add page product -f shop
444
- flu-cli add page cart -f shop
445
-
446
- # 在 user 模块下添加页面
447
- flu-cli add page profile -f user
448
- ```
449
-
450
- ---
451
-
452
- ## 全局选项
453
-
454
- 所有命令都支持以下选项:
455
-
456
- - `-V, --version` - 查看版本号
457
- - `-h, --help` - 查看帮助信息
458
-
459
- **示例:**
460
-
461
- ```bash
462
- flu-cli --version
463
- flu-cli add --help
464
- ```
465
-
466
- ---
467
-
468
- ## 配置文件
469
-
470
- Flu-CLI 会在以下位置存储配置:
471
-
472
- - **缓存目录**: `~/.flu-cli/cache/`
473
- - **配置文件**: `~/.flu-cli/config.json`
474
-
475
- ---
476
-
477
- ## 故障排除
478
-
479
- ### 命令卡住
480
-
481
- 如果命令执行过程中卡住,可以:
482
-
483
- 1. 按 `Ctrl+C` 中止
484
- 2. 运行 `flu-cli cache clean` 清理缓存
485
- 3. 重新执行命令
486
-
487
- ### 模板拉取失败
488
-
489
- ```bash
490
- # 清理缓存后重试
491
- flu-cli cache clean
492
- flu-cli new my_app
493
-
494
- # 或使用本地模板(开发环境)
495
- flu-cli new my_app --no-cache
496
- ```
497
-
498
- ### 代码片段不生效
499
-
500
- VSCode 扩展使用**动态代码片段**功能,会根据项目配置自动适配:
501
-
502
- 1. 确保已安装 Flu CLI VSCode 扩展
503
- 2. 打开 `.dart` 文件时扩展会自动激活
504
- 3. 代码片段会根据 `.flu-cli.json` 配置动态显示
505
- 4. 如果看不到代码片段,尝试重启 VSCode
506
-
507
- ---
508
-
509
- ## 更多帮助
510
-
511
- - 查看具体命令帮助:`flu-cli <command> --help`
512
- - 项目文档:[flu-cli 文档站](https://your-docs-url)
513
- - 问题反馈:[GitHub Issues](https://github.com/your-repo/issues)