zen-gitsync 1.3.6 → 1.3.9

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
@@ -28,6 +28,14 @@ $ g
28
28
  ```bash
29
29
  $ g -y
30
30
  ```
31
+ #### 设置默认提交信息:
32
+ ```bash
33
+ $ g --set-default-message="提交"
34
+ ```
35
+ #### 获取默认提交信息:
36
+ ```bash
37
+ $ g get-config
38
+ ```
31
39
  #### 传入message直接提交:
32
40
  ```bash
33
41
  $ g -m <message>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zen-gitsync",
3
- "version": "1.3.6",
3
+ "version": "1.3.9",
4
4
  "description": "一个 git 自动查看差异并提交的工具",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -16,7 +16,9 @@
16
16
  "g:no-diff": "node ./src/gitCommit.js --no-diff",
17
17
  "g:log": "node ./src/gitCommit.js log",
18
18
  "g:log5": "node ./src/gitCommit.js log --n=5",
19
- "g:h": "node ./src/gitCommit.js -h"
19
+ "g:h": "node ./src/gitCommit.js -h",
20
+ "g:get-config": "node ./src/gitCommit.js get-config",
21
+ "g:set-default-message": "node ./src/gitCommit.js --set-default-message=\"提交\""
20
22
  },
21
23
  "files": [
22
24
  "src/*",
package/src/config.js CHANGED
@@ -1,3 +1,30 @@
1
- export default {
2
- "defaultCommitMessage": "submit"
1
+ import { promises as fs } from 'fs';
2
+ import path from 'path';
3
+ import os from 'os';
4
+
5
+ const configPath = path.join(os.homedir(), '.git-commit-tool.json');
6
+
7
+ // 默认配置
8
+ const defaultConfig = {
9
+ defaultCommitMessage: "submit"
10
+ };
11
+
12
+ // 异步读取配置文件
13
+ async function loadConfig() {
14
+ try {
15
+ const data = await fs.readFile(configPath, 'utf-8');
16
+ return { ...defaultConfig, ...JSON.parse(data) };
17
+ } catch (error) {
18
+ return defaultConfig;
19
+ }
20
+ }
21
+
22
+ // 异步保存配置
23
+ async function saveConfig(config) {
24
+ await fs.writeFile(configPath, JSON.stringify(config, null, 2), 'utf-8');
3
25
  }
26
+
27
+ export default {
28
+ loadConfig,
29
+ saveConfig
30
+ };
package/src/gitCommit.js CHANGED
@@ -7,8 +7,8 @@ import readline from 'readline'
7
7
  import ora from 'ora';
8
8
  import chalk from 'chalk';
9
9
  import boxen from 'boxen';
10
- import config from './config.js'
11
-
10
+ import config from './config.js';
11
+ const { loadConfig, saveConfig } = config;
12
12
  const {defaultCommitMessage} = config
13
13
 
14
14
  let timer = null
@@ -17,16 +17,18 @@ const showHelp = () => {
17
17
  Usage: g [options]
18
18
 
19
19
  Options:
20
- -h, --help Show this help message
21
- -y Auto commit with default message
22
- -m <message> Commit message (use quotes if message contains spaces)
23
- -m=<message> Commit message (use this form without spaces around '=')
24
- --path=<path> Set custom working directory
25
- --cwd=<path> Set custom working directory
26
- --interval=<seconds> Set interval time for automatic commits (in seconds)
27
- log Show git commit logs
28
- --n=<number> Number of commits to show with --log
29
- --no-diff Skip displaying git diff
20
+ -h, --help Show this help message
21
+ --set-default-message=<msg> Set default commit message
22
+ get-config Show current configuration
23
+ -y Auto commit with default message
24
+ -m <message> Commit message (use quotes if message contains spaces)
25
+ -m=<message> Commit message (use this form without spaces around '=')
26
+ --path=<path> Set custom working directory
27
+ --cwd=<path> Set custom working directory
28
+ --interval=<seconds> Set interval time for automatic commits (in seconds)
29
+ log Show git commit logs
30
+ --n=<number> Number of commits to show with --log
31
+ --no-diff Skip displaying git diff
30
32
 
31
33
  Example:
32
34
  g -m "Initial commit" Commit with a custom message
@@ -49,7 +51,25 @@ Start a background process for automatic commits:
49
51
  console.log(helpMessage);
50
52
  process.exit();
51
53
  };
54
+ // 添加配置管理函数
55
+ async function handleConfigCommands() {
56
+ if (process.argv.includes('get-config')) {
57
+ const currentConfig = await loadConfig();
58
+ console.log('Current configuration:');
59
+ console.log(currentConfig);
60
+ process.exit();
61
+ }
52
62
 
63
+ const setMsgArg = process.argv.find(arg => arg.startsWith('--set-default-message='));
64
+ if (setMsgArg) {
65
+ const newMessage = setMsgArg.split('=')[1];
66
+ const currentConfig = await loadConfig();
67
+ currentConfig.defaultCommitMessage = newMessage;
68
+ await saveConfig(currentConfig);
69
+ console.log(chalk.green(`✓ 默认提交信息已设置为: "${newMessage}"`));
70
+ process.exit();
71
+ }
72
+ }
53
73
  const judgePlatform = () => {
54
74
  // 判断是否是 Windows 系统
55
75
  if (os.platform() === 'win32') {
@@ -91,8 +111,11 @@ class GitCommit {
91
111
  constructor(options) {
92
112
  this.statusOutput = null
93
113
  this.exit = options.exit
94
- this.commitMessage = defaultCommitMessage
95
- this.init()
114
+ // 从配置加载默认提交信息
115
+ loadConfig().then(config => {
116
+ this.commitMessage = config.defaultCommitMessage;
117
+ this.init();
118
+ });
96
119
  }
97
120
 
98
121
  exec_exit() {
@@ -323,7 +346,7 @@ class GitCommit {
323
346
  let {encoding = 'utf-8', maxBuffer = 30 * 1024 * 1024, head = command, log = true} = options
324
347
  try {
325
348
  let cwd = getCwd()
326
- const output = execSync(command, {encoding, maxBuffer, cwd})
349
+ const output = execSync(command, {env: { ...process.env, LANG: 'C.UTF-8' },encoding, maxBuffer, cwd})
327
350
  if (options.spinner) {
328
351
  options.spinner.stop();
329
352
  }
@@ -341,7 +364,7 @@ class GitCommit {
341
364
  return new Promise((resolve, reject) => {
342
365
  let {encoding = 'utf-8', maxBuffer = 30 * 1024 * 1024, head = command, log = true} = options
343
366
  let cwd = getCwd()
344
- exec(command, {encoding, maxBuffer, cwd}, (error, stdout, stderr) => {
367
+ exec(command, {env: { ...process.env, LANG: 'C.UTF-8' },encoding, maxBuffer, cwd}, (error, stdout, stderr) => {
345
368
  if (options.spinner) {
346
369
  options.spinner.stop();
347
370
  }
@@ -365,7 +388,11 @@ class GitCommit {
365
388
  })
366
389
  }
367
390
  }
368
-
391
+ // 在 judgeInterval 函数前添加配置命令处理
392
+ async function main() {
393
+ await handleConfigCommands();
394
+ judgeInterval();
395
+ }
369
396
  const judgeInterval = () => {
370
397
  // 判断是否有 --interval 参数
371
398
  const intervalArg = process.argv.find(arg => arg.startsWith('--interval'));
@@ -400,4 +427,4 @@ const judgeInterval = () => {
400
427
  }
401
428
  };
402
429
 
403
- judgeInterval()
430
+ main()