zen-gitsync 1.3.0 → 1.3.1
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/README.md +6 -0
- package/package.json +4 -2
- package/src/gitCommit.js +34 -3
- package/src/utils/index.js +30 -18
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zen-gitsync",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "一个 git 自动查看差异并提交的工具",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -10,7 +10,9 @@
|
|
|
10
10
|
"g:y:interval": "node ./src/gitCommit.js -y --interval",
|
|
11
11
|
"g:y:interval10": "node ./src/gitCommit.js -y --interval=10",
|
|
12
12
|
"g:cwd": "node ./src/gitCommit.js --path=./",
|
|
13
|
-
"g:no-diff": "node ./src/gitCommit.js --no-diff"
|
|
13
|
+
"g:no-diff": "node ./src/gitCommit.js --no-diff",
|
|
14
|
+
"g:log": "node ./src/gitCommit.js log",
|
|
15
|
+
"g:log5": "node ./src/gitCommit.js log --n=5"
|
|
14
16
|
},
|
|
15
17
|
"files": [
|
|
16
18
|
"src/gitCommit.js",
|
package/src/gitCommit.js
CHANGED
|
@@ -65,6 +65,12 @@ class GitCommit {
|
|
|
65
65
|
try {
|
|
66
66
|
judgePlatform()
|
|
67
67
|
|
|
68
|
+
const logArg = process.argv.find(arg => arg === 'log');
|
|
69
|
+
if (logArg) {
|
|
70
|
+
await this.printGitLog(); // 如果有 log 参数,打印 Git 提交记录
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
68
74
|
this.statusOutput = this.execSyncGitCommand('git status')
|
|
69
75
|
if (this.statusOutput.includes('nothing to commit, working tree clean')) {
|
|
70
76
|
if (this.statusOutput.includes('use "git push')) {
|
|
@@ -77,7 +83,9 @@ class GitCommit {
|
|
|
77
83
|
|
|
78
84
|
const no_diff = process.argv.find(arg => arg.startsWith('--no-diff'))
|
|
79
85
|
if(!no_diff){
|
|
80
|
-
this.execSyncGitCommand('git diff'
|
|
86
|
+
this.execSyncGitCommand('git diff --color=always', {
|
|
87
|
+
head: `git diff`
|
|
88
|
+
})
|
|
81
89
|
}
|
|
82
90
|
|
|
83
91
|
// 检查命令行参数,判断是否有 -y 参数
|
|
@@ -106,6 +114,29 @@ class GitCommit {
|
|
|
106
114
|
console.log(`e ==> `, e)
|
|
107
115
|
}
|
|
108
116
|
}
|
|
117
|
+
async printGitLog() {
|
|
118
|
+
let n = 20;
|
|
119
|
+
let logArg = process.argv.find(arg => arg.startsWith('--n='));
|
|
120
|
+
if (logArg) {
|
|
121
|
+
n = parseInt(logArg.split('=')[1], 10);
|
|
122
|
+
}
|
|
123
|
+
const logCommand = `git log -n ${n} --pretty=format:"%C(green)%h%C(reset) | %C(cyan)%an%C(reset) | %C(yellow)%ad%C(reset) | %C(blue)%D%C(reset) | %C(magenta)%s%C(reset)" --date=format:"%Y-%m-%d %H:%M" --graph --decorate --color`
|
|
124
|
+
try {
|
|
125
|
+
const logOutput = this.execSyncGitCommand(logCommand, {
|
|
126
|
+
head: `git log`
|
|
127
|
+
});
|
|
128
|
+
// // 格式化输出 Git 提交记录
|
|
129
|
+
// const box = boxen(chalk.green.bold(logOutput), {
|
|
130
|
+
// borderStyle: 'round',
|
|
131
|
+
// borderColor: 'cyan',
|
|
132
|
+
// backgroundColor: 'black',
|
|
133
|
+
// });
|
|
134
|
+
// console.log(box); // 打印优雅的 Git 提交记录
|
|
135
|
+
} catch (error) {
|
|
136
|
+
console.error('无法获取 Git 提交记录:', error.message);
|
|
137
|
+
}
|
|
138
|
+
this.exec_exit(); // 打印完成后退出
|
|
139
|
+
}
|
|
109
140
|
|
|
110
141
|
exec_push() {
|
|
111
142
|
// 执行 git push
|
|
@@ -134,14 +165,14 @@ class GitCommit {
|
|
|
134
165
|
|
|
135
166
|
execSyncGitCommand(command, options = {}) {
|
|
136
167
|
try {
|
|
137
|
-
let {encoding = 'utf-8', maxBuffer = 30 * 1024 * 1024} = options
|
|
168
|
+
let {encoding = 'utf-8', maxBuffer = 30 * 1024 * 1024, head = command} = options
|
|
138
169
|
let cwd = getCwd()
|
|
139
170
|
const output = execSync(command, {encoding, maxBuffer, cwd})
|
|
140
171
|
if(options.spinner){
|
|
141
172
|
options.spinner.stop();
|
|
142
173
|
}
|
|
143
174
|
let result = output.trim()
|
|
144
|
-
coloredLog(
|
|
175
|
+
coloredLog(head, result)
|
|
145
176
|
return result
|
|
146
177
|
} catch (e) {
|
|
147
178
|
console.log(`执行命令出错 ==> `, command, e)
|
package/src/utils/index.js
CHANGED
|
@@ -31,7 +31,7 @@ const printTableWithHeaderUnderline = (head, content, style) => {
|
|
|
31
31
|
if (!style) {
|
|
32
32
|
style = {
|
|
33
33
|
// head: ['cyan'], // 表头文字颜色为cyan
|
|
34
|
-
|
|
34
|
+
border: [chalk.reset()], // 边框颜色
|
|
35
35
|
compact: true, // 启用紧凑模式,去掉不必要的空白
|
|
36
36
|
}
|
|
37
37
|
}
|
|
@@ -41,6 +41,23 @@ const printTableWithHeaderUnderline = (head, content, style) => {
|
|
|
41
41
|
colWidths, // 使用动态计算的列宽
|
|
42
42
|
style: style,
|
|
43
43
|
wordWrap: true, // 启用自动换行
|
|
44
|
+
// chars: {
|
|
45
|
+
// 'top': '═', // 顶部边框使用长横线
|
|
46
|
+
// 'top-mid': '╤', // 顶部连接符
|
|
47
|
+
// 'top-left': '╔', // 左上角
|
|
48
|
+
// 'top-right': '╗', // 右上角
|
|
49
|
+
// 'bottom': '═', // 底部边框
|
|
50
|
+
// 'bottom-mid': '╧', // 底部连接符
|
|
51
|
+
// 'bottom-left': '╚',// 左下角
|
|
52
|
+
// 'bottom-right': '╝',// 右下角
|
|
53
|
+
// 'left': '║', // 左边框
|
|
54
|
+
// 'left-mid': '╟', // 左连接符
|
|
55
|
+
// 'mid': '═', // 中间分隔符
|
|
56
|
+
// 'mid-mid': '╪', // 中间连接符
|
|
57
|
+
// 'right': '║', // 右边框
|
|
58
|
+
// 'right-mid': '╢', // 右连接符
|
|
59
|
+
// 'middle': '│' // 中间内容的边界
|
|
60
|
+
// }
|
|
44
61
|
});
|
|
45
62
|
|
|
46
63
|
// 向表格中添加不同颜色的行
|
|
@@ -94,15 +111,15 @@ const calcColor = (commandLine, str) => {
|
|
|
94
111
|
}
|
|
95
112
|
break;
|
|
96
113
|
case 'git diff':
|
|
97
|
-
if (str.startsWith('
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
if (str.startsWith('
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
if (str.startsWith('@@ ')) {
|
|
104
|
-
|
|
105
|
-
}
|
|
114
|
+
// if (str.startsWith('---')) {
|
|
115
|
+
// color = 'red'
|
|
116
|
+
// }
|
|
117
|
+
// if (str.startsWith('+++')) {
|
|
118
|
+
// color = 'green'
|
|
119
|
+
// }
|
|
120
|
+
// if (str.startsWith('@@ ')) {
|
|
121
|
+
// color = 'cyan'
|
|
122
|
+
// }
|
|
106
123
|
break;
|
|
107
124
|
}
|
|
108
125
|
return color
|
|
@@ -112,7 +129,7 @@ const tableLog = (commandLine, content, type) => {
|
|
|
112
129
|
let head = chalk.bold.blue(handle_commandLine)
|
|
113
130
|
let style = {
|
|
114
131
|
// head: ['cyan'], // 表头文字颜色为cyan
|
|
115
|
-
|
|
132
|
+
border: [chalk.reset()], // 边框颜色
|
|
116
133
|
compact: true, // 启用紧凑模式,去掉不必要的空白
|
|
117
134
|
}
|
|
118
135
|
switch (type) {
|
|
@@ -121,7 +138,7 @@ const tableLog = (commandLine, content, type) => {
|
|
|
121
138
|
content = content.toString().split('\n')
|
|
122
139
|
head = chalk.bold.red(handle_commandLine)
|
|
123
140
|
break;
|
|
124
|
-
case '
|
|
141
|
+
case 'common':
|
|
125
142
|
style.head = ['blue'];
|
|
126
143
|
content = content.split('\n')
|
|
127
144
|
break;
|
|
@@ -140,12 +157,7 @@ const coloredLog = (...args) => {
|
|
|
140
157
|
// 获取参数内容
|
|
141
158
|
const commandLine = args[0];
|
|
142
159
|
const content = args[1];
|
|
143
|
-
const type = args[2] || '
|
|
144
|
-
|
|
145
|
-
|
|
160
|
+
const type = args[2] || 'common';
|
|
146
161
|
tableLog(commandLine, content, type);
|
|
147
|
-
|
|
148
|
-
// console.log(`args ==> `, args)
|
|
149
|
-
|
|
150
162
|
}
|
|
151
163
|
export {coloredLog};
|