zen-gitsync 2.4.10 → 2.4.11
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-BjdGW78N.css +1 -0
- package/src/ui/public/assets/index-Cn7LQamN.js +46 -0
- package/src/ui/public/assets/{vendor-D-Vg0AbY.js → vendor-C6SHWN-W.js} +18 -13
- package/src/ui/public/index.html +3 -3
- package/src/ui/server/index.js +188 -1
- package/src/utils/index.js +40 -1
- package/src/ui/public/assets/index-BmMYpCWy.css +0 -1
- package/src/ui/public/assets/index-COr7M_hD.js +0 -45
package/src/ui/public/index.html
CHANGED
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
7
|
<title>Zen-GitSync - Git同步工具</title>
|
|
8
|
-
<script type="module" crossorigin src="/assets/index-
|
|
9
|
-
<link rel="modulepreload" crossorigin href="/assets/vendor-
|
|
8
|
+
<script type="module" crossorigin src="/assets/index-Cn7LQamN.js"></script>
|
|
9
|
+
<link rel="modulepreload" crossorigin href="/assets/vendor-C6SHWN-W.js">
|
|
10
10
|
<link rel="stylesheet" crossorigin href="/assets/vendor-D9qDBEE1.css">
|
|
11
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
11
|
+
<link rel="stylesheet" crossorigin href="/assets/index-BjdGW78N.css">
|
|
12
12
|
</head>
|
|
13
13
|
<body>
|
|
14
14
|
<div id="app"></div>
|
package/src/ui/server/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import express from 'express';
|
|
|
2
2
|
import { createServer } from 'http';
|
|
3
3
|
import { fileURLToPath } from 'url';
|
|
4
4
|
import path from 'path';
|
|
5
|
-
import { execGitCommand, getCommandHistory, clearCommandHistory, registerSocketIO, execGitAddWithLockFilter } from '../../utils/index.js';
|
|
5
|
+
import { execGitCommand, getCommandHistory, addCommandToHistory, clearCommandHistory, registerSocketIO, execGitAddWithLockFilter } from '../../utils/index.js';
|
|
6
6
|
import open from 'open';
|
|
7
7
|
import config from '../../config.js';
|
|
8
8
|
import chalk from 'chalk';
|
|
@@ -10,6 +10,7 @@ import fs from 'fs/promises';
|
|
|
10
10
|
import os from 'os';
|
|
11
11
|
import { Server } from 'socket.io';
|
|
12
12
|
import chokidar from 'chokidar';
|
|
13
|
+
import { spawn } from 'child_process';
|
|
13
14
|
// import { exec } from 'child_process';
|
|
14
15
|
|
|
15
16
|
const __filename = fileURLToPath(import.meta.url);
|
|
@@ -1392,6 +1393,192 @@ async function startUIServer(noOpen = false, savePort = false) {
|
|
|
1392
1393
|
res.status(500).json({ success: false, error: error.message });
|
|
1393
1394
|
}
|
|
1394
1395
|
});
|
|
1396
|
+
|
|
1397
|
+
// 带进度的推送更改 (SSE)
|
|
1398
|
+
app.post('/api/push-with-progress', async (req, res) => {
|
|
1399
|
+
// 设置SSE响应头
|
|
1400
|
+
res.setHeader('Content-Type', 'text/event-stream');
|
|
1401
|
+
res.setHeader('Cache-Control', 'no-cache');
|
|
1402
|
+
res.setHeader('Connection', 'keep-alive');
|
|
1403
|
+
res.flushHeaders();
|
|
1404
|
+
|
|
1405
|
+
const sendProgress = (data) => {
|
|
1406
|
+
res.write(`data: ${JSON.stringify(data)}\n\n`);
|
|
1407
|
+
};
|
|
1408
|
+
|
|
1409
|
+
try {
|
|
1410
|
+
// 获取当前工作目录 - 与execGitCommand保持一致
|
|
1411
|
+
const cwdArg = process.argv.find(arg => arg.startsWith('--path')) || process.argv.find(arg => arg.startsWith('--cwd'));
|
|
1412
|
+
let workDir = process.cwd();
|
|
1413
|
+
if (cwdArg) {
|
|
1414
|
+
const [, value] = cwdArg.split('=');
|
|
1415
|
+
workDir = value || process.cwd();
|
|
1416
|
+
}
|
|
1417
|
+
|
|
1418
|
+
console.log('开始推送,工作目录:', workDir);
|
|
1419
|
+
|
|
1420
|
+
// 记录开始时间
|
|
1421
|
+
const startTime = Date.now();
|
|
1422
|
+
|
|
1423
|
+
// 发送开始消息
|
|
1424
|
+
sendProgress({
|
|
1425
|
+
type: 'progress',
|
|
1426
|
+
message: '开始推送到远程仓库...'
|
|
1427
|
+
});
|
|
1428
|
+
|
|
1429
|
+
// 使用spawn执行git push --progress
|
|
1430
|
+
const gitPush = spawn('git', ['push', '--progress'], {
|
|
1431
|
+
cwd: workDir,
|
|
1432
|
+
env: {
|
|
1433
|
+
...process.env,
|
|
1434
|
+
GIT_CONFIG_PARAMETERS: "'core.quotepath=false'" // 关闭路径转义
|
|
1435
|
+
}
|
|
1436
|
+
});
|
|
1437
|
+
|
|
1438
|
+
let errorOutput = '';
|
|
1439
|
+
let standardOutput = '';
|
|
1440
|
+
|
|
1441
|
+
// Git的进度信息在stderr中
|
|
1442
|
+
gitPush.stderr.on('data', (data) => {
|
|
1443
|
+
const output = data.toString();
|
|
1444
|
+
errorOutput += output;
|
|
1445
|
+
|
|
1446
|
+
// 解析进度信息
|
|
1447
|
+
const lines = output.split('\n');
|
|
1448
|
+
for (const line of lines) {
|
|
1449
|
+
if (line.trim()) {
|
|
1450
|
+
// 发送原始行
|
|
1451
|
+
sendProgress({
|
|
1452
|
+
type: 'progress',
|
|
1453
|
+
message: line.trim()
|
|
1454
|
+
});
|
|
1455
|
+
|
|
1456
|
+
// 识别不同阶段并解析百分比
|
|
1457
|
+
const percentMatch = line.match(/(\d+)%/);
|
|
1458
|
+
if (percentMatch) {
|
|
1459
|
+
const percent = parseInt(percentMatch[1]);
|
|
1460
|
+
let stage = 'unknown';
|
|
1461
|
+
|
|
1462
|
+
if (line.includes('Enumerating objects')) {
|
|
1463
|
+
stage = 'enumerating';
|
|
1464
|
+
} else if (line.includes('Counting objects')) {
|
|
1465
|
+
stage = 'counting';
|
|
1466
|
+
} else if (line.includes('Compressing objects')) {
|
|
1467
|
+
stage = 'compressing';
|
|
1468
|
+
} else if (line.includes('Writing objects')) {
|
|
1469
|
+
stage = 'writing';
|
|
1470
|
+
} else if (line.includes('Resolving deltas')) {
|
|
1471
|
+
stage = 'resolving';
|
|
1472
|
+
}
|
|
1473
|
+
|
|
1474
|
+
sendProgress({
|
|
1475
|
+
type: 'stage-progress',
|
|
1476
|
+
stage: stage,
|
|
1477
|
+
percent: percent,
|
|
1478
|
+
message: line.trim()
|
|
1479
|
+
});
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1483
|
+
});
|
|
1484
|
+
|
|
1485
|
+
gitPush.stdout.on('data', (data) => {
|
|
1486
|
+
standardOutput += data.toString();
|
|
1487
|
+
});
|
|
1488
|
+
|
|
1489
|
+
gitPush.on('close', (code) => {
|
|
1490
|
+
console.log(`Git push 进程结束,退出码: ${code}`);
|
|
1491
|
+
console.log('标准输出:', standardOutput);
|
|
1492
|
+
console.log('错误输出:', errorOutput);
|
|
1493
|
+
|
|
1494
|
+
// 计算执行时间
|
|
1495
|
+
const executionTime = Date.now() - startTime;
|
|
1496
|
+
|
|
1497
|
+
if (code === 0) {
|
|
1498
|
+
// 推送成功
|
|
1499
|
+
recentPushStatus = {
|
|
1500
|
+
justPushed: true,
|
|
1501
|
+
pushTime: Date.now(),
|
|
1502
|
+
validDuration: 10000
|
|
1503
|
+
};
|
|
1504
|
+
|
|
1505
|
+
// 添加到命令历史
|
|
1506
|
+
addCommandToHistory(
|
|
1507
|
+
'git push --progress',
|
|
1508
|
+
standardOutput,
|
|
1509
|
+
errorOutput,
|
|
1510
|
+
null,
|
|
1511
|
+
executionTime
|
|
1512
|
+
);
|
|
1513
|
+
|
|
1514
|
+
sendProgress({
|
|
1515
|
+
type: 'complete',
|
|
1516
|
+
success: true,
|
|
1517
|
+
message: standardOutput || errorOutput || 'Push successful'
|
|
1518
|
+
});
|
|
1519
|
+
} else {
|
|
1520
|
+
// 推送失败
|
|
1521
|
+
console.error('推送失败:', errorOutput || standardOutput);
|
|
1522
|
+
|
|
1523
|
+
// 添加到命令历史(失败情况)
|
|
1524
|
+
addCommandToHistory(
|
|
1525
|
+
'git push --progress',
|
|
1526
|
+
standardOutput,
|
|
1527
|
+
errorOutput,
|
|
1528
|
+
errorOutput || standardOutput || `Push failed with code ${code}`,
|
|
1529
|
+
executionTime
|
|
1530
|
+
);
|
|
1531
|
+
|
|
1532
|
+
sendProgress({
|
|
1533
|
+
type: 'complete',
|
|
1534
|
+
success: false,
|
|
1535
|
+
error: errorOutput || standardOutput || `Push failed with code ${code}`
|
|
1536
|
+
});
|
|
1537
|
+
}
|
|
1538
|
+
res.end();
|
|
1539
|
+
});
|
|
1540
|
+
|
|
1541
|
+
gitPush.on('error', (error) => {
|
|
1542
|
+
console.error('Git push 进程错误:', error);
|
|
1543
|
+
|
|
1544
|
+
// 计算执行时间
|
|
1545
|
+
const executionTime = Date.now() - startTime;
|
|
1546
|
+
|
|
1547
|
+
// 添加到命令历史(错误情况)
|
|
1548
|
+
addCommandToHistory(
|
|
1549
|
+
'git push --progress',
|
|
1550
|
+
'',
|
|
1551
|
+
'',
|
|
1552
|
+
error.message,
|
|
1553
|
+
executionTime
|
|
1554
|
+
);
|
|
1555
|
+
|
|
1556
|
+
sendProgress({
|
|
1557
|
+
type: 'complete',
|
|
1558
|
+
success: false,
|
|
1559
|
+
error: error.message
|
|
1560
|
+
});
|
|
1561
|
+
res.end();
|
|
1562
|
+
});
|
|
1563
|
+
|
|
1564
|
+
} catch (error) {
|
|
1565
|
+
// 添加到命令历史(异常情况)
|
|
1566
|
+
addCommandToHistory(
|
|
1567
|
+
'git push --progress',
|
|
1568
|
+
'',
|
|
1569
|
+
'',
|
|
1570
|
+
error.message,
|
|
1571
|
+
0
|
|
1572
|
+
);
|
|
1573
|
+
|
|
1574
|
+
sendProgress({
|
|
1575
|
+
type: 'complete',
|
|
1576
|
+
success: false,
|
|
1577
|
+
error: error.message
|
|
1578
|
+
});
|
|
1579
|
+
res.end();
|
|
1580
|
+
}
|
|
1581
|
+
});
|
|
1395
1582
|
|
|
1396
1583
|
// 添加git pull API端点
|
|
1397
1584
|
app.post('/api/pull', async (req, res) => {
|
package/src/utils/index.js
CHANGED
|
@@ -331,6 +331,45 @@ function getCommandHistory() {
|
|
|
331
331
|
return [...commandHistory];
|
|
332
332
|
}
|
|
333
333
|
|
|
334
|
+
// Function to manually add command to history (for commands not using execGitCommand)
|
|
335
|
+
function addCommandToHistory(command, stdout = '', stderr = '', error = null, executionTime = 0) {
|
|
336
|
+
const MAX_OUTPUT_LENGTH = 5000;
|
|
337
|
+
|
|
338
|
+
// Truncate outputs if too long
|
|
339
|
+
const isStdoutTruncated = stdout.length > MAX_OUTPUT_LENGTH;
|
|
340
|
+
const isStderrTruncated = stderr.length > MAX_OUTPUT_LENGTH;
|
|
341
|
+
const truncatedStdout = isStdoutTruncated ? stdout.substring(0, MAX_OUTPUT_LENGTH) + '...[truncated]' : stdout;
|
|
342
|
+
const truncatedStderr = isStderrTruncated ? stderr.substring(0, MAX_OUTPUT_LENGTH) + '...[truncated]' : stderr;
|
|
343
|
+
|
|
344
|
+
const historyItem = {
|
|
345
|
+
command,
|
|
346
|
+
stdout: truncatedStdout || '',
|
|
347
|
+
stderr: truncatedStderr || '',
|
|
348
|
+
error: error ? (typeof error === 'string' ? error : error.message) : null,
|
|
349
|
+
executionTime,
|
|
350
|
+
timestamp: new Date().toISOString(),
|
|
351
|
+
success: !error,
|
|
352
|
+
isStdoutTruncated,
|
|
353
|
+
isStderrTruncated
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
// Add to history (limited size)
|
|
357
|
+
commandHistory.unshift(historyItem);
|
|
358
|
+
if (commandHistory.length > MAX_HISTORY_SIZE) {
|
|
359
|
+
commandHistory.pop();
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// Broadcast via WebSocket if available
|
|
363
|
+
if (ioInstance) {
|
|
364
|
+
ioInstance.emit('command_history_update', {
|
|
365
|
+
newCommand: historyItem,
|
|
366
|
+
fullHistory: commandHistory.slice(0, 10)
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
return historyItem;
|
|
371
|
+
}
|
|
372
|
+
|
|
334
373
|
const getCwd = () => {
|
|
335
374
|
const cwdArg = process.argv.find(arg => arg.startsWith('--path')) || process.argv.find(arg => arg.startsWith('--cwd'));
|
|
336
375
|
if (cwdArg) {
|
|
@@ -914,7 +953,7 @@ async function addResetScriptToPackageJson() {
|
|
|
914
953
|
|
|
915
954
|
export {
|
|
916
955
|
coloredLog, errorLog, execSyncGitCommand,
|
|
917
|
-
execGitCommand, getCommandHistory, // Add
|
|
956
|
+
execGitCommand, getCommandHistory, addCommandToHistory, // Add command history exports
|
|
918
957
|
clearCommandHistory,
|
|
919
958
|
registerSocketIO, // 导出注册Socket.io的函数
|
|
920
959
|
getCwd, judgePlatform, showHelp, judgeLog, printGitLog,
|