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
|
@@ -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
|
|
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📝
|
|
72
|
-
console.log(` 您需要手动执行上述命令才能进入刚创建的自定义组件项目(${projectName}
|
|
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',
|
|
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
|
|
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
|
|
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 = [{ app: { name: 'cursor' } }, { app: { name: 'Cursor' } }];
|
|
25
41
|
} else if (isWindows || isLinux) {
|
|
26
|
-
|
|
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
|
-
|
|
47
|
+
editorConfigs = [{ app: { name: 'code' } }, { app: { name: 'Visual Studio Code' } }];
|
|
32
48
|
} else if (isWindows || isLinux) {
|
|
33
|
-
|
|
49
|
+
editorConfigs = [{ app: { name: 'code' } }];
|
|
34
50
|
}
|
|
35
51
|
} else {
|
|
36
52
|
// 自动检测:优先尝试 Cursor,如果失败则尝试 VSCode
|
|
37
53
|
if (isMac) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
61
|
+
editorConfigs = [{ app: { name: 'cursor' } }, { app: { name: 'code' } }];
|
|
46
62
|
}
|
|
47
63
|
}
|
|
48
64
|
|
|
49
|
-
if (
|
|
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
|
|
58
|
-
if (index >=
|
|
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
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
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.
|
|
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),请升级到最新版本。';
|