zen-gitsync 2.1.2 → 2.1.6

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.
Files changed (38) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +96 -96
  3. package/index.js +2 -2
  4. package/package.json +69 -66
  5. package/src/config.js +51 -51
  6. package/src/gitCommit.js +261 -261
  7. package/src/ui/public/assets/index-8gQo1ABk.js +20 -0
  8. package/src/ui/public/assets/index-IcGOG2Ja.css +1 -0
  9. package/src/ui/public/assets/{vendor-Dy1zosHw.js → vendor-Bm8yNvvz.js} +1 -1
  10. package/src/ui/public/favicon.svg +26 -26
  11. package/src/ui/public/index.html +3 -3
  12. package/src/ui/public/logo.svg +26 -26
  13. package/src/ui/server/index.js +141 -51
  14. package/src/ui/client/README.md +0 -5
  15. package/src/ui/client/auto-imports.d.ts +0 -10
  16. package/src/ui/client/components.d.ts +0 -33
  17. package/src/ui/client/index.html +0 -13
  18. package/src/ui/client/package.json +0 -28
  19. package/src/ui/client/public/favicon.svg +0 -27
  20. package/src/ui/client/public/logo.svg +0 -27
  21. package/src/ui/client/public/vite.svg +0 -1
  22. package/src/ui/client/src/App.vue +0 -984
  23. package/src/ui/client/src/assets/logo.svg +0 -27
  24. package/src/ui/client/src/components/CommitForm.vue +0 -2167
  25. package/src/ui/client/src/components/GitStatus.vue +0 -1621
  26. package/src/ui/client/src/components/LogList.vue +0 -1937
  27. package/src/ui/client/src/main.ts +0 -7
  28. package/src/ui/client/src/stores/configStore.ts +0 -212
  29. package/src/ui/client/src/stores/gitLogStore.ts +0 -790
  30. package/src/ui/client/src/stores/gitStore.ts +0 -443
  31. package/src/ui/client/src/vite-env.d.ts +0 -1
  32. package/src/ui/client/stats.html +0 -4949
  33. package/src/ui/client/tsconfig.app.json +0 -14
  34. package/src/ui/client/tsconfig.json +0 -7
  35. package/src/ui/client/tsconfig.node.json +0 -24
  36. package/src/ui/client/vite.config.ts +0 -50
  37. package/src/ui/public/assets/index-C0FIVyIy.css +0 -1
  38. package/src/ui/public/assets/index-FuuBZ-mS.js +0 -20
