zen-gitsync 2.7.4 → 2.7.8
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 +1 -1
- package/src/ui/public/assets/index-CZcypxPJ.js +77 -0
- package/src/ui/public/assets/index-Cpt2Z6hH.css +1 -0
- package/src/ui/public/assets/{vendor-D5igP2uM.js → vendor-ChHq8Z33.js} +17 -17
- package/src/ui/public/index.html +3 -3
- package/src/ui/server/index.js +150 -4
- package/src/ui/public/assets/index-BP6dXCQE.css +0 -1
- package/src/ui/public/assets/index-CS-XVEPv.js +0 -77
package/src/ui/public/index.html
CHANGED
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
|
7
7
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
8
8
|
<title>Zen GitSync</title>
|
|
9
|
-
<script type="module" crossorigin src="/assets/index-
|
|
10
|
-
<link rel="modulepreload" crossorigin href="/assets/vendor-
|
|
9
|
+
<script type="module" crossorigin src="/assets/index-CZcypxPJ.js"></script>
|
|
10
|
+
<link rel="modulepreload" crossorigin href="/assets/vendor-ChHq8Z33.js">
|
|
11
11
|
<link rel="stylesheet" crossorigin href="/assets/vendor-BWT9SBHo.css">
|
|
12
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
12
|
+
<link rel="stylesheet" crossorigin href="/assets/index-Cpt2Z6hH.css">
|
|
13
13
|
</head>
|
|
14
14
|
<body>
|
|
15
15
|
<div id="app"></div>
|
package/src/ui/server/index.js
CHANGED
|
@@ -347,12 +347,15 @@ async function startUIServer(noOpen = false, savePort = false) {
|
|
|
347
347
|
// 在新终端中执行自定义命令
|
|
348
348
|
app.post('/api/exec-in-terminal', async (req, res) => {
|
|
349
349
|
try {
|
|
350
|
-
const { command } = req.body || {};
|
|
350
|
+
const { command, workingDirectory } = req.body || {};
|
|
351
351
|
if (!command || typeof command !== 'string' || !command.trim()) {
|
|
352
352
|
return res.status(400).json({ success: false, error: 'command 不能为空' });
|
|
353
353
|
}
|
|
354
354
|
|
|
355
|
+
// 使用传入的工作目录,如果没有则使用当前项目路径
|
|
356
|
+
const targetDir = workingDirectory || currentProjectPath;
|
|
355
357
|
console.log(`在终端中执行命令: ${command}`);
|
|
358
|
+
console.log(`工作目录: ${targetDir}`);
|
|
356
359
|
|
|
357
360
|
// 根据操作系统选择合适的终端命令
|
|
358
361
|
let terminalCommand;
|
|
@@ -360,14 +363,14 @@ async function startUIServer(noOpen = false, savePort = false) {
|
|
|
360
363
|
if (process.platform === 'win32') {
|
|
361
364
|
// Windows: 使用 start 命令打开新的 cmd 窗口
|
|
362
365
|
// /K 参数表示执行命令后保持窗口打开
|
|
363
|
-
terminalCommand = `start cmd /K "cd /d ${
|
|
366
|
+
terminalCommand = `start cmd /K "cd /d ${targetDir} && ${command}"`;
|
|
364
367
|
} else if (process.platform === 'darwin') {
|
|
365
368
|
// macOS: 使用 osascript 打开 Terminal.app
|
|
366
|
-
const script = `tell application "Terminal" to do script "cd ${
|
|
369
|
+
const script = `tell application "Terminal" to do script "cd ${targetDir} && ${command}"`;
|
|
367
370
|
terminalCommand = `osascript -e '${script}'`;
|
|
368
371
|
} else {
|
|
369
372
|
// Linux: 尝试常见的终端模拟器
|
|
370
|
-
terminalCommand = `gnome-terminal -- bash -c "cd ${
|
|
373
|
+
terminalCommand = `gnome-terminal -- bash -c "cd ${targetDir} && ${command}; exec bash" || xterm -e "cd ${targetDir} && ${command}; bash"`;
|
|
371
374
|
}
|
|
372
375
|
|
|
373
376
|
// 执行命令打开新终端
|
|
@@ -4103,6 +4106,149 @@ async function startUIServer(noOpen = false, savePort = false) {
|
|
|
4103
4106
|
}
|
|
4104
4107
|
});
|
|
4105
4108
|
|
|
4109
|
+
// 扫描项目目录下的所有package.json文件(用于版本管理)
|
|
4110
|
+
app.get('/api/scan-package-files', async (req, res) => {
|
|
4111
|
+
try {
|
|
4112
|
+
const projectRoot = process.cwd();
|
|
4113
|
+
const packageFiles = [];
|
|
4114
|
+
const startTime = Date.now();
|
|
4115
|
+
|
|
4116
|
+
// 需要忽略的目录列表
|
|
4117
|
+
const IGNORED_DIRS = new Set([
|
|
4118
|
+
'node_modules',
|
|
4119
|
+
'.git',
|
|
4120
|
+
'.svn',
|
|
4121
|
+
'.hg',
|
|
4122
|
+
'dist',
|
|
4123
|
+
'build',
|
|
4124
|
+
'coverage',
|
|
4125
|
+
'out',
|
|
4126
|
+
'target',
|
|
4127
|
+
'vendor',
|
|
4128
|
+
'__pycache__',
|
|
4129
|
+
'.next',
|
|
4130
|
+
'.nuxt',
|
|
4131
|
+
'.vscode',
|
|
4132
|
+
'.idea',
|
|
4133
|
+
'tmp',
|
|
4134
|
+
'temp',
|
|
4135
|
+
'cache',
|
|
4136
|
+
'.cache'
|
|
4137
|
+
]);
|
|
4138
|
+
|
|
4139
|
+
let scannedCount = 0;
|
|
4140
|
+
let fileReadCount = 0;
|
|
4141
|
+
|
|
4142
|
+
// 检查指定目录下是否有package.json
|
|
4143
|
+
async function checkPackageJson(dir) {
|
|
4144
|
+
try {
|
|
4145
|
+
const packagePath = path.join(dir, 'package.json');
|
|
4146
|
+
|
|
4147
|
+
// 先检查文件是否存在
|
|
4148
|
+
try {
|
|
4149
|
+
await fs.access(packagePath);
|
|
4150
|
+
} catch {
|
|
4151
|
+
return false;
|
|
4152
|
+
}
|
|
4153
|
+
|
|
4154
|
+
// 检查文件大小
|
|
4155
|
+
const stats = await fs.stat(packagePath);
|
|
4156
|
+
const fileSizeMB = stats.size / (1024 * 1024);
|
|
4157
|
+
if (fileSizeMB > 1) {
|
|
4158
|
+
return false;
|
|
4159
|
+
}
|
|
4160
|
+
|
|
4161
|
+
fileReadCount++;
|
|
4162
|
+
const content = await fs.readFile(packagePath, 'utf8');
|
|
4163
|
+
const packageData = JSON.parse(content);
|
|
4164
|
+
|
|
4165
|
+
// 添加所有有效的package.json文件(不仅仅是有scripts的)
|
|
4166
|
+
if (packageData.name || packageData.version) {
|
|
4167
|
+
const relativePath = path.relative(projectRoot, dir);
|
|
4168
|
+
packageFiles.push({
|
|
4169
|
+
path: dir,
|
|
4170
|
+
relativePath: relativePath || '.',
|
|
4171
|
+
name: packageData.name || path.basename(dir),
|
|
4172
|
+
version: packageData.version || '0.0.0',
|
|
4173
|
+
displayName: packageData.name ? `${packageData.name} (${packageData.version || '0.0.0'})` : `${path.basename(dir)} (${packageData.version || '0.0.0'})`,
|
|
4174
|
+
fullPath: packagePath
|
|
4175
|
+
});
|
|
4176
|
+
return true;
|
|
4177
|
+
}
|
|
4178
|
+
} catch (error) {
|
|
4179
|
+
// 文件不存在或解析失败,忽略
|
|
4180
|
+
}
|
|
4181
|
+
return false;
|
|
4182
|
+
}
|
|
4183
|
+
|
|
4184
|
+
// 递归扫描目录,最大深度4层
|
|
4185
|
+
const MAX_DEPTH = 4;
|
|
4186
|
+
const MAX_DIRS_PER_LEVEL = 50;
|
|
4187
|
+
|
|
4188
|
+
async function scanDirectory(dir, depth = 0) {
|
|
4189
|
+
if (depth > MAX_DEPTH) return;
|
|
4190
|
+
|
|
4191
|
+
scannedCount++;
|
|
4192
|
+
|
|
4193
|
+
// 检查当前目录的package.json
|
|
4194
|
+
await checkPackageJson(dir);
|
|
4195
|
+
|
|
4196
|
+
// 如果已经达到最大深度,不再继续
|
|
4197
|
+
if (depth >= MAX_DEPTH) return;
|
|
4198
|
+
|
|
4199
|
+
// 读取子目录
|
|
4200
|
+
try {
|
|
4201
|
+
const items = await fs.readdir(dir, { withFileTypes: true });
|
|
4202
|
+
const subDirs = [];
|
|
4203
|
+
|
|
4204
|
+
// 收集所有子目录
|
|
4205
|
+
for (const item of items) {
|
|
4206
|
+
if (!item.isDirectory()) continue;
|
|
4207
|
+
|
|
4208
|
+
const dirName = item.name;
|
|
4209
|
+
|
|
4210
|
+
// 跳过忽略的目录
|
|
4211
|
+
if (IGNORED_DIRS.has(dirName) || dirName.startsWith('.')) {
|
|
4212
|
+
continue;
|
|
4213
|
+
}
|
|
4214
|
+
|
|
4215
|
+
subDirs.push(item);
|
|
4216
|
+
}
|
|
4217
|
+
|
|
4218
|
+
// 限制每层扫描的子目录数量
|
|
4219
|
+
const dirsToScan = subDirs.slice(0, MAX_DIRS_PER_LEVEL);
|
|
4220
|
+
|
|
4221
|
+
// 递归扫描子目录
|
|
4222
|
+
for (const item of dirsToScan) {
|
|
4223
|
+
const subDirPath = path.join(dir, item.name);
|
|
4224
|
+
await scanDirectory(subDirPath, depth + 1);
|
|
4225
|
+
}
|
|
4226
|
+
} catch (error) {
|
|
4227
|
+
// 忽略无法读取的目录
|
|
4228
|
+
}
|
|
4229
|
+
}
|
|
4230
|
+
|
|
4231
|
+
// 开始扫描
|
|
4232
|
+
await scanDirectory(projectRoot);
|
|
4233
|
+
|
|
4234
|
+
const scanTime = Date.now() - startTime;
|
|
4235
|
+
|
|
4236
|
+
res.json({
|
|
4237
|
+
success: true,
|
|
4238
|
+
packages: packageFiles,
|
|
4239
|
+
scanTime,
|
|
4240
|
+
scannedCount,
|
|
4241
|
+
fileReadCount
|
|
4242
|
+
});
|
|
4243
|
+
} catch (error) {
|
|
4244
|
+
console.error('扫描package.json文件失败:', error);
|
|
4245
|
+
res.status(500).json({
|
|
4246
|
+
success: false,
|
|
4247
|
+
error: `扫描package.json文件失败: ${error.message}`
|
|
4248
|
+
});
|
|
4249
|
+
}
|
|
4250
|
+
});
|
|
4251
|
+
|
|
4106
4252
|
// 在新终端中执行npm脚本
|
|
4107
4253
|
app.post('/api/run-npm-script', async (req, res) => {
|
|
4108
4254
|
try {
|