@lppx/nlearn 1.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 (19) hide show
  1. package/dist/scripts/sync-repo.js +100 -0
  2. package/dist/src/cli/cli.js +9 -0
  3. package/dist/src/demo/commander/01-/345/237/272/347/241/200/346/246/202/345/277/265.js +174 -0
  4. package/dist/src/demo/commander/02-/345/221/275/344/273/244/347/263/273/347/273/237.js +260 -0
  5. package/dist/src/demo/commander/03-/351/253/230/347/272/247/347/211/271/346/200/247.js +285 -0
  6. package/dist/src/demo/commander/04-/345/256/236/346/210/230/346/241/210/344/276/213.js +408 -0
  7. package/dist/src/demo/esm/01-/345/237/272/347/241/200/346/246/202/345/277/265.js +226 -0
  8. package/dist/src/demo/esm/02-/345/257/274/345/207/272/350/257/255/346/263/225.js +281 -0
  9. package/dist/src/demo/esm/03-/345/257/274/345/205/245/350/257/255/346/263/225.js +366 -0
  10. package/dist/src/demo/esm/04-/345/256/236/346/210/230/346/241/210/344/276/213.js +509 -0
  11. package/dist/src/demo/inquirer/01-/345/237/272/347/241/200/346/246/202/345/277/265.js +135 -0
  12. package/dist/src/demo/inquirer/02-/351/200/211/346/213/251/347/261/273/345/236/213.js +143 -0
  13. package/dist/src/demo/inquirer/03-/351/253/230/347/272/247/347/211/271/346/200/247.js +211 -0
  14. package/dist/src/demo/inquirer/04-/345/256/236/346/210/230/346/241/210/344/276/213.js +343 -0
  15. package/dist/src/demo/yargs/01-/345/237/272/347/241/200/346/246/202/345/277/265.js +142 -0
  16. package/dist/src/demo/yargs/02-/345/221/275/344/273/244/347/263/273/347/273/237.js +211 -0
  17. package/dist/src/demo/yargs/03-/351/253/230/347/272/247/347/211/271/346/200/247.js +205 -0
  18. package/dist/src/demo/yargs/04-/345/256/236/346/210/230/346/241/210/344/276/213.js +276 -0
  19. package/package.json +39 -0
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+ /**
3
+ * Inquirer.js 选择类型
4
+ * ===================
5
+ * 介绍各种选择类型的问题:单选、多选、列表等
6
+ * 这些是构建 CLI 工具中最常用的交互方式
7
+ */
8
+ var __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const inquirer_1 = __importDefault(require("inquirer"));
13
+ // #region 示例1: 列表单选 (list)
14
+ async function listChoice() {
15
+ console.log('\n=== 示例1: 列表单选 ===\n');
16
+ const answers = await inquirer_1.default.prompt([
17
+ {
18
+ type: 'list',
19
+ name: 'framework',
20
+ message: '选择你喜欢的前端框架:',
21
+ choices: ['React', 'Vue', 'Angular', 'Svelte'],
22
+ }
23
+ ]);
24
+ console.log(`你选择了: ${answers.framework}`);
25
+ }
26
+ // #endregion
27
+ // #region 示例2: 原始列表 (rawlist)
28
+ async function rawListChoice() {
29
+ console.log('\n=== 示例2: 原始列表 (带数字索引) ===\n');
30
+ const answers = await inquirer_1.default.prompt([
31
+ {
32
+ type: 'rawlist',
33
+ name: 'language',
34
+ message: '选择编程语言:',
35
+ choices: ['JavaScript', 'TypeScript', 'Python', 'Go', 'Rust'],
36
+ }
37
+ ]);
38
+ console.log(`你选择了: ${answers.language}`);
39
+ }
40
+ // #endregion
41
+ // #region 示例3: 扩展列表 (expand)
42
+ async function expandChoice() {
43
+ console.log('\n=== 示例3: 扩展列表 (快捷键选择) ===\n');
44
+ const answers = await inquirer_1.default.prompt([
45
+ {
46
+ type: 'expand',
47
+ name: 'action',
48
+ message: '选择操作:',
49
+ choices: [
50
+ { key: 'c', name: '创建', value: 'create' },
51
+ { key: 'u', name: '更新', value: 'update' },
52
+ { key: 'd', name: '删除', value: 'delete' },
53
+ { key: 'r', name: '读取', value: 'read' },
54
+ ],
55
+ }
56
+ ]);
57
+ console.log(`执行操作: ${answers.action}`);
58
+ }
59
+ // #endregion
60
+ // #region 示例4: 多选 (checkbox)
61
+ async function checkboxChoice() {
62
+ console.log('\n=== 示例4: 多选 ===\n');
63
+ const answers = await inquirer_1.default.prompt([
64
+ {
65
+ type: 'checkbox',
66
+ name: 'features',
67
+ message: '选择需要的功能 (空格选择,回车确认):',
68
+ choices: [
69
+ { name: 'TypeScript', checked: true },
70
+ { name: 'ESLint', checked: true },
71
+ { name: 'Prettier' },
72
+ { name: 'Jest' },
73
+ { name: 'Husky' },
74
+ ],
75
+ }
76
+ ]);
77
+ console.log('已选择的功能:');
78
+ answers.features.forEach((feature) => {
79
+ console.log(` - ${feature}`);
80
+ });
81
+ }
82
+ // #endregion
83
+ // #region 示例5: 带分隔符的选择
84
+ async function choiceWithSeparator() {
85
+ console.log('\n=== 示例5: 带分隔符的选择 ===\n');
86
+ const answers = await inquirer_1.default.prompt([
87
+ {
88
+ type: 'list',
89
+ name: 'package',
90
+ message: '选择要安装的包:',
91
+ choices: [
92
+ '--- 框架 ---',
93
+ 'express',
94
+ 'koa',
95
+ 'fastify',
96
+ new inquirer_1.default.Separator(),
97
+ '--- 工具库 ---',
98
+ 'lodash',
99
+ 'axios',
100
+ 'dayjs',
101
+ ],
102
+ }
103
+ ]);
104
+ console.log(`选择安装: ${answers.package}`);
105
+ }
106
+ // #endregion
107
+ // #region 示例6: 带值的选择项
108
+ async function choiceWithValue() {
109
+ console.log('\n=== 示例6: 带值的选择项 ===\n');
110
+ const answers = await inquirer_1.default.prompt([
111
+ {
112
+ type: 'list',
113
+ name: 'size',
114
+ message: '选择实例规格:',
115
+ choices: [
116
+ { name: '小型 (1核2G) - ¥50/月', value: 'small' },
117
+ { name: '中型 (2核4G) - ¥100/月', value: 'medium' },
118
+ { name: '大型 (4核8G) - ¥200/月', value: 'large' },
119
+ { name: '超大型 (8核16G) - ¥400/月', value: 'xlarge' },
120
+ ],
121
+ }
122
+ ]);
123
+ console.log(`选择的规格代码: ${answers.size}`);
124
+ }
125
+ // #endregion
126
+ if (require.main === module) {
127
+ const exampleNumber = process.argv[2];
128
+ const examples = {
129
+ '1': listChoice,
130
+ '2': rawListChoice,
131
+ '3': expandChoice,
132
+ '4': checkboxChoice,
133
+ '5': choiceWithSeparator,
134
+ '6': choiceWithValue,
135
+ };
136
+ if (exampleNumber && examples[exampleNumber]) {
137
+ examples[exampleNumber]();
138
+ }
139
+ else {
140
+ console.log('请指定示例编号 (1-6)');
141
+ console.log('例如: ts-node src/demo/inquirer/02-选择类型.ts 1');
142
+ }
143
+ }
@@ -0,0 +1,211 @@
1
+ "use strict";
2
+ /**
3
+ * Inquirer.js 高级特性
4
+ * ===================
5
+ * 介绍验证、过滤、条件显示、循环等高级功能
6
+ * 这些特性让交互更加智能和用户友好
7
+ */
8
+ var __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const inquirer_1 = __importDefault(require("inquirer"));
13
+ // #region 示例1: 输入验证
14
+ async function inputValidation() {
15
+ console.log('\n=== 示例1: 输入验证 ===\n');
16
+ const answers = await inquirer_1.default.prompt([
17
+ {
18
+ type: 'input',
19
+ name: 'email',
20
+ message: '请输入邮箱地址:',
21
+ validate: (input) => {
22
+ const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
23
+ if (emailRegex.test(input)) {
24
+ return true;
25
+ }
26
+ return '请输入有效的邮箱地址';
27
+ },
28
+ },
29
+ {
30
+ type: 'input',
31
+ name: 'phone',
32
+ message: '请输入手机号:',
33
+ validate: (input) => {
34
+ if (/^1[3-9]\d{9}$/.test(input)) {
35
+ return true;
36
+ }
37
+ return '请输入有效的11位手机号';
38
+ },
39
+ }
40
+ ]);
41
+ console.log('验证通过的信息:');
42
+ console.log(JSON.stringify(answers, null, 2));
43
+ }
44
+ // #endregion
45
+ // #region 示例2: 输入过滤和转换
46
+ async function inputFilter() {
47
+ console.log('\n=== 示例2: 输入过滤和转换 ===\n');
48
+ const answers = await inquirer_1.default.prompt([
49
+ {
50
+ type: 'input',
51
+ name: 'username',
52
+ message: '请输入用户名:',
53
+ filter: (input) => {
54
+ // 自动转换为小写并去除空格
55
+ return input.toLowerCase().trim();
56
+ },
57
+ },
58
+ {
59
+ type: 'input',
60
+ name: 'tags',
61
+ message: '请输入标签 (逗号分隔):',
62
+ filter: (input) => {
63
+ // 转换为数组
64
+ return input.split(',').map(tag => tag.trim());
65
+ },
66
+ }
67
+ ]);
68
+ console.log('处理后的数据:');
69
+ console.log(JSON.stringify(answers, null, 2));
70
+ }
71
+ // #endregion
72
+ // #region 示例3: 条件显示问题 (when)
73
+ async function conditionalQuestions() {
74
+ console.log('\n=== 示例3: 条件显示问题 ===\n');
75
+ const answers = await inquirer_1.default.prompt([
76
+ {
77
+ type: 'confirm',
78
+ name: 'needsDatabase',
79
+ message: '项目需要数据库吗?',
80
+ default: true,
81
+ },
82
+ {
83
+ type: 'list',
84
+ name: 'database',
85
+ message: '选择数据库类型:',
86
+ choices: ['MySQL', 'PostgreSQL', 'MongoDB', 'Redis'],
87
+ when: (answers) => answers.needsDatabase, // 只有选择需要数据库时才显示
88
+ },
89
+ {
90
+ type: 'input',
91
+ name: 'dbHost',
92
+ message: '数据库主机地址:',
93
+ default: 'localhost',
94
+ when: (answers) => answers.needsDatabase,
95
+ }
96
+ ]);
97
+ console.log('配置结果:');
98
+ console.log(JSON.stringify(answers, null, 2));
99
+ }
100
+ // #endregion
101
+ // #region 示例4: 动态默认值
102
+ async function dynamicDefault() {
103
+ console.log('\n=== 示例4: 动态默认值 ===\n');
104
+ const answers = await inquirer_1.default.prompt([
105
+ {
106
+ type: 'input',
107
+ name: 'projectName',
108
+ message: '项目名称:',
109
+ },
110
+ {
111
+ type: 'input',
112
+ name: 'packageName',
113
+ message: '包名称:',
114
+ default: (answers) => {
115
+ // 基于项目名称生成默认包名
116
+ return `@myorg/${answers.projectName}`;
117
+ },
118
+ },
119
+ {
120
+ type: 'input',
121
+ name: 'description',
122
+ message: '项目描述:',
123
+ default: (answers) => {
124
+ return `A awesome ${answers.projectName} project`;
125
+ },
126
+ }
127
+ ]);
128
+ console.log('项目信息:');
129
+ console.log(JSON.stringify(answers, null, 2));
130
+ }
131
+ // #endregion
132
+ // #region 示例5: 动态选择列表
133
+ async function dynamicChoices() {
134
+ console.log('\n=== 示例5: 动态选择列表 ===\n');
135
+ const answers = await inquirer_1.default.prompt([
136
+ {
137
+ type: 'list',
138
+ name: 'category',
139
+ message: '选择分类:',
140
+ choices: ['前端', '后端', '移动端'],
141
+ },
142
+ {
143
+ type: 'list',
144
+ name: 'framework',
145
+ message: '选择框架:',
146
+ choices: (answers) => {
147
+ // 根据分类返回不同的框架选项
148
+ const frameworkMap = {
149
+ '前端': ['React', 'Vue', 'Angular'],
150
+ '后端': ['Express', 'Koa', 'NestJS'],
151
+ '移动端': ['React Native', 'Flutter', 'Ionic'],
152
+ };
153
+ return frameworkMap[answers.category] || [];
154
+ },
155
+ }
156
+ ]);
157
+ console.log(`选择: ${answers.category} - ${answers.framework}`);
158
+ }
159
+ // #endregion
160
+ // #region 示例6: 循环询问
161
+ async function loopQuestions() {
162
+ console.log('\n=== 示例6: 循环询问 ===\n');
163
+ const dependencies = [];
164
+ let addMore = true;
165
+ while (addMore) {
166
+ const answers = await inquirer_1.default.prompt([
167
+ {
168
+ type: 'input',
169
+ name: 'package',
170
+ message: '输入要添加的依赖包名:',
171
+ validate: (input) => {
172
+ if (input.trim().length === 0) {
173
+ return '包名不能为空';
174
+ }
175
+ return true;
176
+ },
177
+ },
178
+ {
179
+ type: 'confirm',
180
+ name: 'continue',
181
+ message: '是否继续添加?',
182
+ default: false,
183
+ }
184
+ ]);
185
+ dependencies.push(answers.package);
186
+ addMore = answers.continue;
187
+ }
188
+ console.log('\n已添加的依赖:');
189
+ dependencies.forEach((dep, index) => {
190
+ console.log(` ${index + 1}. ${dep}`);
191
+ });
192
+ }
193
+ // #endregion
194
+ if (require.main === module) {
195
+ const exampleNumber = process.argv[2];
196
+ const examples = {
197
+ '1': inputValidation,
198
+ '2': inputFilter,
199
+ '3': conditionalQuestions,
200
+ '4': dynamicDefault,
201
+ '5': dynamicChoices,
202
+ '6': loopQuestions,
203
+ };
204
+ if (exampleNumber && examples[exampleNumber]) {
205
+ examples[exampleNumber]();
206
+ }
207
+ else {
208
+ console.log('请指定示例编号 (1-6)');
209
+ console.log('例如: ts-node src/demo/inquirer/03-高级特性.ts 1');
210
+ }
211
+ }
@@ -0,0 +1,343 @@
1
+ "use strict";
2
+ /**
3
+ * Inquirer.js 实战案例
4
+ * ===================
5
+ * 综合运用 Inquirer.js 的各种特性构建实用的 CLI 工具
6
+ * 包括项目初始化、配置生成、任务管理等场景
7
+ */
8
+ var __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const inquirer_1 = __importDefault(require("inquirer"));
13
+ // #region 示例1: 项目初始化向导
14
+ async function projectInitWizard() {
15
+ console.log('\n=== 项目初始化向导 ===\n');
16
+ const answers = await inquirer_1.default.prompt([
17
+ {
18
+ type: 'input',
19
+ name: 'projectName',
20
+ message: '项目名称:',
21
+ validate: (input) => {
22
+ if (/^[a-z0-9-]+$/.test(input))
23
+ return true;
24
+ return '项目名称只能包含小写字母、数字和连字符';
25
+ },
26
+ },
27
+ {
28
+ type: 'input',
29
+ name: 'description',
30
+ message: '项目描述:',
31
+ default: 'A new project',
32
+ },
33
+ {
34
+ type: 'input',
35
+ name: 'author',
36
+ message: '作者:',
37
+ },
38
+ {
39
+ type: 'list',
40
+ name: 'license',
41
+ message: '选择许可证:',
42
+ choices: ['MIT', 'Apache-2.0', 'GPL-3.0', 'ISC', 'BSD-3-Clause'],
43
+ default: 'MIT',
44
+ },
45
+ {
46
+ type: 'checkbox',
47
+ name: 'features',
48
+ message: '选择需要的功能:',
49
+ choices: [
50
+ { name: 'TypeScript', value: 'typescript', checked: true },
51
+ { name: 'ESLint', value: 'eslint', checked: true },
52
+ { name: 'Prettier', value: 'prettier' },
53
+ { name: 'Jest', value: 'jest' },
54
+ { name: 'Husky', value: 'husky' },
55
+ ],
56
+ },
57
+ ]);
58
+ console.log('\n生成的 package.json 配置:');
59
+ const packageJson = {
60
+ name: answers.projectName,
61
+ version: '1.0.0',
62
+ description: answers.description,
63
+ author: answers.author,
64
+ license: answers.license,
65
+ scripts: {},
66
+ devDependencies: {},
67
+ };
68
+ console.log(JSON.stringify(packageJson, null, 2));
69
+ console.log(`\n已选择功能: ${answers.features.join(', ')}`);
70
+ }
71
+ // #endregion
72
+ // #region 示例2: 数据库配置生成器
73
+ async function databaseConfigGenerator() {
74
+ console.log('\n=== 数据库配置生成器 ===\n');
75
+ const answers = await inquirer_1.default.prompt([
76
+ {
77
+ type: 'list',
78
+ name: 'type',
79
+ message: '选择数据库类型:',
80
+ choices: ['MySQL', 'PostgreSQL', 'MongoDB', 'Redis'],
81
+ },
82
+ {
83
+ type: 'input',
84
+ name: 'host',
85
+ message: '主机地址:',
86
+ default: 'localhost',
87
+ },
88
+ {
89
+ type: 'number',
90
+ name: 'port',
91
+ message: '端口号:',
92
+ default: (answers) => {
93
+ const defaultPorts = {
94
+ 'MySQL': 3306,
95
+ 'PostgreSQL': 5432,
96
+ 'MongoDB': 27017,
97
+ 'Redis': 6379,
98
+ };
99
+ return defaultPorts[answers.type];
100
+ },
101
+ },
102
+ {
103
+ type: 'input',
104
+ name: 'database',
105
+ message: '数据库名:',
106
+ when: (answers) => answers.type !== 'Redis',
107
+ },
108
+ {
109
+ type: 'input',
110
+ name: 'username',
111
+ message: '用户名:',
112
+ },
113
+ {
114
+ type: 'password',
115
+ name: 'password',
116
+ message: '密码:',
117
+ mask: '*',
118
+ },
119
+ {
120
+ type: 'confirm',
121
+ name: 'ssl',
122
+ message: '启用 SSL?',
123
+ default: false,
124
+ },
125
+ ]);
126
+ console.log('\n生成的数据库配置:');
127
+ console.log(JSON.stringify(answers, null, 2));
128
+ }
129
+ // #endregion
130
+ // #region 示例3: Git 提交助手
131
+ async function gitCommitHelper() {
132
+ console.log('\n=== Git 提交助手 ===\n');
133
+ const answers = await inquirer_1.default.prompt([
134
+ {
135
+ type: 'list',
136
+ name: 'type',
137
+ message: '提交类型:',
138
+ choices: [
139
+ { name: '✨ feat: 新功能', value: 'feat' },
140
+ { name: '🐛 fix: 修复 Bug', value: 'fix' },
141
+ { name: '📝 docs: 文档更新', value: 'docs' },
142
+ { name: '💄 style: 代码格式', value: 'style' },
143
+ { name: '♻️ refactor: 重构', value: 'refactor' },
144
+ { name: '⚡️ perf: 性能优化', value: 'perf' },
145
+ { name: '✅ test: 测试', value: 'test' },
146
+ { name: '🔧 chore: 构建/工具', value: 'chore' },
147
+ ],
148
+ },
149
+ {
150
+ type: 'input',
151
+ name: 'scope',
152
+ message: '影响范围 (可选):',
153
+ },
154
+ {
155
+ type: 'input',
156
+ name: 'subject',
157
+ message: '简短描述:',
158
+ validate: (input) => {
159
+ if (input.length > 0 && input.length <= 50)
160
+ return true;
161
+ return '描述长度应在 1-50 个字符之间';
162
+ },
163
+ },
164
+ {
165
+ type: 'input',
166
+ name: 'body',
167
+ message: '详细描述 (可选):',
168
+ },
169
+ {
170
+ type: 'confirm',
171
+ name: 'breaking',
172
+ message: '是否包含破坏性变更?',
173
+ default: false,
174
+ },
175
+ {
176
+ type: 'input',
177
+ name: 'breakingDesc',
178
+ message: '描述破坏性变更:',
179
+ when: (answers) => answers.breaking,
180
+ },
181
+ ]);
182
+ // 生成提交信息
183
+ let commitMsg = answers.type;
184
+ if (answers.scope) {
185
+ commitMsg += `(${answers.scope})`;
186
+ }
187
+ commitMsg += `: ${answers.subject}`;
188
+ if (answers.body) {
189
+ commitMsg += `\n\n${answers.body}`;
190
+ }
191
+ if (answers.breaking && answers.breakingDesc) {
192
+ commitMsg += `\n\nBREAKING CHANGE: ${answers.breakingDesc}`;
193
+ }
194
+ console.log('\n生成的提交信息:');
195
+ console.log('---');
196
+ console.log(commitMsg);
197
+ console.log('---');
198
+ }
199
+ // #endregion
200
+ // #region 示例4: 环境配置管理
201
+ async function envConfigManager() {
202
+ console.log('\n=== 环境配置管理 ===\n');
203
+ const answers = await inquirer_1.default.prompt([
204
+ {
205
+ type: 'list',
206
+ name: 'env',
207
+ message: '选择环境:',
208
+ choices: ['development', 'staging', 'production'],
209
+ },
210
+ {
211
+ type: 'input',
212
+ name: 'apiUrl',
213
+ message: 'API 地址:',
214
+ default: (answers) => {
215
+ const defaults = {
216
+ 'development': 'http://localhost:3000',
217
+ 'staging': 'https://staging-api.example.com',
218
+ 'production': 'https://api.example.com',
219
+ };
220
+ return defaults[answers.env];
221
+ },
222
+ },
223
+ {
224
+ type: 'confirm',
225
+ name: 'debug',
226
+ message: '启用调试模式?',
227
+ default: (answers) => answers.env === 'development',
228
+ },
229
+ {
230
+ type: 'list',
231
+ name: 'logLevel',
232
+ message: '日志级别:',
233
+ choices: ['error', 'warn', 'info', 'debug'],
234
+ default: (answers) => {
235
+ return answers.env === 'production' ? 'error' : 'debug';
236
+ },
237
+ },
238
+ ]);
239
+ console.log('\n生成的 .env 文件内容:');
240
+ console.log(`NODE_ENV=${answers.env}`);
241
+ console.log(`API_URL=${answers.apiUrl}`);
242
+ console.log(`DEBUG=${answers.debug}`);
243
+ console.log(`LOG_LEVEL=${answers.logLevel}`);
244
+ }
245
+ // #endregion
246
+ // #region 示例5: 任务管理器
247
+ async function taskManager() {
248
+ console.log('\n=== 任务管理器 ===\n');
249
+ const tasks = [];
250
+ while (true) {
251
+ const action = await inquirer_1.default.prompt([
252
+ {
253
+ type: 'list',
254
+ name: 'action',
255
+ message: '选择操作:',
256
+ choices: [
257
+ '➕ 添加任务',
258
+ '📋 查看任务',
259
+ '✅ 完成任务',
260
+ '🚪 退出',
261
+ ],
262
+ },
263
+ ]);
264
+ if (action.action === '🚪 退出') {
265
+ break;
266
+ }
267
+ if (action.action === '➕ 添加任务') {
268
+ const newTask = await inquirer_1.default.prompt([
269
+ {
270
+ type: 'input',
271
+ name: 'title',
272
+ message: '任务标题:',
273
+ validate: (input) => input.length > 0 || '标题不能为空',
274
+ },
275
+ {
276
+ type: 'list',
277
+ name: 'priority',
278
+ message: '优先级:',
279
+ choices: ['高', '中', '低'],
280
+ default: '中',
281
+ },
282
+ ]);
283
+ tasks.push({ ...newTask, done: false });
284
+ console.log('✅ 任务已添加\n');
285
+ }
286
+ if (action.action === '📋 查看任务') {
287
+ if (tasks.length === 0) {
288
+ console.log('暂无任务\n');
289
+ }
290
+ else {
291
+ console.log('\n当前任务列表:');
292
+ tasks.forEach((task, index) => {
293
+ const status = task.done ? '✅' : '⬜';
294
+ console.log(`${index + 1}. ${status} [${task.priority}] ${task.title}`);
295
+ });
296
+ console.log();
297
+ }
298
+ }
299
+ if (action.action === '✅ 完成任务') {
300
+ if (tasks.length === 0) {
301
+ console.log('暂无任务\n');
302
+ continue;
303
+ }
304
+ const undoneTasks = tasks.filter(t => !t.done);
305
+ if (undoneTasks.length === 0) {
306
+ console.log('所有任务已完成\n');
307
+ continue;
308
+ }
309
+ const complete = await inquirer_1.default.prompt([
310
+ {
311
+ type: 'list',
312
+ name: 'taskIndex',
313
+ message: '选择要完成的任务:',
314
+ choices: undoneTasks.map((task, index) => ({
315
+ name: `[${task.priority}] ${task.title}`,
316
+ value: tasks.indexOf(task),
317
+ })),
318
+ },
319
+ ]);
320
+ tasks[complete.taskIndex].done = true;
321
+ console.log('✅ 任务已完成\n');
322
+ }
323
+ }
324
+ console.log('再见!');
325
+ }
326
+ // #endregion
327
+ if (require.main === module) {
328
+ const exampleNumber = process.argv[2];
329
+ const examples = {
330
+ '1': projectInitWizard,
331
+ '2': databaseConfigGenerator,
332
+ '3': gitCommitHelper,
333
+ '4': envConfigManager,
334
+ '5': taskManager,
335
+ };
336
+ if (exampleNumber && examples[exampleNumber]) {
337
+ examples[exampleNumber]();
338
+ }
339
+ else {
340
+ console.log('请指定示例编号 (1-5)');
341
+ console.log('例如: ts-node src/demo/inquirer/04-实战案例.ts 1');
342
+ }
343
+ }