zen-gitsync 1.2.3 → 1.2.5

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 CHANGED
@@ -26,17 +26,25 @@ npm install -g zen-gitsync
26
26
  - `git push`
27
27
 
28
28
  ### 示例:
29
-
29
+ #### 交互式提交:
30
30
  ```bash
31
31
  $ g
32
32
  请输入你的提交信息: 修复了登录页样式问题
33
33
  ```
34
- 直接提交
34
+ #### 直接提交:
35
35
  ```bash
36
36
  $ g -y
37
37
  ```
38
- 定时执行自动提交,默认间隔1小时
38
+ #### 定时执行自动提交,默认间隔1小时
39
39
  ```bash
40
40
  $ g -y --interval
41
41
  $ g -y --interval=秒数
42
42
  ```
43
+ #### 指定目录提交
44
+ ```bash
45
+ $ g --path=./
46
+ ```
47
+
48
+ ```bash
49
+ $ g --cwd=./
50
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zen-gitsync",
3
- "version": "1.2.3",
3
+ "version": "1.2.5",
4
4
  "description": "控制台输入g,回车,输入提交内容,自动执行git add+commit+push",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -8,7 +8,8 @@
8
8
  "g": "node ./src/gitCommit.js",
9
9
  "g:y": "node ./src/gitCommit.js -y",
10
10
  "g:y:interval": "node ./src/gitCommit.js -y --interval",
11
- "g:y:interval10": "node ./src/gitCommit.js -y --interval=10"
11
+ "g:y:interval10": "node ./src/gitCommit.js -y --interval=10",
12
+ "g:cwd": "node ./src/gitCommit.js --path=./"
12
13
  },
13
14
  "files": [
14
15
  "src/gitCommit.js",
package/src/gitCommit.js CHANGED
@@ -18,6 +18,16 @@ const judgePlatform = () => {
18
18
  }
19
19
  }
20
20
  };
21
+ const getCwd = () => {
22
+ const cwdArg = process.argv.find(arg => arg.startsWith('--path')) || process.argv.find(arg => arg.startsWith('--cwd'));
23
+ if (cwdArg) {
24
+ // console.log(`cwdArg ==> `, cwdArg)
25
+ const [, value] = cwdArg.split('=')
26
+ // console.log(`value ==> `, value)
27
+ return value || process.cwd()
28
+ }
29
+ return process.cwd()
30
+ }
21
31
 
22
32
  // 有时候有乱码呢123神奇
23
33
 
@@ -72,7 +82,7 @@ class GitCommit {
72
82
  }
73
83
 
74
84
  // 执行 git add .
75
- this.statusOutput.includes('(use "git add <file>') && this.execSyncGitCommand('git add .')
85
+ this.statusOutput.includes('(use "git add') && this.execSyncGitCommand('git add .')
76
86
 
77
87
  // 执行 git commit
78
88
  if (this.statusOutput.includes('Untracked files:') || this.statusOutput.includes('Changes not staged for commit') || this.statusOutput.includes('Changes to be committed')) {
@@ -102,8 +112,8 @@ class GitCommit {
102
112
 
103
113
  execSyncGitCommand(command, options = {}) {
104
114
  try {
105
- let {encoding = 'utf-8', maxBuffer = 30 * 1024 * 1024, cwd = process.cwd()} = options
106
- // cwd = process.argv[2] || cwd
115
+ let {encoding = 'utf-8', maxBuffer = 30 * 1024 * 1024} = options
116
+ let cwd = getCwd()
107
117
  const output = execSync(command, {encoding, maxBuffer, cwd})
108
118
  let result = output.trim()
109
119
  coloredLog(command, result)
@@ -115,8 +125,8 @@ class GitCommit {
115
125
  }
116
126
 
117
127
  execGitCommand(command, options = {}, callback) {
118
- let {encoding = 'utf-8', maxBuffer = 30 * 1024 * 1024, cwd = process.cwd()} = options
119
- // cwd = process.argv[2] || cwd
128
+ let {encoding = 'utf-8', maxBuffer = 30 * 1024 * 1024} = options
129
+ let cwd = getCwd()
120
130
  exec(command, {encoding, maxBuffer, cwd}, (error, stdout, stderr) => {
121
131
  if (error) {
122
132
  coloredLog(command, error)
@@ -34,7 +34,8 @@ function getRandomColor() {
34
34
  function resetColor() {
35
35
  return '\x1b[0m';
36
36
  }
37
- const coloredLog = (...args) =>{
37
+
38
+ const coloredLog = (...args) => {
38
39
  const color = getRandomColor();
39
40
  // 获取控制台的宽度
40
41
  const terminalWidth = process.stdout.columns;
@@ -43,8 +44,8 @@ const coloredLog = (...args) =>{
43
44
  // const line = '-'.repeat(terminalWidth);
44
45
  let str = '├─'
45
46
  let str2 = '│'
46
- const start_line = '┌' + '──'.repeat(terminalWidth / 2 - 1) + '┐';
47
- const end_line = '└' + '──'.repeat(terminalWidth / 2 - 1) + '┘';
47
+ const start_line = '┌' + ''.repeat(terminalWidth - 2) + '┐';
48
+ const end_line = '└' + ''.repeat(terminalWidth - 2) + '┘';
48
49
  let _args = args.map(arg => arg.split('\n')).flat().filter(arg => arg.trim() !== '');
49
50
  console.log(start_line);
50
51
  _args.map(async (arg, i) => {
@@ -62,34 +63,45 @@ const coloredLog = (...args) =>{
62
63
  if (_args[0] === 'git status' && trim_arg.startsWith('modified:')) {
63
64
  _color = '\x1b[32m';
64
65
  }
66
+ if (_args[0] === 'git status' && trim_arg.startsWith('deleted:')) {
67
+ _color = '\x1b[31m';
68
+ }
65
69
  if (_args[0] === 'git diff' && arg.startsWith('@@ ')) {
66
70
  _color = '\x1b[36m';
67
71
  }
68
72
  // 测试边框
69
73
  let fix_end = ''
70
74
  let length = stringWidth(arg);
71
- if (length < terminalWidth) {
75
+ // if (length < terminalWidth) {
72
76
  let fix2 = 0
73
- if(trim_arg.startsWith('modified:')){
77
+ if (
78
+ _args[0] === 'git status' && trim_arg.startsWith('modified:')
79
+ || _args[0] === 'git status' && trim_arg.startsWith('deleted:')
80
+ ) {
74
81
  fix2 = 6
75
82
  }
76
83
  if (i === 0) {
77
84
  fix2 = 2
78
85
  }
79
- fix_end = ' '.repeat(terminalWidth - length - 4 - fix2)
86
+ let repeatLen = terminalWidth - length - 3 - fix2
87
+ if (repeatLen < 0) {
88
+ // repeatLen += terminalWidth
89
+ repeatLen = repeatLen % terminalWidth + terminalWidth
90
+ }
91
+ fix_end = ' '.repeat(repeatLen)
80
92
  fix_end += "│"
81
- }
93
+ // }
82
94
  // console.log(`fix_end ==> `, fix_end)
83
95
  if (i === 0) {
84
96
  console.log(`│ \x1b[1m\x1b[34m> ${arg}\x1b[22m\x1b[39m${fix_end}`);
85
- let mid = '├─' + '──'.repeat(terminalWidth / 2 - 2) + '─┤';
97
+ let mid = '' + ''.repeat(terminalWidth - 2) + '';
86
98
  console.log(mid);
87
99
  } else {
88
- if(arg.trim().length > 0) {
100
+ if (arg.trim().length > 0) {
89
101
  console.log(`│${_color} ${arg}${resetColor()}${fix_end}`);
90
102
  }
91
103
  }
92
104
  });
93
105
  console.log(end_line);
94
106
  }
95
- export { coloredLog };
107
+ export {coloredLog};