neo-cmp-cli 1.7.8 → 1.7.9
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
|
@@ -71,8 +71,11 @@ module.exports = function (projectPath, options = {}) {
|
|
|
71
71
|
console.log('\n📝 说明:组件开发工具(neo-cmp-cli)无法直接改变当前命令窗口工作目录,');
|
|
72
72
|
console.log(` 您需要手动执行上述命令才能进入刚创建的自定义组件项目(${projectName})。\n`);
|
|
73
73
|
|
|
74
|
-
// 自动打开 IDE
|
|
75
|
-
openProject('auto', projectName)
|
|
74
|
+
// 自动打开 IDE编辑器(异步执行,不需要等待)
|
|
75
|
+
openProject('auto', projectName).catch((error) => {
|
|
76
|
+
// 错误已在 openProject 内部处理,这里只是防止未处理的 Promise 警告
|
|
77
|
+
console.error(`打开编辑器时出错: ${error.message}`);
|
|
78
|
+
});
|
|
76
79
|
}
|
|
77
80
|
|
|
78
81
|
return success;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
|
-
const
|
|
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,79 @@ 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
|
|
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
|
-
|
|
40
|
+
editorConfigs = [
|
|
41
|
+
{ app: { name: 'cursor' } },
|
|
42
|
+
{ app: { name: 'Cursor' } }
|
|
43
|
+
];
|
|
25
44
|
} else if (isWindows || isLinux) {
|
|
26
|
-
|
|
45
|
+
editorConfigs = [{ app: { name: 'cursor' } }];
|
|
27
46
|
}
|
|
28
47
|
} else if (editorType === 'vscode' || editorType === 'code') {
|
|
29
48
|
editorName = 'Visual Studio Code';
|
|
30
49
|
if (isMac) {
|
|
31
|
-
|
|
50
|
+
editorConfigs = [
|
|
51
|
+
{ app: { name: 'code' } },
|
|
52
|
+
{ app: { name: 'Visual Studio Code' } }
|
|
53
|
+
];
|
|
32
54
|
} else if (isWindows || isLinux) {
|
|
33
|
-
|
|
55
|
+
editorConfigs = [{ app: { name: 'code' } }];
|
|
34
56
|
}
|
|
35
57
|
} else {
|
|
36
58
|
// 自动检测:优先尝试 Cursor,如果失败则尝试 VSCode
|
|
37
59
|
if (isMac) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
60
|
+
editorConfigs = [
|
|
61
|
+
{ app: { name: 'cursor' } },
|
|
62
|
+
{ app: { name: 'Cursor' } },
|
|
63
|
+
{ app: { name: 'code' } },
|
|
64
|
+
{ app: { name: 'Visual Studio Code' } }
|
|
43
65
|
];
|
|
44
66
|
} else if (isWindows || isLinux) {
|
|
45
|
-
|
|
67
|
+
editorConfigs = [
|
|
68
|
+
{ app: { name: 'cursor' } },
|
|
69
|
+
{ app: { name: 'code' } }
|
|
70
|
+
];
|
|
46
71
|
}
|
|
47
72
|
}
|
|
48
73
|
|
|
49
|
-
if (
|
|
74
|
+
if (editorConfigs.length === 0) {
|
|
50
75
|
errorLog(`不支持的操作系统: ${process.platform}`);
|
|
51
76
|
process.exit(1);
|
|
52
77
|
}
|
|
53
78
|
|
|
54
79
|
const spinner = ora(`${consoleTag}正在尝试使用 ${editorName} 打开项目: ${targetDir}`).start();
|
|
55
80
|
|
|
56
|
-
//
|
|
57
|
-
const
|
|
58
|
-
if (index >=
|
|
81
|
+
// 尝试打开编辑器
|
|
82
|
+
const tryOpenEditor = async (index) => {
|
|
83
|
+
if (index >= editorConfigs.length) {
|
|
59
84
|
errorLog(
|
|
60
85
|
`无法打开编辑器,已尝试所有可用方式。\n 请确保已安装 Cursor 或 Visual Studio Code 并将其添加到系统 PATH 中。`,
|
|
61
86
|
spinner
|
|
@@ -63,19 +88,16 @@ module.exports = function (editorType, targetPath) {
|
|
|
63
88
|
process.exit(1);
|
|
64
89
|
}
|
|
65
90
|
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
});
|
|
91
|
+
const config = editorConfigs[index];
|
|
92
|
+
try {
|
|
93
|
+
await open(targetDir, config);
|
|
94
|
+
spinner.stop();
|
|
95
|
+
// 成功打开,不需要继续尝试
|
|
96
|
+
} catch (error) {
|
|
97
|
+
// 如果当前配置失败,尝试下一个
|
|
98
|
+
await tryOpenEditor(index + 1);
|
|
99
|
+
}
|
|
77
100
|
};
|
|
78
101
|
|
|
79
|
-
|
|
80
|
-
spinner.stop();
|
|
102
|
+
await tryOpenEditor(0);
|
|
81
103
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const { execSync } = require('child_process');
|
|
2
2
|
|
|
3
3
|
// 所有需要废弃的版本(1.6.2 之前的所有版本)
|
|
4
|
-
const versionsToDeprecate = ["1.
|
|
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"];
|
|
5
5
|
|
|
6
6
|
const packageName = 'neo-cmp-cli';
|
|
7
7
|
const deprecateMessage = '此版本为开发中版本(存在 bug),请升级到最新版本。';
|