zen-gitsync 2.15.11 → 2.15.12
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 +3 -3
- package/src/gitCommit.js +475 -475
- package/src/ui/public/assets/AppVersionBadge-BaXEI9Aq.js +2 -0
- package/src/ui/public/assets/BranchSelector-DJhEF0y9.js +1 -0
- package/src/ui/public/assets/CommitForm-BfpcK-bz.js +6 -0
- package/src/ui/public/assets/ConsoleView-D838O0O6.js +17 -0
- package/src/ui/public/assets/CustomCommandManager-BcCK46df.js +1 -0
- package/src/ui/public/assets/EditorView-DnnqYNGF.js +0 -0
- package/src/ui/public/assets/{FlowExecutionViewer-CJgoxffE.js → FlowExecutionViewer-CSlMmcDS.js} +1 -1
- package/src/ui/public/assets/FlowOrchestrationWorkspace-UgHpZ3FR.js +21 -0
- package/src/ui/public/assets/LogList-uUgskwwp.js +7 -0
- package/src/ui/public/assets/MindmapView-CCmFMiHR.js +1 -0
- package/src/ui/public/assets/MonitorView-BxoqeX70.js +1 -0
- package/src/ui/public/assets/ProjectStartupButton-C3AwivIB.js +1 -0
- package/src/ui/public/assets/{RemoteRepoCard-CKQguRWi.js → RemoteRepoCard-BbxeVpje.js} +1 -1
- package/src/ui/public/assets/SourceMapView-DKv-Y6t_.js +3 -0
- package/src/ui/public/assets/{SvgIcon-DOkE0Qie.js → SvgIcon-sMM8XFgm.js} +1 -1
- package/src/ui/public/assets/TemplateManager-Dzj8rXVw.js +1 -0
- package/src/ui/public/assets/UserInputNode-BU7Trzq-.js +1 -0
- package/src/ui/public/assets/WorkbenchView-DTgRoOkv.js +12 -0
- package/src/ui/public/assets/{_plugin-vue_export-helper-DvV-QrsM.js → _plugin-vue_export-helper-8ryIYVvs.js} +1 -1
- package/src/ui/public/assets/{configStore-BRR4SloR.js → configStore-D77uNk8X.js} +1 -1
- package/src/ui/public/assets/element-plus-D8SQiesr.js +17 -0
- package/src/ui/public/assets/element-plus-DB_sOyH_.css +1 -0
- package/src/ui/public/assets/{flow-mindmap-BMvnvRl8.js → flow-mindmap-BLa-kSA7.js} +1 -1
- package/src/ui/public/assets/index-CpFreGqX.js +23 -0
- package/src/ui/public/assets/{socket-io-C2w3MxRu.js → socket-io-B1foIbJS.js} +1 -1
- package/src/ui/public/assets/{vendor--LaaJk9m.js → vendor-B9orL8iU.js} +37 -37
- package/src/ui/public/assets/vendor-Dm_yd-By.css +1 -0
- package/src/ui/public/assets/{vue-flow-MtbKS8yD.js → vue-flow-BY7LODit.js} +1 -1
- package/src/ui/public/favicon.svg +75 -75
- package/src/ui/public/index.html +27 -27
- package/src/ui/public/logo.svg +74 -74
- package/src/ui/server/middleware/requestLogger.js +53 -53
- package/src/ui/server/routes/branchStatus.js +105 -105
- package/src/ui/server/routes/fileOpen.js +309 -309
- package/src/ui/server/routes/fs.js +791 -791
- package/src/ui/server/routes/git/diff.js +426 -426
- package/src/ui/server/routes/git/diffUtils.js +149 -149
- package/src/ui/server/routes/git/stash.js +550 -550
- package/src/ui/server/routes/git/tags.js +176 -176
- package/src/ui/server/routes/git.js +181 -181
- package/src/ui/server/routes/gitOps.js +1211 -1211
- package/src/ui/server/routes/process.js +86 -86
- package/src/ui/server/routes/status.js +67 -67
- package/src/ui/server/utils/createSavePortToFile.js +48 -48
- package/src/ui/server/utils/instanceRegistry.js +282 -282
- package/src/ui/server/utils/startServerOnAvailablePort.js +116 -116
- package/src/utils/index.js +1168 -1168
- package/src/ui/public/assets/AppVersionBadge-CEhrATQo.js +0 -2
- package/src/ui/public/assets/BranchSelector-xLl3O-4I.js +0 -1
- package/src/ui/public/assets/CommitForm--izGtr_x.js +0 -6
- package/src/ui/public/assets/ConsoleView-BLYfnXAy.js +0 -17
- package/src/ui/public/assets/CustomCommandManager-D8Qd3b9m.js +0 -1
- package/src/ui/public/assets/EditorView-DG8tqp3L.js +0 -0
- package/src/ui/public/assets/FlowOrchestrationWorkspace-BAIqeASp.js +0 -21
- package/src/ui/public/assets/LogList-DjuL8nWB.js +0 -7
- package/src/ui/public/assets/MindmapView-DPomtQsu.js +0 -1
- package/src/ui/public/assets/MonitorView-gZhz528u.js +0 -1
- package/src/ui/public/assets/ProjectStartupButton-C8nDEd8N.js +0 -1
- package/src/ui/public/assets/SourceMapView-DfSRy6lc.js +0 -3
- package/src/ui/public/assets/TemplateManager-BJZloJIO.js +0 -1
- package/src/ui/public/assets/UserInputNode-DpRNQzrz.js +0 -1
- package/src/ui/public/assets/WorkbenchView-vaZsec5Z.js +0 -12
- package/src/ui/public/assets/element-plus-CL7fBdM_.js +0 -24
- package/src/ui/public/assets/element-plus-Cu9Y2raX.css +0 -1
- package/src/ui/public/assets/index-BAFCDhj2.js +0 -23
- package/src/ui/public/assets/vendor-CCbwTgrE.css +0 -1
- package/src/ui/server/.claude/codediff.txt +0 -8
|
@@ -1,86 +1,86 @@
|
|
|
1
|
-
// Copyright 2026 xz333221
|
|
2
|
-
//
|
|
3
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
// you may not use this file except in compliance with the License.
|
|
5
|
-
// You may obtain a copy of the License at
|
|
6
|
-
//
|
|
7
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
//
|
|
9
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
// See the License for the specific language governing permissions and
|
|
13
|
-
// limitations under the License.
|
|
14
|
-
//
|
|
15
|
-
import { asyncRoute, HttpError } from '../utils/asyncRoute.js'
|
|
16
|
-
|
|
17
|
-
import logger from '../utils/logger.js'
|
|
18
|
-
|
|
19
|
-
export function registerProcessRoutes({
|
|
20
|
-
app,
|
|
21
|
-
runningProcesses,
|
|
22
|
-
exec
|
|
23
|
-
}) {
|
|
24
|
-
// 停止正在运行的进程
|
|
25
|
-
app.post('/api/kill-process', asyncRoute(async (req, res) => {
|
|
26
|
-
try {
|
|
27
|
-
const { processId } = req.body || {};
|
|
28
|
-
if (!processId || typeof processId !== 'number') {
|
|
29
|
-
throw new HttpError(400, 'processId 必须是数字');
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const processInfo = runningProcesses.get(processId);
|
|
33
|
-
if (!processInfo) {
|
|
34
|
-
return res.status(404).json({
|
|
35
|
-
success: false,
|
|
36
|
-
error: `进程 #${processId} 不存在或已结束`
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
logger.info(`[进程管理] 尝试停止进程 #${processId}: ${processInfo.command}`);
|
|
41
|
-
|
|
42
|
-
try {
|
|
43
|
-
// 在 Windows 上需要使用 taskkill 来杀死整个进程树
|
|
44
|
-
if (process.platform === 'win32') {
|
|
45
|
-
// 使用已导入的 exec
|
|
46
|
-
// /F 强制终止, /T 终止进程树
|
|
47
|
-
exec(`taskkill /pid ${processInfo.childProcess.pid} /T /F`, (error) => {
|
|
48
|
-
if (error) {
|
|
49
|
-
logger.error(`[进程管理] taskkill 失败:`, error);
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
} else {
|
|
53
|
-
// Unix/Linux/Mac 使用 SIGTERM
|
|
54
|
-
processInfo.childProcess.kill('SIGTERM');
|
|
55
|
-
|
|
56
|
-
// 如果 2 秒后还没结束,使用 SIGKILL 强制终止
|
|
57
|
-
setTimeout(() => {
|
|
58
|
-
if (runningProcesses.has(processId)) {
|
|
59
|
-
logger.info(`[进程管理] 进程 #${processId} 未响应 SIGTERM,使用 SIGKILL 强制终止`);
|
|
60
|
-
processInfo.childProcess.kill('SIGKILL');
|
|
61
|
-
}
|
|
62
|
-
}, 2000);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
res.json({
|
|
66
|
-
success: true,
|
|
67
|
-
message: `已发送停止信号到进程 #${processId}`,
|
|
68
|
-
processId,
|
|
69
|
-
command: processInfo.command
|
|
70
|
-
});
|
|
71
|
-
} catch (killError) {
|
|
72
|
-
logger.error(`[进程管理] 停止进程失败:`, killError);
|
|
73
|
-
res.status(500).json({
|
|
74
|
-
success: false,
|
|
75
|
-
error: `停止进程失败: ${killError.message}`
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
} catch (error) {
|
|
79
|
-
logger.error('停止进程接口失败:', error);
|
|
80
|
-
res.status(500).json({
|
|
81
|
-
success: false,
|
|
82
|
-
error: `停止进程失败: ${error.message}`
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
}));
|
|
86
|
-
}
|
|
1
|
+
// Copyright 2026 xz333221
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
//
|
|
15
|
+
import { asyncRoute, HttpError } from '../utils/asyncRoute.js'
|
|
16
|
+
|
|
17
|
+
import logger from '../utils/logger.js'
|
|
18
|
+
|
|
19
|
+
export function registerProcessRoutes({
|
|
20
|
+
app,
|
|
21
|
+
runningProcesses,
|
|
22
|
+
exec
|
|
23
|
+
}) {
|
|
24
|
+
// 停止正在运行的进程
|
|
25
|
+
app.post('/api/kill-process', asyncRoute(async (req, res) => {
|
|
26
|
+
try {
|
|
27
|
+
const { processId } = req.body || {};
|
|
28
|
+
if (!processId || typeof processId !== 'number') {
|
|
29
|
+
throw new HttpError(400, 'processId 必须是数字');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const processInfo = runningProcesses.get(processId);
|
|
33
|
+
if (!processInfo) {
|
|
34
|
+
return res.status(404).json({
|
|
35
|
+
success: false,
|
|
36
|
+
error: `进程 #${processId} 不存在或已结束`
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
logger.info(`[进程管理] 尝试停止进程 #${processId}: ${processInfo.command}`);
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
// 在 Windows 上需要使用 taskkill 来杀死整个进程树
|
|
44
|
+
if (process.platform === 'win32') {
|
|
45
|
+
// 使用已导入的 exec
|
|
46
|
+
// /F 强制终止, /T 终止进程树
|
|
47
|
+
exec(`taskkill /pid ${processInfo.childProcess.pid} /T /F`, (error) => {
|
|
48
|
+
if (error) {
|
|
49
|
+
logger.error(`[进程管理] taskkill 失败:`, error);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
} else {
|
|
53
|
+
// Unix/Linux/Mac 使用 SIGTERM
|
|
54
|
+
processInfo.childProcess.kill('SIGTERM');
|
|
55
|
+
|
|
56
|
+
// 如果 2 秒后还没结束,使用 SIGKILL 强制终止
|
|
57
|
+
setTimeout(() => {
|
|
58
|
+
if (runningProcesses.has(processId)) {
|
|
59
|
+
logger.info(`[进程管理] 进程 #${processId} 未响应 SIGTERM,使用 SIGKILL 强制终止`);
|
|
60
|
+
processInfo.childProcess.kill('SIGKILL');
|
|
61
|
+
}
|
|
62
|
+
}, 2000);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
res.json({
|
|
66
|
+
success: true,
|
|
67
|
+
message: `已发送停止信号到进程 #${processId}`,
|
|
68
|
+
processId,
|
|
69
|
+
command: processInfo.command
|
|
70
|
+
});
|
|
71
|
+
} catch (killError) {
|
|
72
|
+
logger.error(`[进程管理] 停止进程失败:`, killError);
|
|
73
|
+
res.status(500).json({
|
|
74
|
+
success: false,
|
|
75
|
+
error: `停止进程失败: ${killError.message}`
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
} catch (error) {
|
|
79
|
+
logger.error('停止进程接口失败:', error);
|
|
80
|
+
res.status(500).json({
|
|
81
|
+
success: false,
|
|
82
|
+
error: `停止进程失败: ${error.message}`
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
@@ -1,67 +1,67 @@
|
|
|
1
|
-
// Copyright 2026 xz333221
|
|
2
|
-
//
|
|
3
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
// you may not use this file except in compliance with the License.
|
|
5
|
-
// You may obtain a copy of the License at
|
|
6
|
-
//
|
|
7
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
//
|
|
9
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
// See the License for the specific language governing permissions and
|
|
13
|
-
// limitations under the License.
|
|
14
|
-
//
|
|
15
|
-
import { promises as fs } from 'fs';
|
|
16
|
-
import { asyncRoute, HttpError } from '../utils/asyncRoute.js';
|
|
17
|
-
import path from 'path';
|
|
18
|
-
|
|
19
|
-
export function registerStatusRoutes({
|
|
20
|
-
app,
|
|
21
|
-
getCommandHistory,
|
|
22
|
-
execGitCommand
|
|
23
|
-
}) {
|
|
24
|
-
// Add new endpoint for command history
|
|
25
|
-
app.get('/api/command-history', asyncRoute(async (req, res) => {
|
|
26
|
-
try {
|
|
27
|
-
const history = getCommandHistory();
|
|
28
|
-
res.json({ success: true, history });
|
|
29
|
-
} catch (error) {
|
|
30
|
-
res.status(500).json({ success: false, error: error.message });
|
|
31
|
-
}
|
|
32
|
-
}));
|
|
33
|
-
|
|
34
|
-
app.get('/api/status_porcelain', asyncRoute(async (req, res) => {
|
|
35
|
-
try {
|
|
36
|
-
const { stdout } = await execGitCommand(['status', '--porcelain', '--untracked-files=all']);
|
|
37
|
-
// 检测是否处于 MERGING 状态(MERGE_HEAD 存在)
|
|
38
|
-
let isMergeInProgress = false;
|
|
39
|
-
let mergeMessage = '';
|
|
40
|
-
try {
|
|
41
|
-
const { stdout: mergeHead } = await execGitCommand(['rev-parse', '-q', '--verify', 'MERGE_HEAD']);
|
|
42
|
-
isMergeInProgress = mergeHead.trim().length > 0;
|
|
43
|
-
} catch (_) {
|
|
44
|
-
// MERGE_HEAD 不存在时命令会报错,属正常情况
|
|
45
|
-
isMergeInProgress = false;
|
|
46
|
-
}
|
|
47
|
-
if (isMergeInProgress) {
|
|
48
|
-
try {
|
|
49
|
-
const { stdout: gitDir } = await execGitCommand(['rev-parse', '--git-dir']);
|
|
50
|
-
const mergeMsgPath = path.resolve(gitDir.trim(), 'MERGE_MSG');
|
|
51
|
-
const raw = await fs.readFile(mergeMsgPath, 'utf-8');
|
|
52
|
-
// 过滤掉以 # 开头的注释行,拼接所有非空非注释行(保留多段信息如合并分支列表)
|
|
53
|
-
mergeMessage = raw
|
|
54
|
-
.split('\n')
|
|
55
|
-
.filter(line => line.trim() && !line.startsWith('#'))
|
|
56
|
-
.join('\n')
|
|
57
|
-
.trim();
|
|
58
|
-
} catch (_) {
|
|
59
|
-
// MERGE_MSG 不存在/无权限时忽略
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
res.json({ status: stdout, isMergeInProgress, mergeMessage });
|
|
63
|
-
} catch (error) {
|
|
64
|
-
res.status(500).json({ error: error.message });
|
|
65
|
-
}
|
|
66
|
-
}));
|
|
67
|
-
}
|
|
1
|
+
// Copyright 2026 xz333221
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
//
|
|
15
|
+
import { promises as fs } from 'fs';
|
|
16
|
+
import { asyncRoute, HttpError } from '../utils/asyncRoute.js';
|
|
17
|
+
import path from 'path';
|
|
18
|
+
|
|
19
|
+
export function registerStatusRoutes({
|
|
20
|
+
app,
|
|
21
|
+
getCommandHistory,
|
|
22
|
+
execGitCommand
|
|
23
|
+
}) {
|
|
24
|
+
// Add new endpoint for command history
|
|
25
|
+
app.get('/api/command-history', asyncRoute(async (req, res) => {
|
|
26
|
+
try {
|
|
27
|
+
const history = getCommandHistory();
|
|
28
|
+
res.json({ success: true, history });
|
|
29
|
+
} catch (error) {
|
|
30
|
+
res.status(500).json({ success: false, error: error.message });
|
|
31
|
+
}
|
|
32
|
+
}));
|
|
33
|
+
|
|
34
|
+
app.get('/api/status_porcelain', asyncRoute(async (req, res) => {
|
|
35
|
+
try {
|
|
36
|
+
const { stdout } = await execGitCommand(['status', '--porcelain', '--untracked-files=all']);
|
|
37
|
+
// 检测是否处于 MERGING 状态(MERGE_HEAD 存在)
|
|
38
|
+
let isMergeInProgress = false;
|
|
39
|
+
let mergeMessage = '';
|
|
40
|
+
try {
|
|
41
|
+
const { stdout: mergeHead } = await execGitCommand(['rev-parse', '-q', '--verify', 'MERGE_HEAD']);
|
|
42
|
+
isMergeInProgress = mergeHead.trim().length > 0;
|
|
43
|
+
} catch (_) {
|
|
44
|
+
// MERGE_HEAD 不存在时命令会报错,属正常情况
|
|
45
|
+
isMergeInProgress = false;
|
|
46
|
+
}
|
|
47
|
+
if (isMergeInProgress) {
|
|
48
|
+
try {
|
|
49
|
+
const { stdout: gitDir } = await execGitCommand(['rev-parse', '--git-dir']);
|
|
50
|
+
const mergeMsgPath = path.resolve(gitDir.trim(), 'MERGE_MSG');
|
|
51
|
+
const raw = await fs.readFile(mergeMsgPath, 'utf-8');
|
|
52
|
+
// 过滤掉以 # 开头的注释行,拼接所有非空非注释行(保留多段信息如合并分支列表)
|
|
53
|
+
mergeMessage = raw
|
|
54
|
+
.split('\n')
|
|
55
|
+
.filter(line => line.trim() && !line.startsWith('#'))
|
|
56
|
+
.join('\n')
|
|
57
|
+
.trim();
|
|
58
|
+
} catch (_) {
|
|
59
|
+
// MERGE_MSG 不存在/无权限时忽略
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
res.json({ status: stdout, isMergeInProgress, mergeMessage });
|
|
63
|
+
} catch (error) {
|
|
64
|
+
res.status(500).json({ error: error.message });
|
|
65
|
+
}
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
// Copyright 2026 xz333221
|
|
2
|
-
//
|
|
3
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
// you may not use this file except in compliance with the License.
|
|
5
|
-
// You may obtain a copy of the License at
|
|
6
|
-
//
|
|
7
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
//
|
|
9
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
// See the License for the specific language governing permissions and
|
|
13
|
-
// limitations under the License.
|
|
14
|
-
//
|
|
15
|
-
import logger from './logger.js'
|
|
16
|
-
|
|
17
|
-
export function createSavePortToFile({ savePort, fs, path, cwdFn = process.cwd }) {
|
|
18
|
-
let savedPort = null;
|
|
19
|
-
|
|
20
|
-
return async function savePortToFile(port) {
|
|
21
|
-
try {
|
|
22
|
-
if (savePort && savedPort !== port) {
|
|
23
|
-
savedPort = port;
|
|
24
|
-
|
|
25
|
-
const portFilePath = path.join(cwdFn(), '.port');
|
|
26
|
-
await fs.writeFile(portFilePath, port.toString(), 'utf8');
|
|
27
|
-
logger.info(`端口号 ${port} 已保存到 ${portFilePath}`);
|
|
28
|
-
|
|
29
|
-
try {
|
|
30
|
-
const clientPath = path.join(cwdFn(), 'src', 'ui', 'client');
|
|
31
|
-
const envPath = path.join(clientPath, '.env.local');
|
|
32
|
-
|
|
33
|
-
await fs.access(clientPath).catch(() => {
|
|
34
|
-
logger.info(`客户端目录 ${clientPath} 不存在,跳过环境变量设置`);
|
|
35
|
-
return Promise.reject(new Error('Client directory not found'));
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
await fs.writeFile(envPath, `VITE_BACKEND_PORT=${port}\n`, 'utf8');
|
|
39
|
-
logger.info(`端口号环境变量已保存到 ${envPath}`);
|
|
40
|
-
} catch (envError) {
|
|
41
|
-
logger.error('保存端口号到环境变量失败,但不影响主要功能:', envError);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
} catch (error) {
|
|
45
|
-
logger.error('保存端口号到文件失败:', error);
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
}
|
|
1
|
+
// Copyright 2026 xz333221
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
//
|
|
15
|
+
import logger from './logger.js'
|
|
16
|
+
|
|
17
|
+
export function createSavePortToFile({ savePort, fs, path, cwdFn = process.cwd }) {
|
|
18
|
+
let savedPort = null;
|
|
19
|
+
|
|
20
|
+
return async function savePortToFile(port) {
|
|
21
|
+
try {
|
|
22
|
+
if (savePort && savedPort !== port) {
|
|
23
|
+
savedPort = port;
|
|
24
|
+
|
|
25
|
+
const portFilePath = path.join(cwdFn(), '.port');
|
|
26
|
+
await fs.writeFile(portFilePath, port.toString(), 'utf8');
|
|
27
|
+
logger.info(`端口号 ${port} 已保存到 ${portFilePath}`);
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
const clientPath = path.join(cwdFn(), 'src', 'ui', 'client');
|
|
31
|
+
const envPath = path.join(clientPath, '.env.local');
|
|
32
|
+
|
|
33
|
+
await fs.access(clientPath).catch(() => {
|
|
34
|
+
logger.info(`客户端目录 ${clientPath} 不存在,跳过环境变量设置`);
|
|
35
|
+
return Promise.reject(new Error('Client directory not found'));
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
await fs.writeFile(envPath, `VITE_BACKEND_PORT=${port}\n`, 'utf8');
|
|
39
|
+
logger.info(`端口号环境变量已保存到 ${envPath}`);
|
|
40
|
+
} catch (envError) {
|
|
41
|
+
logger.error('保存端口号到环境变量失败,但不影响主要功能:', envError);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
} catch (error) {
|
|
45
|
+
logger.error('保存端口号到文件失败:', error);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|