zen-gitsync 2.5.1 → 2.5.3

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zen-gitsync",
3
- "version": "2.5.1",
3
+ "version": "2.5.3",
4
4
  "description": "一个 git 自动查看差异并提交的工具",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -96,8 +96,41 @@ async function startUIServer(noOpen = false, savePort = false) {
96
96
 
97
97
  // 添加请求日志中间件
98
98
  app.use((req, res, next) => {
99
- const now = new Date().toLocaleString();
100
- console.log(`[${now}] ${req.method} ${req.url}`);
99
+ const startTime = Date.now();
100
+ const requestTime = new Date().toLocaleString('zh-CN', { hour12: false });
101
+
102
+ // 监听响应完成事件
103
+ res.on('finish', () => {
104
+ const duration = Date.now() - startTime;
105
+ const statusCode = res.statusCode;
106
+
107
+ // 根据状态码选择颜色
108
+ let statusColor = chalk.green;
109
+ if (statusCode >= 400 && statusCode < 500) {
110
+ statusColor = chalk.yellow;
111
+ } else if (statusCode >= 500) {
112
+ statusColor = chalk.red;
113
+ }
114
+
115
+ // 根据请求耗时选择颜色
116
+ let durationColor = chalk.gray;
117
+ if (duration > 1000) {
118
+ durationColor = chalk.red;
119
+ } else if (duration > 500) {
120
+ durationColor = chalk.yellow;
121
+ } else if (duration > 200) {
122
+ durationColor = chalk.cyan;
123
+ }
124
+
125
+ console.log(
126
+ chalk.dim(`[${requestTime}]`),
127
+ chalk.bold(req.method),
128
+ req.url,
129
+ statusColor(`[${statusCode}]`),
130
+ durationColor(`${duration}ms`)
131
+ );
132
+ });
133
+
101
134
  next();
102
135
  });
103
136
 
@@ -202,6 +202,11 @@ function execSyncGitCommand(command, options = {}) {
202
202
  }
203
203
  let result = output.trim()
204
204
  log && coloredLog(head, result)
205
+ // 打印当前目录和时间信息
206
+ if (log) {
207
+ const currentTime = new Date().toLocaleString('zh-CN', { hour12: false });
208
+ console.log(chalk.dim(`📁 目录: ${cwd} | ⏰ 时间: ${currentTime}`));
209
+ }
205
210
  return result
206
211
  } catch (e) {
207
212
  // console.log(`执行命令出错 ==> `, command, e)
@@ -312,8 +317,18 @@ function execGitCommand(command, options = {}) {
312
317
  if (stderr) {
313
318
  log && coloredLog(head, stderr)
314
319
  }
320
+ // 打印当前目录和时间信息
321
+ if (log && (stdout || stderr)) {
322
+ const currentTime = new Date().toLocaleString('zh-CN', { hour12: false });
323
+ console.log(chalk.dim(`📁 目录: ${cwd} | ⏰ 时间: ${currentTime}`));
324
+ }
315
325
  if (error) {
316
326
  log && coloredLog(head, error, 'error')
327
+ // 错误情况也打印目录和时间
328
+ if (log) {
329
+ const currentTime = new Date().toLocaleString('zh-CN', { hour12: false });
330
+ console.log(chalk.dim(`📁 目录: ${cwd} | ⏰ 时间: ${currentTime}`));
331
+ }
317
332
  reject(error)
318
333
  return
319
334
  }