package/src/gitCommit.js CHANGED
@@ -1,261 +1,261 @@
1
- #!/usr/bin/env node
2
- import {
3
- coloredLog, errorLog, execGitCommand, execSyncGitCommand, showHelp,
4
- getCwd, judgePlatform, judgeLog, judgeHelp, exec_exit, judgeUnmerged, formatDuration,
5
- exec_push, execPull, judgeRemote, execDiff, execAddAndCommit, delay, addScriptToPackageJson, addResetScriptToPackageJson
6
- } from './utils/index.js';
7
- import readline from 'readline'
8
- import ora from 'ora';
9
- import chalk from 'chalk';
10
- import boxen from 'boxen';
11
- import config from './config.js';
12
- import dateFormat from 'date-fns/format';
13
- import logUpdate from 'log-update';
14
- import startUIServer from './ui/server/index.js';
15
-
16
- let countdownInterval = null;
17
-
18
- function startCountdown(interval) {
19
- let remaining = interval;
20
-
21
- // 清除旧的倒计时
22
- if (countdownInterval) {
23
- clearInterval(countdownInterval);
24
- }
25
-
26
- const render = () => {
27
- const nextTime = Date.now() + remaining;
28
- const formattedTime = dateFormat(nextTime, 'yyyy-MM-dd HH:mm:ss');
29
- const duration = formatDuration(remaining);
30
-
31
- const message = [
32
- `🕒 ${chalk.green.bold('倒计时')}`,
33
- `工作目录: ${chalk.green(getCwd())}`,
34
- `下次提交: ${chalk.blue(formattedTime)}`,
35
- `剩余时间: ${chalk.yellow(duration)}`,
36
- chalk.dim('按 Ctrl+C 终止进程')
37
- ].join('\n');
38
-
39
- const box = boxen(message, {
40
- padding: 1,
41
- margin: 1,
42
- borderColor: 'cyan',
43
- borderStyle: 'round'
44
- });
45
-
46
- setTimeout(() => {
47
- logUpdate(box);
48
- }, 200);
49
- // logUpdate(box);
50
- };
51
-
52
- // 立即渲染一次
53
- render();
54
-
55
- // 每秒更新
56
- countdownInterval = setInterval(() => {
57
- remaining -= 1000;
58
-
59
- if (remaining <= 0) {
60
- clearInterval(countdownInterval);
61
- logUpdate.clear();
62
- return;
63
- }
64
-
65
- render();
66
- }, 1000);
67
- }
68
-
69
- const {loadConfig, saveConfig, handleConfigCommands} = config;
70
- const {defaultCommitMessage} = config
71
-
72
- let timer = null
73
-
74
- async function createGitCommit(options) {
75
- // console.log(`自动提交流程开始=====================>`)
76
- try {
77
- let statusOutput = null
78
- let exit = options ? !!options.exit : true
79
- const config = await loadConfig()
80
- let commitMessage = config.defaultCommitMessage
81
- let {stdout} = await execGitCommand('git status')
82
- statusOutput = stdout
83
- judgeUnmerged(statusOutput)
84
- // 先检查本地是否有未提交的更改
85
- const hasLocalChanges = !statusOutput.includes('nothing to commit, working tree clean');
86
- if (hasLocalChanges) {
87
- // 检查是否有 --no-diff 参数
88
- await execDiff()
89
- await execAddAndCommit({statusOutput, commitMessage, exit})
90
- statusOutput.includes('use "git pull') && await execPull()
91
-
92
- // 检查是否有远程更新
93
- await judgeRemote() // 等待 judgeRemote 完成
94
-
95
- await exec_push({exit, commitMessage})
96
- } else {
97
- if (statusOutput.includes('use "git push')) {
98
- await exec_push({exit, commitMessage})
99
- } else if (statusOutput.includes('use "git pull')) {
100
- await execPull()
101
- } else {
102
- await judgeRemote() // 等待 judgeRemote 完成
103
- exec_exit(exit);
104
- }
105
- }
106
- } catch (e) {
107
- console.error(chalk.red.bold('提交流程错误:'));
108
- console.error(chalk.dim(e.stack)); // 打印完整错误堆栈
109
- throw e; // 继续向上抛出错误
110
- }
111
- }
112
- async function main() {
113
- judgePlatform()
114
-
115
- // 检查是否是UI命令
116
- if (process.argv.includes('ui')) {
117
- await startUIServer();
118
- return;
119
- }
120
-
121
- // 检查是否是添加脚本命令
122
- if (process.argv.includes('addScript')) {
123
- await addScriptToPackageJson();
124
- return;
125
- }
126
-
127
- // 检查是否是添加重置脚本命令
128
- if (process.argv.includes('addResetScript')) {
129
- await addResetScriptToPackageJson();
130
- return;
131
- }
132
-
133
- // 检查是否有 log 参数
134
- judgeLog()
135
-
136
- // 检查帮助参数
137
- judgeHelp()
138
-
139
- await handleConfigCommands();
140
-
141
- judgeInterval();
142
- }
143
-
144
- const showStartInfo = (interval) => {
145
- const cwd = getCwd();
146
- const intervalSeconds = interval / 1000;
147
- const startTime = new Date().toLocaleString();
148
-
149
- const head = `⏰ 定时提交任务已启动`;
150
-
151
- const message = chalk.green.bold([
152
- `开始时间: ${chalk.yellow(startTime)}`,
153
- `工作目录: ${chalk.cyan(cwd)}`,
154
- `提交间隔: ${chalk.magenta(formatDuration(interval))}`,
155
- ].join("\n"));
156
-
157
- coloredLog(head, message)
158
- // console.log('\n'.repeat(6));
159
- }
160
- const commitAndSchedule = async (interval) => {
161
- try {
162
- await createGitCommit({exit: false});
163
- // await delay(2000)
164
- startCountdown(interval); // 启动倒计时
165
-
166
- // 设置定时提交
167
- timer = setTimeout(async () => {
168
- await commitAndSchedule(interval);
169
- }, interval + 100);
170
- } catch (error) {
171
- console.error('提交出错:', error.message);
172
- clearTimeout(timer);
173
- clearInterval(countdownInterval);
174
- process.exit(1);
175
- }
176
- };
177
- const judgeInterval = async () => {
178
- const intervalArg = process.argv.find(arg => arg.startsWith('--interval'));
179
- if (intervalArg) {
180
- let interval = parseInt(intervalArg.split('=')[1] || '3600', 10) * 1000;
181
-
182
- showStartInfo(interval);
183
-
184
- try {
185
- await commitAndSchedule(interval);
186
- } catch (error) {
187
- console.error(chalk.red.bold('定时提交致命错误:'), error.message);
188
- process.exit(1);
189
- }
190
-
191
- // 处理退出清理
192
- process.on('SIGINT', () => {
193
- logUpdate.clear();
194
- clearTimeout(timer);
195
- clearInterval(countdownInterval);
196
- console.log(chalk.yellow('\n🛑 定时任务已终止'));
197
- process.exit();
198
- });
199
- } else {
200
- createGitCommit({exit: false});
201
- }
202
- };
203
- // const judgeInterval = async () => {
204
- // // 判断是否有 --interval 参数
205
- // const intervalArg = process.argv.find(arg => arg.startsWith('--interval'));
206
- // if (intervalArg) {
207
- // // // console.log(`intervalArg ==> `, intervalArg)
208
- // // let interval = intervalArg.split('=')[1] || 60 * 60; // 默认间隔为1小时
209
- // // // console.log(`interval ==> `, interval)
210
- // // interval = parseInt(interval, 10) * 1000; // 将间隔时间转换为毫秒
211
- // // // console.log(`interval ==> `, interval)
212
- // // if (isNaN(interval)) {
213
- // // console.log('无效的间隔时间,请使用 --interval=秒数');
214
- // // process.exit(1);
215
- // // }
216
- // // if (timer) {
217
- // // console.log(`清空定时器`)
218
- // // clearInterval(timer);
219
- // // timer = null;
220
- // // }
221
- // // showStartInfo(interval);
222
- // // await createGitCommit({exit: false})
223
- // //
224
- // // timer = setInterval(() => {
225
- // // // console.log(`定时执行`)
226
- // // createGitCommit({exit: false})
227
- // // }, interval)
228
- //
229
- // let interval = parseInt(intervalArg.split('=')[1] || '3600', 10) * 1000;
230
- // // const showUpdates = () => {
231
- // // showNextCommitTime(interval);
232
- // // // 每小时更新一次时间显示
233
- // // timer = setTimeout(() => {
234
- // // showUpdates();
235
- // // }, 20000); // 每小时更新一次
236
- // // };
237
- //
238
- // const commitAndSchedule = async (interval) => {
239
- // try {
240
- // await createGitCommit({exit: false});
241
- // startCountdown(interval); // 启动倒计时
242
- //
243
- // // 设置定时提交
244
- // timer = setTimeout(async () => {
245
- // await commitAndSchedule(interval);
246
- // }, interval);
247
- // } catch (error) {
248
- // console.error('提交出错:', error.message);
249
- // }
250
- // };
251
- //
252
- // await commitAndSchedule();
253
- //
254
- // // 设置定时提交
255
- // timer = setInterval(commitAndSchedule, interval);
256
- // } else {
257
- // createGitCommit({exit: false})
258
- // }
259
- // };
260
-
261
- main()
1
+ #!/usr/bin/env node
2
+ import {
3
+ coloredLog, errorLog, execGitCommand, execSyncGitCommand, showHelp,
4
+ getCwd, judgePlatform, judgeLog, judgeHelp, exec_exit, judgeUnmerged, formatDuration,
5
+ exec_push, execPull, judgeRemote, execDiff, execAddAndCommit, delay, addScriptToPackageJson, addResetScriptToPackageJson
6
+ } from './utils/index.js';
7
+ import readline from 'readline'
8
+ import ora from 'ora';
9
+ import chalk from 'chalk';
10
+ import boxen from 'boxen';
11
+ import config from './config.js';
12
+ import dateFormat from 'date-fns/format';
13
+ import logUpdate from 'log-update';
14
+ import startUIServer from './ui/server/index.js';
15
+
16
+ let countdownInterval = null;
17
+
18
+ function startCountdown(interval) {
19
+ let remaining = interval;
20
+
21
+ // 清除旧的倒计时
22
+ if (countdownInterval) {
23
+ clearInterval(countdownInterval);
24
+ }
25
+
26
+ const render = () => {
27
+ const nextTime = Date.now() + remaining;
28
+ const formattedTime = dateFormat(nextTime, 'yyyy-MM-dd HH:mm:ss');
29
+ const duration = formatDuration(remaining);
30
+
31
+ const message = [
32
+ `🕒 ${chalk.green.bold('倒计时')}`,
33
+ `工作目录: ${chalk.green(getCwd())}`,
34
+ `下次提交: ${chalk.blue(formattedTime)}`,
35
+ `剩余时间: ${chalk.yellow(duration)}`,
36
+ chalk.dim('按 Ctrl+C 终止进程')
37
+ ].join('\n');
38
+
39
+ const box = boxen(message, {
40
+ padding: 1,
41
+ margin: 1,
42
+ borderColor: 'cyan',
43
+ borderStyle: 'round'
44
+ });
45
+
46
+ setTimeout(() => {
47
+ logUpdate(box);
48
+ }, 200);
49
+ // logUpdate(box);
50
+ };
51
+
52
+ // 立即渲染一次
53
+ render();
54
+
55
+ // 每秒更新
56
+ countdownInterval = setInterval(() => {
57
+ remaining -= 1000;
58
+
59
+ if (remaining <= 0) {
60
+ clearInterval(countdownInterval);
61
+ logUpdate.clear();
62
+ return;
63
+ }
64
+
65
+ render();
66
+ }, 1000);
67
+ }
68
+
69
+ const {loadConfig, saveConfig, handleConfigCommands} = config;
70
+ const {defaultCommitMessage} = config
71
+
72
+ let timer = null
73
+
74
+ async function createGitCommit(options) {
75
+ // console.log(`自动提交流程开始=====================>`)
76
+ try {
77
+ let statusOutput = null
78
+ let exit = options ? !!options.exit : true
79
+ const config = await loadConfig()
80
+ let commitMessage = config.defaultCommitMessage
81
+ let {stdout} = await execGitCommand('git status')
82
+ statusOutput = stdout
83
+ judgeUnmerged(statusOutput)
84
+ // 先检查本地是否有未提交的更改
85
+ const hasLocalChanges = !statusOutput.includes('nothing to commit, working tree clean');
86
+ if (hasLocalChanges) {
87
+ // 检查是否有 --no-diff 参数
88
+ await execDiff()
89
+ await execAddAndCommit({statusOutput, commitMessage, exit})
90
+ statusOutput.includes('use "git pull') && await execPull()
91
+
92
+ // 检查是否有远程更新
93
+ await judgeRemote() // 等待 judgeRemote 完成
94
+
95
+ await exec_push({exit, commitMessage})
96
+ } else {
97
+ if (statusOutput.includes('use "git push')) {
98
+ await exec_push({exit, commitMessage})
99
+ } else if (statusOutput.includes('use "git pull')) {
100
+ await execPull()
101
+ } else {
102
+ await judgeRemote() // 等待 judgeRemote 完成
103
+ exec_exit(exit);
104
+ }
105
+ }
106
+ } catch (e) {
107
+ console.error(chalk.red.bold('提交流程错误:'));
108
+ console.error(chalk.dim(e.stack)); // 打印完整错误堆栈
109
+ throw e; // 继续向上抛出错误
110
+ }
111
+ }
112
+ async function main() {
113
+ judgePlatform()
114
+
115
+ // 检查是否是UI命令
116
+ if (process.argv.includes('ui')) {
117
+ await startUIServer();
118
+ return;
119
+ }
120
+
121
+ // 检查是否是添加脚本命令
122
+ if (process.argv.includes('addScript')) {
123
+ await addScriptToPackageJson();
124
+ return;
125
+ }
126
+
127
+ // 检查是否是添加重置脚本命令
128
+ if (process.argv.includes('addResetScript')) {
129
+ await addResetScriptToPackageJson();
130
+ return;
131
+ }
132
+
133
+ // 检查是否有 log 参数
134
+ judgeLog()
135
+
136
+ // 检查帮助参数
137
+ judgeHelp()
138
+
139
+ await handleConfigCommands();
140
+
141
+ judgeInterval();
142
+ }
143
+
144
+ const showStartInfo = (interval) => {
145
+ const cwd = getCwd();
146
+ const intervalSeconds = interval / 1000;
147
+ const startTime = new Date().toLocaleString();
148
+
149
+ const head = `⏰ 定时提交任务已启动`;
150
+
151
+ const message = chalk.green.bold([
152
+ `开始时间: ${chalk.yellow(startTime)}`,
153
+ `工作目录: ${chalk.cyan(cwd)}`,
154
+ `提交间隔: ${chalk.magenta(formatDuration(interval))}`,
155
+ ].join("\n"));
156
+
157
+ coloredLog(head, message)
158
+ // console.log('\n'.repeat(6));
159
+ }
160
+ const commitAndSchedule = async (interval) => {
161
+ try {
162
+ await createGitCommit({exit: false});
163
+ // await delay(2000)
164
+ startCountdown(interval); // 启动倒计时
165
+
166
+ // 设置定时提交
167
+ timer = setTimeout(async () => {
168
+ await commitAndSchedule(interval);
169
+ }, interval + 100);
170
+ } catch (error) {
171
+ console.error('提交出错:', error.message);
172
+ clearTimeout(timer);
173
+ clearInterval(countdownInterval);
174
+ process.exit(1);
175
+ }
176
+ };
177
+ const judgeInterval = async () => {
178
+ const intervalArg = process.argv.find(arg => arg.startsWith('--interval'));
179
+ if (intervalArg) {
180
+ let interval = parseInt(intervalArg.split('=')[1] || '3600', 10) * 1000;
181
+
182
+ showStartInfo(interval);
183
+
184
+ try {
185
+ await commitAndSchedule(interval);
186
+ } catch (error) {
187
+ console.error(chalk.red.bold('定时提交致命错误:'), error.message);
188
+ process.exit(1);
189
+ }
190
+
191
+ // 处理退出清理
192
+ process.on('SIGINT', () => {
193
+ logUpdate.clear();
194
+ clearTimeout(timer);
195
+ clearInterval(countdownInterval);
196
+ console.log(chalk.yellow('\n🛑 定时任务已终止'));
197
+ process.exit();
198
+ });
199
+ } else {
200
+ createGitCommit({exit: false});
201
+ }
202
+ };
203
+ // const judgeInterval = async () => {
204
+ // // 判断是否有 --interval 参数
205
+ // const intervalArg = process.argv.find(arg => arg.startsWith('--interval'));
206
+ // if (intervalArg) {
207
+ // // // console.log(`intervalArg ==> `, intervalArg)
208
+ // // let interval = intervalArg.split('=')[1] || 60 * 60; // 默认间隔为1小时
209
+ // // // console.log(`interval ==> `, interval)
210
+ // // interval = parseInt(interval, 10) * 1000; // 将间隔时间转换为毫秒
211
+ // // // console.log(`interval ==> `, interval)
212
+ // // if (isNaN(interval)) {
213
+ // // console.log('无效的间隔时间,请使用 --interval=秒数');
214
+ // // process.exit(1);
215
+ // // }
216
+ // // if (timer) {
217
+ // // console.log(`清空定时器`)
218
+ // // clearInterval(timer);
219
+ // // timer = null;
220
+ // // }
221
+ // // showStartInfo(interval);
222
+ // // await createGitCommit({exit: false})
223
+ // //
224
+ // // timer = setInterval(() => {
225
+ // // // console.log(`定时执行`)
226
+ // // createGitCommit({exit: false})
227
+ // // }, interval)
228
+ //
229
+ // let interval = parseInt(intervalArg.split('=')[1] || '3600', 10) * 1000;
230
+ // // const showUpdates = () => {
231
+ // // showNextCommitTime(interval);
232
+ // // // 每小时更新一次时间显示
233
+ // // timer = setTimeout(() => {
234
+ // // showUpdates();
235
+ // // }, 20000); // 每小时更新一次
236
+ // // };
237
+ //
238
+ // const commitAndSchedule = async (interval) => {
239
+ // try {
240
+ // await createGitCommit({exit: false});
241
+ // startCountdown(interval); // 启动倒计时
242
+ //
243
+ // // 设置定时提交
244
+ // timer = setTimeout(async () => {
245
+ // await commitAndSchedule(interval);
246
+ // }, interval);
247
+ // } catch (error) {
248
+ // console.error('提交出错:', error.message);
249
+ // }
250
+ // };
251
+ //
252
+ // await commitAndSchedule();
253
+ //
254
+ // // 设置定时提交
255
+ // timer = setInterval(commitAndSchedule, interval);
256
+ // } else {
257
+ // createGitCommit({exit: false})
258
+ // }
259
+ // };
260
+
261
+ main()