zen-gitsync 1.2.5 → 1.2.8
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 +14 -0
- package/package.json +5 -1
- package/src/gitCommit.js +23 -2
- package/src/utils/index.js +35 -4
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zen-gitsync",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.8",
|
|
4
4
|
"description": "控制台输入g,回车,输入提交内容,自动执行git add+commit+push",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -31,6 +31,10 @@
|
|
|
31
31
|
},
|
|
32
32
|
"homepage": "https://github.com/xz333221/zen-gitsync#readme",
|
|
33
33
|
"dependencies": {
|
|
34
|
+
"boxen": "^8.0.1",
|
|
35
|
+
"chalk": "^5.4.1",
|
|
36
|
+
"cli-table3": "^0.6.5",
|
|
37
|
+
"ora": "^8.1.1",
|
|
34
38
|
"string-width": "^7.2.0"
|
|
35
39
|
}
|
|
36
40
|
}
|
package/src/gitCommit.js
CHANGED
|
@@ -4,6 +4,9 @@ import {exec, execSync} from 'child_process'
|
|
|
4
4
|
import os from 'os'
|
|
5
5
|
import {coloredLog} from './utils/index.js';
|
|
6
6
|
import readline from 'readline'
|
|
7
|
+
import ora from 'ora';
|
|
8
|
+
import chalk from 'chalk';
|
|
9
|
+
import boxen from 'boxen';
|
|
7
10
|
|
|
8
11
|
let timer = null
|
|
9
12
|
|
|
@@ -103,8 +106,20 @@ class GitCommit {
|
|
|
103
106
|
exec_push() {
|
|
104
107
|
// 执行 git push
|
|
105
108
|
// this.execSyncGitCommand(`git push`);
|
|
106
|
-
|
|
107
|
-
|
|
109
|
+
const spinner = ora('正在推送代码...').start();
|
|
110
|
+
this.execGitCommand('git push', {
|
|
111
|
+
spinner
|
|
112
|
+
}, (error, stdout, stderr) => {
|
|
113
|
+
|
|
114
|
+
// 使用 boxen 绘制带边框的消息
|
|
115
|
+
const message = chalk.green.bold(' SUCCESS: 提交完成 ');
|
|
116
|
+
const box = boxen(message, {
|
|
117
|
+
// borderStyle: 'round', // 方框的样式
|
|
118
|
+
// borderColor: 'whiteBright', // 边框颜色
|
|
119
|
+
// backgroundColor: 'black', // 背景颜色
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
console.log(box); // 打印带有边框的消息
|
|
108
123
|
this.execSyncGitCommand(`git log -n 1 --pretty=format:"%B%n%h %d%n%ad" --date=iso`)
|
|
109
124
|
this.exec_exit();
|
|
110
125
|
})
|
|
@@ -115,6 +130,9 @@ class GitCommit {
|
|
|
115
130
|
let {encoding = 'utf-8', maxBuffer = 30 * 1024 * 1024} = options
|
|
116
131
|
let cwd = getCwd()
|
|
117
132
|
const output = execSync(command, {encoding, maxBuffer, cwd})
|
|
133
|
+
if(options.spinner){
|
|
134
|
+
options.spinner.stop();
|
|
135
|
+
}
|
|
118
136
|
let result = output.trim()
|
|
119
137
|
coloredLog(command, result)
|
|
120
138
|
return result
|
|
@@ -128,6 +146,9 @@ class GitCommit {
|
|
|
128
146
|
let {encoding = 'utf-8', maxBuffer = 30 * 1024 * 1024} = options
|
|
129
147
|
let cwd = getCwd()
|
|
130
148
|
exec(command, {encoding, maxBuffer, cwd}, (error, stdout, stderr) => {
|
|
149
|
+
if(options.spinner){
|
|
150
|
+
options.spinner.stop();
|
|
151
|
+
}
|
|
131
152
|
if (error) {
|
|
132
153
|
coloredLog(command, error)
|
|
133
154
|
return
|
package/src/utils/index.js
CHANGED
|
@@ -15,6 +15,40 @@
|
|
|
15
15
|
// const boxedMessage = boxen(message, options);
|
|
16
16
|
// console.log(boxedMessage);
|
|
17
17
|
import stringWidth from 'string-width';
|
|
18
|
+
import Table from 'cli-table3';
|
|
19
|
+
import chalk from 'chalk';
|
|
20
|
+
|
|
21
|
+
const printTableWithHeaderUnderline = () => {
|
|
22
|
+
// 获取终端的列数(宽度)
|
|
23
|
+
const terminalWidth = process.stdout.columns;
|
|
24
|
+
|
|
25
|
+
// 计算表格的宽度,保证至少有 2 个字符留给边框
|
|
26
|
+
const tableWidth = terminalWidth - 4; // 4 是左右边框和分隔符的宽度
|
|
27
|
+
|
|
28
|
+
// 计算每列的宽度
|
|
29
|
+
const colWidths = [tableWidth]; // 只有一列,因此宽度设置为终端宽度
|
|
30
|
+
|
|
31
|
+
const table = new Table({
|
|
32
|
+
head: ['Name'], // 只有一个表头
|
|
33
|
+
colWidths, // 使用动态计算的列宽
|
|
34
|
+
style: {
|
|
35
|
+
head: ['cyan'], // 表头文字颜色为cyan
|
|
36
|
+
border: ['yellow'], // 边框颜色为黄色
|
|
37
|
+
compact: true, // 启用紧凑模式,去掉不必要的空白
|
|
38
|
+
},
|
|
39
|
+
wordWrap: true, // 启用自动换行
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// 向表格中添加不同颜色的行
|
|
43
|
+
table.push(
|
|
44
|
+
[chalk.red('张三张三张三张三张三张三张三张三张三张三张三张三张三张三张三张三张三张三张三张三张三张三张三张三张三张三张三张三张三张三张三张三')],
|
|
45
|
+
[chalk.green('李四')],
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
console.log(table.toString()); // 输出表格
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// printTableWithHeaderUnderline();
|
|
18
52
|
|
|
19
53
|
const colors = [
|
|
20
54
|
'\x1b[31m', // 红色
|
|
@@ -40,10 +74,6 @@ const coloredLog = (...args) => {
|
|
|
40
74
|
// 获取控制台的宽度
|
|
41
75
|
const terminalWidth = process.stdout.columns;
|
|
42
76
|
|
|
43
|
-
// 创建与控制台宽度相同的横线
|
|
44
|
-
// const line = '-'.repeat(terminalWidth);
|
|
45
|
-
let str = '├─'
|
|
46
|
-
let str2 = '│'
|
|
47
77
|
const start_line = '┌' + '─'.repeat(terminalWidth - 2) + '┐';
|
|
48
78
|
const end_line = '└' + '─'.repeat(terminalWidth - 2) + '┘';
|
|
49
79
|
let _args = args.map(arg => arg.split('\n')).flat().filter(arg => arg.trim() !== '');
|
|
@@ -77,6 +107,7 @@ const coloredLog = (...args) => {
|
|
|
77
107
|
if (
|
|
78
108
|
_args[0] === 'git status' && trim_arg.startsWith('modified:')
|
|
79
109
|
|| _args[0] === 'git status' && trim_arg.startsWith('deleted:')
|
|
110
|
+
|| _args[0] === 'git status' && trim_arg.startsWith('new file:')
|
|
80
111
|
) {
|
|
81
112
|
fix2 = 6
|
|
82
113
|
}
|