flu-cli 0.0.5 → 2.0.1
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/CLI.md +512 -0
- package/README.md +70 -260
- package/config/dev.config.js +56 -0
- package/config/templates.js +147 -0
- package/index.js +177 -81
- package/lib/commands/add.js +595 -0
- package/lib/commands/cache.js +99 -0
- package/lib/commands/completion.js +92 -0
- package/lib/commands/config.js +70 -0
- package/lib/commands/newClack.js +399 -0
- package/lib/commands/snippets.js +39 -0
- package/lib/commands/template.js +113 -0
- package/lib/commands/templates.js +84 -0
- package/lib/generators/model_generator.js +303 -0
- package/lib/generators/page_generator.js +322 -0
- package/lib/generators/project_generator.js +96 -0
- package/lib/generators/service_generator.js +408 -0
- package/lib/generators/state_manager_generator.js +402 -0
- package/lib/generators/viewmodel_generator.js +115 -0
- package/lib/generators/widget_generator.js +104 -0
- package/lib/templates/templateCopier.js +296 -0
- package/lib/templates/templateManager.js +191 -0
- package/lib/utils/config.js +99 -0
- package/lib/utils/flutterHelper.js +85 -0
- package/lib/utils/index_updater.js +69 -0
- package/lib/utils/logger.js +57 -0
- package/lib/utils/project_detector.js +227 -0
- package/lib/utils/snippet_loader.js +32 -0
- package/lib/utils/string_helper.js +56 -0
- package/lib/utils/templateSelectorEnquirer.js +203 -0
- package/package.json +34 -7
- package/release.sh +107 -0
- package/scripts/e2e-state-tests.js +116 -0
- package/scripts/sync-base-to-templates.js +108 -0
- package/scripts/workspace-clone-all.sh +101 -0
- package/scripts/workspace-status-all.sh +112 -0
- package/templates/README.md +138 -0
- package/templates/base_files/base_list_page.dart.template +174 -0
- package/templates/base_files/base_list_viewmodel.dart.template +134 -0
- package/templates/base_files/base_page.dart.template +251 -0
- package/templates/base_files/base_viewmodel.dart.template +77 -0
- package/templates/base_files/theme/status_views_theme.dart.template +46 -0
- package/templates/snippets/dart.code-snippets +392 -0
- package/lib/createProject.js +0 -220
- package/lib/flutterProjectCreator.js +0 -80
- package/lib/libCopier.js +0 -368
- package/lib/userInteraction.js +0 -274
- package/lib/utils.js +0 -200
- package/publish.sh +0 -29
package/index.js
CHANGED
|
@@ -1,108 +1,204 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* flu-cli v2.0
|
|
5
|
+
* Flutter MVVM 脚手架工具
|
|
5
6
|
*
|
|
6
|
-
*
|
|
7
|
+
* 支持多种架构模板和代码生成功能
|
|
7
8
|
*/
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
import { program } from 'commander'
|
|
10
|
+
import { program } from 'commander';
|
|
11
11
|
import chalk from 'chalk';
|
|
12
|
-
import { createProject } from './lib/createProject.js';
|
|
13
12
|
import { readFileSync } from 'fs';
|
|
14
13
|
import { fileURLToPath } from 'url';
|
|
15
14
|
import { dirname, join } from 'path';
|
|
15
|
+
import { newProjectWithClack } from './lib/commands/newClack.js';
|
|
16
|
+
import { addComponent } from './lib/commands/add.js';
|
|
17
|
+
import { listTemplates, showTemplateDetail } from './lib/commands/templates.js';
|
|
18
|
+
import { updateTemplates, cleanCache } from './lib/commands/cache.js';
|
|
19
|
+
// generate-sm 命令已移除
|
|
16
20
|
|
|
17
|
-
// 获取package.json
|
|
21
|
+
// 获取 package.json
|
|
18
22
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
19
23
|
const packageJson = JSON.parse(readFileSync(join(__dirname, 'package.json'), 'utf8'));
|
|
20
24
|
|
|
21
|
-
//
|
|
25
|
+
// 设置版本和描述
|
|
22
26
|
program
|
|
23
27
|
.version(packageJson.version)
|
|
24
|
-
.description(chalk.cyan('
|
|
25
|
-
|
|
26
|
-
//
|
|
28
|
+
.description(chalk.cyan('🚀 Flutter MVVM 脚手架工具'));
|
|
27
29
|
|
|
28
|
-
//
|
|
30
|
+
// ========== 创建项目命令(V1 已废弃) ==========
|
|
31
|
+
// V1 命令已移除,请使用 'flu new' 命令
|
|
29
32
|
program
|
|
30
33
|
.command('create')
|
|
31
|
-
.description('
|
|
32
|
-
.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
34
|
+
.description('⚠️ 已废弃:请使用 flu new 命令')
|
|
35
|
+
.action(() => {
|
|
36
|
+
console.log(chalk.yellow('\n⚠️ create 命令已在 V2 中废弃\n'));
|
|
37
|
+
console.log(chalk.cyan('请使用新命令:'));
|
|
38
|
+
console.log(chalk.green(' flu new <project-name>\n'));
|
|
39
|
+
console.log(chalk.gray('示例:'));
|
|
40
|
+
console.log(chalk.gray(' flu new my_app --template lite'));
|
|
41
|
+
console.log(chalk.gray(' flu new my_app --template modular'));
|
|
42
|
+
console.log(chalk.gray(' flu new my_app --template clean\n'));
|
|
43
|
+
console.log(chalk.blue('查看帮助:flu new --help\n'));
|
|
44
|
+
process.exit(0);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// ========== 新建项目命令(现代化交互式体验) ==========
|
|
48
|
+
program
|
|
49
|
+
.command('new [project-name]')
|
|
50
|
+
.alias('n')
|
|
51
|
+
.description('创建 Flutter 项目(实时模板预览)')
|
|
52
|
+
.option('-t, --template <type>', '模板类型: lite, modular, clean')
|
|
53
|
+
.option('-s, --state <type>', '状态管理器: default, provider, getx, riverpod', 'default')
|
|
54
|
+
.option('-d, --dir <path>', '项目存放目录', process.cwd())
|
|
55
|
+
.option('--no-cache', '不使用缓存,强制从 Git 拉取')
|
|
56
|
+
.option('--remote', '使用远程 Gitee 模板(默认使用本地模板)')
|
|
57
|
+
.action((projectName, options) => {
|
|
58
|
+
newProjectWithClack(projectName, options);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// ========== 添加组件命令 ==========
|
|
62
|
+
program
|
|
63
|
+
.command('add [type] [name]')
|
|
64
|
+
.alias('a')
|
|
65
|
+
.description('添加 Flutter 代码组件 (page/p, widget/w, component/c, ...)')
|
|
66
|
+
.option('-f, --feature <name>', '所属功能模块(仅 modular/clean 模式)')
|
|
67
|
+
.option('--stateful', '创建 StatefulWidget(默认 StatelessWidget)')
|
|
68
|
+
.option('--stateless', '强制创建 StatelessWidget(即使有 ViewModel,不推荐)')
|
|
69
|
+
.option('--list-page', '创建列表页 (BaseListPage)')
|
|
70
|
+
.option('--no-vm', '不生成 ViewModel(仅 page 类型)')
|
|
71
|
+
.option('--json <file>', '从 JSON 文件生成(仅 model 类型)')
|
|
72
|
+
.option('--list', '查看支持的类型列表')
|
|
73
|
+
.action((type, name, options) => {
|
|
74
|
+
addComponent(type, name, options);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// ========== 模板管理命令 ==========
|
|
78
|
+
program
|
|
79
|
+
.command('templates [template-name]')
|
|
80
|
+
.alias('t')
|
|
81
|
+
.description('查看所有模板或指定模板详情')
|
|
82
|
+
.action((templateName) => {
|
|
83
|
+
if (templateName) {
|
|
84
|
+
showTemplateDetail(templateName);
|
|
85
|
+
} else {
|
|
86
|
+
listTemplates();
|
|
56
87
|
}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// generate-sm 命令已移除
|
|
57
91
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
// 如果提供了命令行参数,则直接使用这些参数创建项目
|
|
69
|
-
// 否则使用交互式方式获取参数
|
|
70
|
-
createProject({
|
|
71
|
-
useCommandLineArgs: hasCommandLineArgs,
|
|
72
|
-
projectType: options.projectType,
|
|
73
|
-
templateType: options.templateType,
|
|
74
|
-
stateManager: options.stateManager,
|
|
75
|
-
projectName: options.projectName,
|
|
76
|
-
packageName: options.packageName,
|
|
77
|
-
parentDir: options.parentDir,
|
|
78
|
-
ideChoice: options.ide,
|
|
79
|
-
flutterSdkPath: options.flutterSdk,
|
|
80
|
-
});
|
|
92
|
+
// ========== 缓存管理命令 ==========
|
|
93
|
+
program
|
|
94
|
+
.command('update-templates [template-name]')
|
|
95
|
+
.alias('update')
|
|
96
|
+
.alias('u')
|
|
97
|
+
.description('更新模板缓存')
|
|
98
|
+
.option('--force', '强制刷新并清理未跟踪文件')
|
|
99
|
+
.action((templateName, options) => {
|
|
100
|
+
updateTemplates(templateName, options);
|
|
81
101
|
});
|
|
82
102
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
103
|
+
program
|
|
104
|
+
.command('cache <action>')
|
|
105
|
+
.alias('c')
|
|
106
|
+
.description('缓存管理 (action: clean)')
|
|
107
|
+
.action((action) => {
|
|
108
|
+
if (action === 'clean') {
|
|
109
|
+
cleanCache();
|
|
110
|
+
} else {
|
|
111
|
+
console.log(chalk.red(`未知的操作: ${action}`));
|
|
112
|
+
console.log(chalk.yellow('支持的操作: clean'));
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// ========== 代码片段管理 ==========
|
|
117
|
+
import { syncSnippets } from './lib/commands/snippets.js';
|
|
118
|
+
|
|
119
|
+
program
|
|
120
|
+
.command('sync-snippets')
|
|
121
|
+
.alias('sync')
|
|
122
|
+
.description('同步最新版本的标准代码片段到当前项目')
|
|
123
|
+
.action(() => {
|
|
124
|
+
syncSnippets();
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
// ========== 模板管理命令 (New) ==========
|
|
128
|
+
import { listAllTemplates, addTemplate, removeTemplate } from './lib/commands/template.js';
|
|
129
|
+
|
|
130
|
+
const templateCmd = program.command('template');
|
|
131
|
+
|
|
132
|
+
templateCmd
|
|
133
|
+
.description('管理自定义项目模板')
|
|
134
|
+
.action(() => {
|
|
135
|
+
listAllTemplates();
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
templateCmd
|
|
139
|
+
.command('list')
|
|
140
|
+
.description('列出所有模板')
|
|
141
|
+
.action(() => {
|
|
142
|
+
listAllTemplates();
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
templateCmd
|
|
146
|
+
.command('add <id> <source>')
|
|
147
|
+
.description('添加自定义模板 (id: 唯一标识, source: Git URL 或本地路径)')
|
|
148
|
+
.option('--local', '添加本地模板 (source 为路径)')
|
|
149
|
+
.option('-n, --name <name>', '显示名称')
|
|
150
|
+
.option('-b, --branch <branch>', 'Git 分支 (默认 main)')
|
|
151
|
+
.option('-d, --description <text>', '描述信息')
|
|
152
|
+
.option('-f, --force', '覆盖已存在的模板')
|
|
153
|
+
.action((id, source, options) => {
|
|
154
|
+
addTemplate(id, source, options);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
templateCmd
|
|
158
|
+
.command('remove <id>')
|
|
159
|
+
.description('删除自定义模板')
|
|
160
|
+
.action((id) => {
|
|
161
|
+
removeTemplate(id);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
// ========== 自动补全 ==========
|
|
165
|
+
import { completion } from './lib/commands/completion.js';
|
|
166
|
+
|
|
167
|
+
program
|
|
168
|
+
.command('completion')
|
|
169
|
+
.alias('comp')
|
|
170
|
+
.description('生成 Shell 自动补全脚本 (bash/zsh)')
|
|
171
|
+
.action(() => {
|
|
172
|
+
completion();
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
// ========== 配置管理命令 ==========
|
|
177
|
+
import { initConfig } from './lib/commands/config.js';
|
|
178
|
+
|
|
179
|
+
const configCmd = program.command('config');
|
|
180
|
+
|
|
181
|
+
configCmd
|
|
182
|
+
.description('管理项目生成配置 (.flu-cli.json)')
|
|
183
|
+
.action(() => {
|
|
184
|
+
configCmd.help();
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
configCmd
|
|
188
|
+
.command('init')
|
|
189
|
+
.description('初始化配置文件 (基于当前项目结构)')
|
|
190
|
+
.option('-d, --dir <path>', '项目目录', process.cwd())
|
|
191
|
+
.option('-f, --force', '覆盖已存在的配置文件')
|
|
192
|
+
.action((options) => {
|
|
193
|
+
initConfig(options);
|
|
194
|
+
});
|
|
99
195
|
|
|
100
196
|
|
|
197
|
+
// 解析命令行参数
|
|
198
|
+
program.parse(process.argv);
|
|
101
199
|
|
|
102
|
-
//
|
|
200
|
+
// 如果没有提供命令,显示帮助信息
|
|
103
201
|
if (process.argv.length === 2) {
|
|
104
|
-
console.log(chalk.bold.
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
program.parse(process.argv);
|
|
108
|
-
}
|
|
202
|
+
console.log(chalk.bold.cyan('\n🚀 欢迎使用 flu-cli v2.0\n'));
|
|
203
|
+
program.help({ error: false });
|
|
204
|
+
}
|