@agile-team/robot-cli 1.1.12 → 2.2.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.
package/package.json CHANGED
@@ -1,51 +1,47 @@
1
1
  {
2
2
  "name": "@agile-team/robot-cli",
3
- "version": "1.1.12",
3
+ "version": "2.2.0",
4
4
  "description": "🤖 现代化项目脚手架工具,支持多技术栈快速创建项目 - 优先 bun,兼容 npm/pnpm/yarn",
5
5
  "type": "module",
6
6
  "bin": {
7
- "robot": "bin/index.js"
7
+ "robot": "bin/robot.js"
8
8
  },
9
9
  "scripts": {
10
- "robot": "node bin/index.js",
11
- "robot:create": "node bin/index.js create",
12
- "robot:list": "node bin/index.js list",
13
- "robot:search": "node bin/index.js search",
14
- "test": "node test/local-test.js",
15
- "test:setup": "node test/local-test.js --setup",
16
- "test:clean": "node test/local-test.js --clean",
17
- "dev": "node bin/index.js",
18
- "dev:create": "node bin/index.js create",
19
- "dev:list": "node bin/index.js list",
20
- "dev:search": "node bin/index.js search",
21
- "install:deps": "bun install",
22
- "install:fallback": "npm install",
23
- "clean:modules": "rm -rf node_modules",
24
- "reinstall": "npm run clean:modules && npm run install:deps",
25
- "prepublishOnly": "npm run test",
26
- "version:patch": "npm version patch",
27
- "version:minor": "npm version minor",
28
- "version:major": "npm version major",
29
- "publish:npm": "npm publish --access public",
30
- "release:patch": "npm run version:patch && npm run publish:npm",
31
- "release:minor": "npm run version:minor && npm run publish:npm",
32
- "release:major": "npm run version:major && npm run publish:npm",
33
- "clean:all": "npm run test:clean && npm run reinstall"
10
+ "build": "tsup",
11
+ "dev": "tsup --watch",
12
+ "test": "vitest run",
13
+ "test:watch": "vitest",
14
+ "lint": "oxlint src/ tests/",
15
+ "lint:fix": "oxlint --fix src/ tests/",
16
+ "typecheck": "tsc --noEmit",
17
+ "prepublishOnly": "bun run build && bun run test",
18
+ "release:patch": "bun version patch && bunx npm publish --access public",
19
+ "release:minor": "bun version minor && bunx npm publish --access public",
20
+ "release:major": "bun version major && bunx npm publish --access public"
34
21
  },
35
22
  "dependencies": {
36
- "boxen": "^7.1.0",
37
23
  "chalk": "^5.3.0",
38
24
  "commander": "^11.0.0",
39
25
  "extract-zip": "^2.0.1",
40
26
  "fs-extra": "^11.1.0",
27
+ "gradient-string": "^3.0.0",
41
28
  "inquirer": "^9.2.0",
42
- "node-fetch": "^3.3.0",
43
29
  "ora": "^7.0.0"
44
30
  },
31
+ "devDependencies": {
32
+ "@types/fs-extra": "^11.0.4",
33
+ "@types/inquirer": "^9.0.9",
34
+ "@types/node": "^22.0.0",
35
+ "oxlint": "^0.16.0",
36
+ "tsup": "^8.4.0",
37
+ "typescript": "^5.7.0",
38
+ "vitest": "^3.0.0"
39
+ },
45
40
  "files": [
46
41
  "bin",
47
- "lib",
48
- "README.md"
42
+ "dist",
43
+ "README.md",
44
+ "CHANGELOG.md"
49
45
  ],
50
46
  "keywords": [
51
47
  "cli",
package/bin/index.js DELETED
@@ -1,405 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import { fileURLToPath, pathToFileURL } from 'url';
4
- import { dirname, join, resolve } from 'path';
5
- import { existsSync } from 'fs';
6
- import { readFileSync } from 'fs';
7
-
8
- // 获取当前文件的目录
9
- const __filename = fileURLToPath(import.meta.url);
10
- const __dirname = dirname(__filename);
11
-
12
- /**
13
- * 获取包版本号
14
- */
15
- function getPackageVersion() {
16
- try {
17
- const possiblePaths = [
18
- join(__dirname, '..', 'package.json'),
19
- join(__dirname, 'package.json'),
20
- join(__dirname, '..', '..', 'package.json')
21
- ];
22
-
23
- for (const packagePath of possiblePaths) {
24
- if (existsSync(packagePath)) {
25
- const packageJson = JSON.parse(readFileSync(packagePath, 'utf8'));
26
- return packageJson.version || '1.0.0';
27
- }
28
- }
29
-
30
- return '1.0.0';
31
- } catch (error) {
32
- return '1.0.0';
33
- }
34
- }
35
-
36
- const PACKAGE_VERSION = getPackageVersion();
37
-
38
- /**
39
- * 智能路径解析
40
- */
41
- function resolveLibPath() {
42
- const possiblePaths = [
43
- join(__dirname, '..', 'lib'),
44
- join(__dirname, 'lib'),
45
- join(__dirname, '..', '..', 'lib'),
46
- join(__dirname, '..', 'node_modules', '@agile-team', 'robot-cli', 'lib'),
47
- resolve(__dirname, '..', 'lib'),
48
- resolve(__dirname, '../../lib'),
49
- join(__dirname, '..', '..', '@agile-team', 'robot-cli', 'lib'),
50
- ];
51
-
52
- for (const libPath of possiblePaths) {
53
- if (existsSync(libPath)) {
54
- return libPath;
55
- }
56
- }
57
-
58
- throw new Error(`
59
- 无法找到 lib 目录,已尝试以下路径:
60
- ${possiblePaths.map(p => ` - ${p}`).join('\n')}
61
-
62
- 当前执行路径: ${__dirname}
63
- 工作目录: ${process.cwd()}
64
-
65
- 可能的解决方案:
66
- 1. 重新安装: npm uninstall -g @agile-team/robot-cli && npm install -g @agile-team/robot-cli
67
- 2. 使用 npx: npx @agile-team/robot-cli
68
- 3. 检查包完整性: npm list -g @agile-team/robot-cli
69
- `);
70
- }
71
-
72
- // 动态导入所需模块
73
- async function loadModules() {
74
- try {
75
- const libPath = resolveLibPath();
76
-
77
- const createUrl = pathToFileURL(join(libPath, 'create.js')).href;
78
- const templatesUrl = pathToFileURL(join(libPath, 'templates.js')).href;
79
- const utilsUrl = pathToFileURL(join(libPath, 'utils.js')).href;
80
-
81
- const [
82
- { Command },
83
- chalk,
84
- boxen,
85
- inquirer,
86
- { createProject },
87
- { getAllTemplates, searchTemplates, getRecommendedTemplates },
88
- { checkNetworkConnection }
89
- ] = await Promise.all([
90
- import('commander'),
91
- import('chalk'),
92
- import('boxen'),
93
- import('inquirer'),
94
- import(createUrl),
95
- import(templatesUrl),
96
- import(utilsUrl)
97
- ]);
98
-
99
- return {
100
- Command,
101
- chalk: chalk.default,
102
- boxen: boxen.default,
103
- inquirer: inquirer.default,
104
- createProject,
105
- getAllTemplates,
106
- searchTemplates,
107
- getRecommendedTemplates,
108
- checkNetworkConnection
109
- };
110
- } catch (error) {
111
- console.error(`
112
- ❌ 模块加载失败: ${error.message}
113
-
114
- 🔧 诊断信息:
115
- 当前文件: ${__filename}
116
- 执行目录: ${__dirname}
117
- 工作目录: ${process.cwd()}
118
- Node版本: ${process.version}
119
-
120
- 💡 解决方案:
121
- 1. 完全重装: npm uninstall -g @agile-team/robot-cli && npm install -g @agile-team/robot-cli
122
- 2. 使用npx: npx @agile-team/robot-cli
123
- 3. 联系支持: https://github.com/ChenyCHENYU/robot-cli/issues
124
- `);
125
- process.exit(1);
126
- }
127
- }
128
-
129
- // 主程序
130
- async function main() {
131
- try {
132
- const modules = await loadModules();
133
- const {
134
- Command,
135
- chalk,
136
- boxen,
137
- inquirer,
138
- createProject,
139
- getAllTemplates,
140
- searchTemplates,
141
- getRecommendedTemplates,
142
- checkNetworkConnection
143
- } = modules;
144
-
145
- const program = new Command();
146
-
147
- // 现代化欢迎信息
148
- function showWelcome() {
149
- console.clear();
150
-
151
- const logoLines = [
152
- ' ██████╗ ██████╗ ██████╗ ██████╗ ████████╗',
153
- ' ██╔══██╗██╔═══██╗██╔══██╗██╔═══██╗╚══██╔══╝',
154
- ' ██████╔╝██║ ██║██████╔╝██║ ██║ ██║ ',
155
- ' ██╔══██╗██║ ██║██╔══██╗██║ ██║ ██║ ',
156
- ' ██║ ██║╚██████╔╝██████╔╝╚██████╔╝ ██║ ',
157
- ' ╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚═╝ '
158
- ];
159
-
160
- const logo = logoLines.map(line => chalk.cyan(line)).join('\n');
161
-
162
- const titleBox = boxen(
163
- logo + '\n\n' +
164
- ` 🤖 Robot 项目脚手架工具 v${PACKAGE_VERSION}\n` +
165
- ' 优先 bun,兼容 npm/pnpm/yarn',
166
- {
167
- padding: { top: 1, bottom: 1, left: 2, right: 2 },
168
- borderStyle: 'round',
169
- borderColor: 'cyan',
170
- backgroundColor: 'blackBright'
171
- }
172
- );
173
-
174
- console.log();
175
- console.log(titleBox);
176
- console.log();
177
- }
178
-
179
- // 显示主菜单
180
- async function showMainMenu() {
181
- const title = chalk.white.bold('🚀 快速开始');
182
-
183
- console.log(' ' + title);
184
- console.log();
185
-
186
- const allTemplates = getAllTemplates();
187
- const templateCount = Object.keys(allTemplates).length;
188
-
189
- console.log(chalk.dim(` 📦 可用模板: ${templateCount} 个`));
190
- console.log(chalk.dim(` 🎯 智能包管理器检测: 优先 bun`));
191
- console.log(chalk.dim(` 🌐 总是下载最新版本`));
192
- console.log();
193
-
194
- const commands = [
195
- {
196
- cmd: 'robot create',
197
- desc: '交互式创建项目',
198
- color: 'cyan'
199
- },
200
- {
201
- cmd: 'robot create <name>',
202
- desc: '快速创建项目',
203
- color: 'green'
204
- },
205
- {
206
- cmd: 'robot list',
207
- desc: '查看所有可用模板',
208
- color: 'blue'
209
- },
210
- {
211
- cmd: 'robot search <keyword>',
212
- desc: '搜索模板',
213
- color: 'magenta'
214
- }
215
- ];
216
-
217
- commands.forEach(({ cmd, desc, color }) => {
218
- console.log(' ' + chalk[color](cmd.padEnd(24)) + chalk.dim(desc));
219
- });
220
-
221
- console.log();
222
- console.log(chalk.dim(' 示例命令:'));
223
- console.log(chalk.dim(' robot create my-vue-admin'));
224
- console.log(chalk.dim(' robot create my-app --template robot-admin'));
225
- console.log(chalk.dim(' robot search vue'));
226
- console.log();
227
- console.log(chalk.dim(' 创建后的快速开始 (优先 bun):'));
228
- console.log(chalk.dim(' cd my-vue-admin'));
229
- console.log(chalk.dim(' bun install # 或 npm install'));
230
- console.log(chalk.dim(' bun run dev # 或 npm run dev'));
231
- console.log();
232
- }
233
-
234
- program
235
- .name('robot')
236
- .description('🤖 Robot 项目脚手架工具 - @agile-team/robot-cli')
237
- .version(PACKAGE_VERSION)
238
- .hook('preAction', () => {
239
- showWelcome();
240
- });
241
-
242
- // 创建项目命令
243
- program
244
- .command('create [project-name]')
245
- .description('创建新项目')
246
- .option('-t, --template <template>', '指定模板类型')
247
- .option('--skip-install', '跳过依赖安装')
248
- .action(async (projectName, options) => {
249
- try {
250
- // 检查网络连接
251
- console.log(chalk.blue('🌐 检查网络连接...'));
252
- const hasNetwork = await checkNetworkConnection();
253
- if (!hasNetwork) {
254
- console.log(chalk.red('❌ 网络连接失败,无法下载模板'));
255
- console.log(chalk.yellow('💡 请检查网络连接后重试'));
256
- process.exit(1);
257
- }
258
-
259
- await createProject(projectName, options);
260
- } catch (error) {
261
- console.log();
262
- console.log(chalk.red('✗'), chalk.red.bold('创建失败'));
263
-
264
- if (error.message.includes('网络')) {
265
- console.log(' ' + chalk.dim('网络相关问题,请检查网络连接'));
266
- } else if (error.message.includes('权限')) {
267
- console.log(' ' + chalk.dim('权限问题,请检查文件夹权限'));
268
- } else {
269
- console.log(' ' + chalk.dim(error.message));
270
- }
271
-
272
- console.log();
273
- console.log(chalk.blue('💡 获取帮助:'));
274
- console.log(chalk.dim(' robot --help'));
275
- console.log(chalk.dim(' https://github.com/ChenyCHENYU/robot-cli/issues'));
276
- console.log();
277
- process.exit(1);
278
- }
279
- });
280
-
281
- // 列出所有模板
282
- program
283
- .command('list')
284
- .alias('ls')
285
- .description('列出所有可用模板')
286
- .option('-r, --recommended', '只显示推荐模板')
287
- .option('-c, --category <category>', '按分类筛选')
288
- .action(async (options) => {
289
- try {
290
- let templates;
291
- let title;
292
-
293
- if (options.recommended) {
294
- templates = getRecommendedTemplates();
295
- title = '🎯 推荐模板';
296
- } else {
297
- templates = getAllTemplates();
298
- title = '📋 所有可用模板';
299
- }
300
-
301
- console.log();
302
- console.log(chalk.blue(title));
303
- console.log(chalk.dim(`共 ${Object.keys(templates).length} 个模板\n`));
304
-
305
- // 按分类显示
306
- const categories = {};
307
- Object.entries(templates).forEach(([key, template]) => {
308
- const category = key.split('-')[0];
309
- if (!categories[category]) {
310
- categories[category] = [];
311
- }
312
- categories[category].push({ key, ...template });
313
- });
314
-
315
- Object.entries(categories).forEach(([category, templates]) => {
316
- console.log(chalk.cyan(`${category.toUpperCase()} 相关:`));
317
- templates.forEach(template => {
318
- console.log(` ${chalk.green('●')} ${chalk.bold(template.name)}`);
319
- console.log(` ${chalk.dim(template.description)}`);
320
- console.log(` ${chalk.dim('功能: ' + template.features.join(', '))}`);
321
- console.log(` ${chalk.dim('使用: robot create my-app --template ' + template.key)}`);
322
- console.log(` ${chalk.dim('快速开始: cd my-app && bun install && bun run dev')}`);
323
- console.log();
324
- });
325
- });
326
-
327
- } catch (error) {
328
- console.log(chalk.red('❌ 获取模板列表失败:'), error.message);
329
- }
330
- });
331
-
332
- // 搜索模板
333
- program
334
- .command('search <keyword>')
335
- .description('搜索模板')
336
- .action(async (keyword) => {
337
- try {
338
- const results = searchTemplates(keyword);
339
-
340
- console.log();
341
- if (Object.keys(results).length === 0) {
342
- console.log(chalk.yellow('🔍 没有找到匹配的模板'));
343
- console.log();
344
- console.log(chalk.blue('💡 建议:'));
345
- console.log(chalk.dim(' • 尝试其他关键词'));
346
- console.log(chalk.dim(' • 使用 robot list 查看所有模板'));
347
- console.log(chalk.dim(' • 使用 robot list --recommended 查看推荐模板'));
348
- } else {
349
- console.log(chalk.green(`🔍 找到 ${Object.keys(results).length} 个匹配的模板:`));
350
- console.log();
351
-
352
- Object.entries(results).forEach(([key, template]) => {
353
- console.log(`${chalk.green('●')} ${chalk.bold(template.name)}`);
354
- console.log(` ${chalk.dim(template.description)}`);
355
- console.log(` ${chalk.dim('功能: ' + template.features.join(', '))}`);
356
- console.log(` ${chalk.cyan('robot create my-app --template ' + key)}`);
357
- console.log(` ${chalk.dim('然后: cd my-app && bun install && bun run dev')}`);
358
- console.log();
359
- });
360
- }
361
- } catch (error) {
362
- console.log(chalk.red('❌ 搜索失败:'), error.message);
363
- }
364
- });
365
-
366
- // 如果没有参数,显示主菜单
367
- if (process.argv.length === 2) {
368
- showWelcome();
369
- await showMainMenu();
370
- process.exit(0);
371
- }
372
-
373
- // 全局错误处理
374
- process.on('uncaughtException', (error) => {
375
- console.log();
376
- console.log(chalk.red('💥 程序发生未预期的错误:'));
377
- console.log(chalk.dim(error.message));
378
- console.log();
379
- console.log(chalk.blue('💡 建议:'));
380
- console.log(chalk.dim(' • 重启终端重试'));
381
- console.log(chalk.dim(' • 检查网络连接'));
382
- console.log(chalk.dim(' • 重新安装: npm install -g @agile-team/robot-cli'));
383
- console.log(chalk.dim(' • 联系技术支持: https://github.com/ChenyCHENYU/robot-cli/issues'));
384
- console.log();
385
- process.exit(1);
386
- });
387
-
388
- process.on('unhandledRejection', (error) => {
389
- console.log();
390
- console.log(chalk.red('💥 程序发生未处理的异步错误:'));
391
- console.log(chalk.dim(error.message));
392
- console.log();
393
- process.exit(1);
394
- });
395
-
396
- program.parse();
397
-
398
- } catch (error) {
399
- console.error('启动失败:', error.message);
400
- process.exit(1);
401
- }
402
- }
403
-
404
- // 启动程序
405
- main();