neo-cmp-cli 1.7.8 → 1.7.10

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,6 +1,6 @@
1
1
  {
2
2
  "name": "neo-cmp-cli",
3
- "version": "1.7.8",
3
+ "version": "1.7.10",
4
4
  "description": "前端脚手架:自定义组件开发工具,支持react 和 vue2.0技术栈。",
5
5
  "keywords": [
6
6
  "neo-cli",
@@ -62,17 +62,22 @@ module.exports = function (projectPath, options = {}) {
62
62
 
63
63
  // 输出 shell 命令让用户执行(这样可以真正改变 shell 的工作目录)
64
64
  if (outputShellCommand) {
65
- const command = `neo open -n ${projectName}`;
66
65
  // 输出提示信息
67
66
  console.log('\n' + '='.repeat(60));
68
- console.log('💡 提示:要切换到项目目录,请执行以下命令:');
69
- console.log(`\n ${command}\n`);
67
+ console.log('💡 提示:要切换到新建项目目录,请执行以下命令:');
68
+ console.log(`\n cd ${projectName} \n`);
69
+ console.log(`\n neo open -n ${projectName} \n`);
70
70
  console.log('='.repeat(60));
71
- console.log('\n📝 说明:组件开发工具(neo-cmp-cli)无法直接改变当前命令窗口工作目录,');
72
- console.log(` 您需要手动执行上述命令才能进入刚创建的自定义组件项目(${projectName})。\n`);
71
+ console.log('\n📝 说明1:组件开发工具(neo-cmp-cli)无法直接改变当前命令窗口工作目录,');
72
+ console.log(` 您需要手动执行上述命令才能进入刚创建的自定义组件项目(${projectName})。`);
73
+ console.log(`\n📝 说明2:组件开发工具(neo-cmp-cli)默认自动打开编辑器(neo open -n ${projectName})。\n`);
73
74
 
74
- // 自动打开 IDE编辑器
75
- openProject('auto', projectName);
75
+ // 自动打开 IDE编辑器(异步执行,不需要等待)
76
+ openProject('auto', projectPath).catch((error) => {
77
+ // 错误已在 openProject 内部处理,这里只是防止未处理的 Promise 警告
78
+ console.error(`自动打开编辑器出错(neo open -n ${projectName}): ${error.message}`);
79
+ console.error(`请手动执行命令 neo open -n ${projectName} 打开编辑器。`);
80
+ });
76
81
  }
77
82
 
78
83
  return success;
@@ -1,5 +1,6 @@
1
1
  const path = require('path');
2
- const { exec } = require('child_process');
2
+ const fs = require('fs');
3
+ const open = require('open');
3
4
  const ora = require('ora');
4
5
  const { consoleTag } = require('../neoParams');
5
6
  const { errorLog } = require('../common');
@@ -7,55 +8,70 @@ const { errorLog } = require('../common');
7
8
  /**
8
9
  * 打开自定义组件项目
9
10
  */
10
- module.exports = function (editorType, targetPath) {
11
+ module.exports = async function (editorType, targetPath) {
11
12
  const targetDir = targetPath ? path.resolve(targetPath) : process.cwd();
13
+
14
+ // 检查目录是否存在
15
+ if (!fs.existsSync(targetDir)) {
16
+ errorLog(`目录不存在: ${targetDir}`);
17
+ process.exit(1);
18
+ }
19
+
20
+ // 检查是否为目录
21
+ const stats = fs.statSync(targetDir);
22
+ if (!stats.isDirectory()) {
23
+ errorLog(`路径不是目录: ${targetDir}`);
24
+ process.exit(1);
25
+ }
26
+
12
27
  const isMac = process.platform === 'darwin';
13
28
  const isWindows = process.platform === 'win32';
14
29
  const isLinux = process.platform === 'linux';
15
30
 
16
- // 构建命令列表(按优先级排序)
17
- let commands = [];
31
+ // 构建编辑器配置列表(按优先级排序)
32
+ let editorConfigs = [];
18
33
  let editorName = '编辑器';
19
34
 
20
- // 根据编辑器类型和平台构建命令列表
35
+ // 根据编辑器类型和平台构建配置列表
21
36
  if (editorType === 'cursor') {
22
37
  editorName = 'Cursor';
38
+ // macOS 可以使用应用名称或命令名称
23
39
  if (isMac) {
24
- commands = [`cursor "${targetDir}"`, `open -a "Cursor" "${targetDir}"`];
40
+ editorConfigs = [{ app: { name: 'cursor' } }, { app: { name: 'Cursor' } }];
25
41
  } else if (isWindows || isLinux) {
26
- commands = [`cursor "${targetDir}"`];
42
+ editorConfigs = [{ app: { name: 'cursor' } }];
27
43
  }
28
44
  } else if (editorType === 'vscode' || editorType === 'code') {
29
45
  editorName = 'Visual Studio Code';
30
46
  if (isMac) {
31
- commands = [`code "${targetDir}"`, `open -a "Visual Studio Code" "${targetDir}"`];
47
+ editorConfigs = [{ app: { name: 'code' } }, { app: { name: 'Visual Studio Code' } }];
32
48
  } else if (isWindows || isLinux) {
33
- commands = [`code "${targetDir}"`];
49
+ editorConfigs = [{ app: { name: 'code' } }];
34
50
  }
35
51
  } else {
36
52
  // 自动检测:优先尝试 Cursor,如果失败则尝试 VSCode
37
53
  if (isMac) {
38
- commands = [
39
- `cursor "${targetDir}"`,
40
- `code "${targetDir}"`,
41
- `open -a "Cursor" "${targetDir}"`,
42
- `open -a "Visual Studio Code" "${targetDir}"`
54
+ editorConfigs = [
55
+ { app: { name: 'cursor' } },
56
+ { app: { name: 'Cursor' } },
57
+ { app: { name: 'code' } },
58
+ { app: { name: 'Visual Studio Code' } }
43
59
  ];
44
60
  } else if (isWindows || isLinux) {
45
- commands = [`cursor "${targetDir}"`, `code "${targetDir}"`];
61
+ editorConfigs = [{ app: { name: 'cursor' } }, { app: { name: 'code' } }];
46
62
  }
47
63
  }
48
64
 
49
- if (commands.length === 0) {
65
+ if (editorConfigs.length === 0) {
50
66
  errorLog(`不支持的操作系统: ${process.platform}`);
51
67
  process.exit(1);
52
68
  }
53
69
 
54
70
  const spinner = ora(`${consoleTag}正在尝试使用 ${editorName} 打开项目: ${targetDir}`).start();
55
71
 
56
- // 尝试执行命令列表中的第一个可用命令
57
- const tryCommand = (index) => {
58
- if (index >= commands.length) {
72
+ // 尝试打开编辑器
73
+ const tryOpenEditor = async (index) => {
74
+ if (index >= editorConfigs.length) {
59
75
  errorLog(
60
76
  `无法打开编辑器,已尝试所有可用方式。\n 请确保已安装 Cursor 或 Visual Studio Code 并将其添加到系统 PATH 中。`,
61
77
  spinner
@@ -63,19 +79,16 @@ module.exports = function (editorType, targetPath) {
63
79
  process.exit(1);
64
80
  }
65
81
 
66
- const command = commands[index];
67
- // 使用 exec 配合 shell 执行命令,这样可以更好地处理路径中的空格和特殊字符
68
- exec(command, { shell: true }, (error, stdout, stderr) => {
69
- if (error) {
70
- // 如果当前命令失败,尝试下一个
71
- tryCommand(index + 1);
72
- } else {
73
- // 命令执行成功,不需要继续尝试
74
- // 编辑器命令通常会立即返回,即使编辑器窗口已经打开
75
- }
76
- });
82
+ const config = editorConfigs[index];
83
+ try {
84
+ await open(targetDir, config);
85
+ spinner.stop();
86
+ // 成功打开,不需要继续尝试
87
+ } catch (error) {
88
+ // 如果当前配置失败,尝试下一个
89
+ await tryOpenEditor(index + 1);
90
+ }
77
91
  };
78
92
 
79
- tryCommand(0);
80
- spinner.stop();
93
+ await tryOpenEditor(0);
81
94
  };
@@ -1,7 +1,7 @@
1
1
  const { execSync } = require('child_process');
2
2
 
3
3
  // 所有需要废弃的版本(1.6.2 之前的所有版本)
4
- const versionsToDeprecate = ["1.6.5", "1.6.6", "1.6.7", "1.6.8", "1.7.0", "1.7.1", "1.7.2", "1.7.3"];
4
+ const versionsToDeprecate = ["1.7.5", "1.7.5-beta.1", "1.7.5-beta.2", "1.7.6", "1.7.7", "1.7.8", "1.7.9"];
5
5
 
6
6
  const packageName = 'neo-cmp-cli';
7
7
  const deprecateMessage = '此版本为开发中版本(存在 bug),请升级到最新版本。';