zen-gitsync 1.0.3 → 1.2.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/LICENSE +21 -21
- package/README.md +36 -36
- package/package.json +12 -4
- package/src/gitCommit.js +119 -121
- package/src/utils/index.js +91 -0
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 xz333221
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 xz333221
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
# zen-gitsync
|
|
3
|
-
|
|
4
|
-
`zen-gitsync` 是一个简单的命令行工具,用于自动化 Git 提交和推送操作。只需在控制台输入 `g`,即可自动执行 `git add`、`git commit` 和 `git push` 操作,极大提升 Git 工作流程的效率。
|
|
5
|
-
|
|
6
|
-
## 特性
|
|
7
|
-
|
|
8
|
-
- 一键执行 `git add`、`git commit`、`git push`
|
|
9
|
-
- 使用交互式命令行输入提交信息
|
|
10
|
-
- 提交信息颜色随机显示
|
|
11
|
-
|
|
12
|
-
## 安装
|
|
13
|
-
|
|
14
|
-
通过 npm 安装 `zen-gitsync`,并进行全局安装:
|
|
15
|
-
|
|
16
|
-
```bash
|
|
17
|
-
npm install -g zen-gitsync
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
## 使用方法
|
|
21
|
-
|
|
22
|
-
1. 在终端中,输入 `g` 并按回车。
|
|
23
|
-
2. 输入提交信息,按回车确认提交。
|
|
24
|
-
3. 工具将自动执行以下操作:
|
|
25
|
-
- `git add .`
|
|
26
|
-
- `git commit -m "你的提交信息"`
|
|
27
|
-
- `git push`
|
|
28
|
-
|
|
29
|
-
### 示例:
|
|
30
|
-
|
|
31
|
-
```bash
|
|
32
|
-
$ g
|
|
33
|
-
请输入你的提交信息: 修复了登录页样式问题
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
完成提交后,你会看到一个随机颜色的提交信息确认
|
|
1
|
+
|
|
2
|
+
# zen-gitsync
|
|
3
|
+
|
|
4
|
+
`zen-gitsync` 是一个简单的命令行工具,用于自动化 Git 提交和推送操作。只需在控制台输入 `g`,即可自动执行 `git add`、`git commit` 和 `git push` 操作,极大提升 Git 工作流程的效率。
|
|
5
|
+
|
|
6
|
+
## 特性
|
|
7
|
+
|
|
8
|
+
- 一键执行 `git add`、`git commit`、`git push`
|
|
9
|
+
- 使用交互式命令行输入提交信息
|
|
10
|
+
- 提交信息颜色随机显示
|
|
11
|
+
|
|
12
|
+
## 安装
|
|
13
|
+
|
|
14
|
+
通过 npm 安装 `zen-gitsync`,并进行全局安装:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install -g zen-gitsync
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## 使用方法
|
|
21
|
+
|
|
22
|
+
1. 在终端中,输入 `g` 并按回车。
|
|
23
|
+
2. 输入提交信息,按回车确认提交。
|
|
24
|
+
3. 工具将自动执行以下操作:
|
|
25
|
+
- `git add .`
|
|
26
|
+
- `git commit -m "你的提交信息"`
|
|
27
|
+
- `git push`
|
|
28
|
+
|
|
29
|
+
### 示例:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
$ g
|
|
33
|
+
请输入你的提交信息: 修复了登录页样式问题
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
完成提交后,你会看到一个随机颜色的提交信息确认
|
package/package.json
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zen-gitsync",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "控制台输入g,回车,输入提交内容,自动执行git add+commit+push",
|
|
5
5
|
"main": "index.js",
|
|
6
|
+
"type": "module",
|
|
6
7
|
"scripts": {
|
|
7
|
-
"g": "node ./src/gitCommit.js"
|
|
8
|
+
"g": "node ./src/gitCommit.js",
|
|
9
|
+
"g:y": "node ./src/gitCommit.js -y"
|
|
8
10
|
},
|
|
9
11
|
"files": [
|
|
10
12
|
"src/gitCommit.js",
|
|
13
|
+
"src/utils/index.js",
|
|
11
14
|
"package.json"
|
|
12
15
|
],
|
|
13
|
-
"bin": {
|
|
16
|
+
"bin": {
|
|
17
|
+
"g": "./src/gitCommit.js"
|
|
18
|
+
},
|
|
14
19
|
"repository": {
|
|
15
20
|
"type": "git",
|
|
16
21
|
"url": "git+https://github.com/xz333221/zen-gitsync.git"
|
|
@@ -21,5 +26,8 @@
|
|
|
21
26
|
"bugs": {
|
|
22
27
|
"url": "https://github.com/xz333221/zen-gitsync/issues"
|
|
23
28
|
},
|
|
24
|
-
"homepage": "https://github.com/xz333221/zen-gitsync#readme"
|
|
29
|
+
"homepage": "https://github.com/xz333221/zen-gitsync#readme",
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"string-width": "^7.2.0"
|
|
32
|
+
}
|
|
25
33
|
}
|
package/src/gitCommit.js
CHANGED
|
@@ -1,121 +1,119 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
new GitCommit()
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import {exec, execSync} from 'child_process'
|
|
4
|
+
import os from 'os'
|
|
5
|
+
import { coloredLog } from './utils/index.js';
|
|
6
|
+
import readline from 'readline'
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
const judgePlatform = () => {
|
|
10
|
+
// 判断是否是 Windows 系统
|
|
11
|
+
if (os.platform() === 'win32') {
|
|
12
|
+
try {
|
|
13
|
+
// 设置终端字符编码为 UTF-8
|
|
14
|
+
execSync('chcp 65001');
|
|
15
|
+
} catch (e) {
|
|
16
|
+
console.error('设置字符编码失败:', e.message);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// 有时候有乱码呢123神奇
|
|
22
|
+
|
|
23
|
+
const rl = readline.createInterface({
|
|
24
|
+
input: process.stdin,
|
|
25
|
+
output: process.stdout
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
function rlPromisify(fn) {
|
|
29
|
+
return async (...args) => {
|
|
30
|
+
return new Promise((resolve, reject) => fn(...args, resolve, reject))
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const question = rlPromisify(rl.question.bind(rl))
|
|
35
|
+
|
|
36
|
+
class GitCommit {
|
|
37
|
+
constructor() {
|
|
38
|
+
this.statusOutput = null
|
|
39
|
+
this.init()
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async init() {
|
|
43
|
+
try {
|
|
44
|
+
judgePlatform()
|
|
45
|
+
|
|
46
|
+
this.statusOutput = this.execSyncGitCommand('git status')
|
|
47
|
+
if (this.statusOutput.includes('nothing to commit, working tree clean')) {
|
|
48
|
+
process.exit();
|
|
49
|
+
return
|
|
50
|
+
}
|
|
51
|
+
this.execSyncGitCommand('git diff')
|
|
52
|
+
|
|
53
|
+
// 检查命令行参数,判断是否有 -y 参数
|
|
54
|
+
const autoCommit = process.argv.includes('-y');
|
|
55
|
+
let commitMessage = '提交'; // 默认提交信息
|
|
56
|
+
|
|
57
|
+
if (!autoCommit) {
|
|
58
|
+
// 如果没有 -y 参数,则等待用户输入提交信息
|
|
59
|
+
commitMessage = await question('请输入提交信息:');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// 执行 git add .
|
|
63
|
+
this.statusOutput.includes('(use "git add <file>') && this.execSyncGitCommand('git add .')
|
|
64
|
+
|
|
65
|
+
// 执行 git commit
|
|
66
|
+
if (this.statusOutput.includes('Untracked files:') || this.statusOutput.includes('Changes not staged for commit') || this.statusOutput.includes('Changes to be committed')) {
|
|
67
|
+
this.execSyncGitCommand(`git commit -m "${commitMessage || '提交'}"`)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
// 检查是否需要拉取更新
|
|
72
|
+
this.statusOutput.includes('use "git pull') && this.execSyncGitCommand('git pull')
|
|
73
|
+
|
|
74
|
+
// 执行 git push
|
|
75
|
+
// this.execSyncGitCommand(`git push`);
|
|
76
|
+
this.execGitCommand('git push', {}, (error, stdout, stderr) => {
|
|
77
|
+
console.log('提交完成。')
|
|
78
|
+
this.execSyncGitCommand(`git log -n 1 --pretty=format:"%H %d %ad%n%B" --date=iso`)
|
|
79
|
+
process.exit();
|
|
80
|
+
})
|
|
81
|
+
} catch (e) {
|
|
82
|
+
console.log(`e ==> `, e)
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
execSyncGitCommand(command, options = {}) {
|
|
87
|
+
try {
|
|
88
|
+
let {encoding = 'utf-8', maxBuffer = 30 * 1024 * 1024, cwd = process.cwd()} = options
|
|
89
|
+
// cwd = process.argv[2] || cwd
|
|
90
|
+
const output = execSync(command, {encoding, maxBuffer, cwd})
|
|
91
|
+
let result = output.trim()
|
|
92
|
+
coloredLog(command, result)
|
|
93
|
+
return result
|
|
94
|
+
} catch (e) {
|
|
95
|
+
console.log(`执行命令出错 ==> `, command, e)
|
|
96
|
+
throw new Error(e)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
execGitCommand(command, options = {}, callback) {
|
|
101
|
+
let {encoding = 'utf-8', maxBuffer = 30 * 1024 * 1024, cwd = process.cwd()} = options
|
|
102
|
+
// cwd = process.argv[2] || cwd
|
|
103
|
+
exec(command, {encoding, maxBuffer, cwd}, (error, stdout, stderr) => {
|
|
104
|
+
if (error) {
|
|
105
|
+
coloredLog(command, error)
|
|
106
|
+
return
|
|
107
|
+
}
|
|
108
|
+
if (stdout) {
|
|
109
|
+
coloredLog(command, stdout)
|
|
110
|
+
}
|
|
111
|
+
if (stderr) {
|
|
112
|
+
coloredLog(command, stderr)
|
|
113
|
+
}
|
|
114
|
+
callback && callback(error, stdout, stderr)
|
|
115
|
+
})
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
new GitCommit()
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// const chalk = require('chalk');
|
|
2
|
+
// const boxen = require('boxen');
|
|
3
|
+
// const message = chalk.blue('git diff') + '\n' +
|
|
4
|
+
// chalk.red('- line1') + '\n' +
|
|
5
|
+
// chalk.green('+ line2') + '\n' +
|
|
6
|
+
// chalk.cyan('@@ line diff @@');
|
|
7
|
+
//
|
|
8
|
+
// const options = {
|
|
9
|
+
// padding: 1,
|
|
10
|
+
// margin: 1,
|
|
11
|
+
// borderStyle: 'round', // 可以选择 'single', 'double', 'round' 等边框样式
|
|
12
|
+
// borderColor: 'yellow'
|
|
13
|
+
// };
|
|
14
|
+
//
|
|
15
|
+
// const boxedMessage = boxen(message, options);
|
|
16
|
+
// console.log(boxedMessage);
|
|
17
|
+
import stringWidth from 'string-width';
|
|
18
|
+
|
|
19
|
+
const colors = [
|
|
20
|
+
'\x1b[31m', // 红色
|
|
21
|
+
'\x1b[32m', // 绿色
|
|
22
|
+
'\x1b[33m', // 黄色
|
|
23
|
+
'\x1b[34m', // 蓝色
|
|
24
|
+
'\x1b[35m', // 紫色
|
|
25
|
+
'\x1b[36m', // 青色
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
function getRandomColor() {
|
|
29
|
+
return `\x1b[0m`;
|
|
30
|
+
// const randomIndex = Math.floor(Math.random() * colors.length);
|
|
31
|
+
// return colors[randomIndex];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function resetColor() {
|
|
35
|
+
return '\x1b[0m';
|
|
36
|
+
}
|
|
37
|
+
const coloredLog = (...args) =>{
|
|
38
|
+
const color = getRandomColor();
|
|
39
|
+
// 获取控制台的宽度
|
|
40
|
+
const terminalWidth = process.stdout.columns;
|
|
41
|
+
|
|
42
|
+
// 创建与控制台宽度相同的横线
|
|
43
|
+
// const line = '-'.repeat(terminalWidth);
|
|
44
|
+
const start_line = '┌' + '——'.repeat(terminalWidth / 2 - 1) + '┐';
|
|
45
|
+
const end_line = '└' + '——'.repeat(terminalWidth / 2 - 1) + '┘';
|
|
46
|
+
let _args = args.map(arg => arg.split('\n')).flat().filter(arg => arg.trim() !== '');
|
|
47
|
+
console.log(start_line);
|
|
48
|
+
_args.map(async (arg, i) => {
|
|
49
|
+
let _color = color;
|
|
50
|
+
let trim_arg = arg.trim();
|
|
51
|
+
if (_args[0] === 'git diff' && arg.startsWith('-')) {
|
|
52
|
+
_color = '\x1b[31m';
|
|
53
|
+
}
|
|
54
|
+
if (_args[0] === 'git status' && trim_arg.startsWith('new file:')) {
|
|
55
|
+
_color = '\x1b[31m';
|
|
56
|
+
}
|
|
57
|
+
if (_args[0] === 'git diff' && arg.startsWith('+')) {
|
|
58
|
+
_color = '\x1b[32m';
|
|
59
|
+
}
|
|
60
|
+
if (_args[0] === 'git status' && trim_arg.startsWith('modified:')) {
|
|
61
|
+
_color = '\x1b[32m';
|
|
62
|
+
}
|
|
63
|
+
if (_args[0] === 'git diff' && arg.startsWith('@@ ')) {
|
|
64
|
+
_color = '\x1b[36m';
|
|
65
|
+
}
|
|
66
|
+
// 测试边框
|
|
67
|
+
let fix_end = ''
|
|
68
|
+
let length = stringWidth(arg);
|
|
69
|
+
if (length < terminalWidth) {
|
|
70
|
+
let fix2 = 0
|
|
71
|
+
if(trim_arg.startsWith('modified:')){
|
|
72
|
+
fix2 = 6
|
|
73
|
+
}
|
|
74
|
+
if (i === 0) {
|
|
75
|
+
fix2 = 2
|
|
76
|
+
}
|
|
77
|
+
fix_end = ' '.repeat(terminalWidth - length - 4 - fix2)
|
|
78
|
+
fix_end += "|"
|
|
79
|
+
}
|
|
80
|
+
// console.log(`fix_end ==> `, fix_end)
|
|
81
|
+
if (i === 0) {
|
|
82
|
+
console.log(`| \x1b[1m\x1b[34m> ${arg}\x1b[22m\x1b[39m${fix_end}`);
|
|
83
|
+
} else {
|
|
84
|
+
if(arg.trim().length > 0) {
|
|
85
|
+
console.log(`|${_color} ${arg}${fix_end}`, resetColor());
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
console.log(end_line);
|
|
90
|
+
}
|
|
91
|
+
export { coloredLog };
|