zen-gitsync 2.1.27 → 2.1.30

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
@@ -47,6 +47,21 @@ $ g -h
47
47
  $ g --help
48
48
  ```
49
49
 
50
+ #### 文件锁定功能
51
+ ```shell
52
+ # 锁定文件(锁定后的文件不会被包含在提交中)
53
+ $ g --lock-file=config.json
54
+
55
+ # 解锁文件
56
+ $ g --unlock-file=config.json
57
+
58
+ # 查看所有锁定的文件
59
+ $ g --list-locked
60
+
61
+ # 检查文件是否被锁定
62
+ $ g --check-lock=config.json
63
+ ```
64
+
50
65
  #### 定时执行自动提交,默认间隔1小时
51
66
  ```bash
52
67
  $ g -y --interval
@@ -100,3 +115,33 @@ $ g log --n=5
100
115
  ```shell
101
116
  $ g ui
102
117
  ```
118
+
119
+ ## 🔒 文件锁定功能
120
+
121
+ 文件锁定功能允许您临时排除某些文件不被包含在 Git 提交中,而无需修改 `.gitignore` 文件。这对于以下场景特别有用:
122
+
123
+ - 临时排除配置文件(如包含敏感信息的配置)
124
+ - 跳过正在开发中的实验性文件
125
+ - 避免提交临时的调试文件
126
+
127
+ ### 特点:
128
+ - ✅ 不修改 `.gitignore` 文件
129
+ - ✅ 支持命令行和 Web UI 操作
130
+ - ✅ 锁定状态持久保存
131
+ - ✅ 支持相对路径和绝对路径
132
+ - ✅ 自动跳过锁定文件,显示清晰的提示信息
133
+
134
+ ### 使用场景示例:
135
+ ```shell
136
+ # 锁定配置文件,避免提交敏感信息
137
+ $ g --lock-file=.env
138
+
139
+ # 锁定正在开发的功能文件
140
+ $ g --lock-file=src/experimental-feature.js
141
+
142
+ # 查看当前锁定的文件
143
+ $ g --list-locked
144
+
145
+ # 开发完成后解锁文件
146
+ $ g --unlock-file=src/experimental-feature.js
147
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zen-gitsync",
3
- "version": "2.1.27",
3
+ "version": "2.1.30",
4
4
  "description": "一个 git 自动查看差异并提交的工具",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -26,8 +26,8 @@
26
26
  "g:test-cmd": "node ./src/gitCommit.js --cmd=\"echo zen-gitsync test\" --cmd-interval=5",
27
27
  "g:test-cmd-at": "node ./src/gitCommit.js --cmd=\"echo at-time-test\" --at=21:09",
28
28
  "start:vue": "cd ./src/ui/client && npm run dev",
29
- "start:server": "node -e \"import('./index.js').then(module => module.startServer(false))\"",
30
- "start:server:no-open": "node -e \"import('./index.js').then(module => module.startServer(true))\"",
29
+ "start:server": "node server.js",
30
+ "start:server:no-open": "node server.js --no-open",
31
31
  "release": "node ./scripts/release.js",
32
32
  "release:win": ".\\scripts\\release.bat"
33
33
  },
@@ -493,6 +493,18 @@ async function publishToNpm() {
493
493
  return;
494
494
  }
495
495
 
496
+ // 切换到官方npm registry
497
+ console.log(chalk.gray('切换到官方npm registry...'));
498
+ try {
499
+ execSync('nrm use npm', { stdio: 'inherit' });
500
+ // 等待1s
501
+ await new Promise(resolve => setTimeout(resolve, 1000));
502
+ console.log(chalk.green('已切换到官方npm registry'));
503
+ } catch (error) {
504
+ console.error(chalk.yellow('切换npm registry失败:'), error);
505
+ console.log(chalk.yellow('继续使用当前registry发布...'));
506
+ }
507
+
496
508
  // 执行npm发布
497
509
  console.log(chalk.gray('执行npm发布...'));
498
510
  try {
package/src/config.js CHANGED
@@ -8,7 +8,8 @@ const configPath = path.join(os.homedir(), '.git-commit-tool.json');
8
8
  // 默认配置
9
9
  const defaultConfig = {
10
10
  defaultCommitMessage: "submit",
11
- descriptionTemplates: [] // 添加描述模板数组
11
+ descriptionTemplates: [], // 添加描述模板数组
12
+ lockedFiles: [] // 添加锁定文件数组
12
13
  };
13
14
 
14
15
  // 异步读取配置文件
@@ -25,6 +26,62 @@ async function loadConfig() {
25
26
  async function saveConfig(config) {
26
27
  await fs.writeFile(configPath, JSON.stringify(config, null, 2), 'utf-8');
27
28
  }
29
+ // 文件锁定管理函数
30
+ async function lockFile(filePath) {
31
+ const config = await loadConfig();
32
+ const normalizedPath = path.normalize(filePath);
33
+
34
+ if (!config.lockedFiles.includes(normalizedPath)) {
35
+ config.lockedFiles.push(normalizedPath);
36
+ await saveConfig(config);
37
+ console.log(chalk.green(`✓ 文件已锁定: "${normalizedPath}"`));
38
+ return true;
39
+ } else {
40
+ console.log(chalk.yellow(`⚠️ 文件已经被锁定: "${normalizedPath}"`));
41
+ return false;
42
+ }
43
+ }
44
+
45
+ async function unlockFile(filePath) {
46
+ const config = await loadConfig();
47
+ const normalizedPath = path.normalize(filePath);
48
+ const index = config.lockedFiles.indexOf(normalizedPath);
49
+
50
+ if (index > -1) {
51
+ config.lockedFiles.splice(index, 1);
52
+ await saveConfig(config);
53
+ console.log(chalk.green(`✓ 文件已解锁: "${normalizedPath}"`));
54
+ return true;
55
+ } else {
56
+ console.log(chalk.yellow(`⚠️ 文件未被锁定: "${normalizedPath}"`));
57
+ return false;
58
+ }
59
+ }
60
+
61
+ async function isFileLocked(filePath) {
62
+ const config = await loadConfig();
63
+ const normalizedPath = path.normalize(filePath);
64
+ return config.lockedFiles.includes(normalizedPath);
65
+ }
66
+
67
+ async function listLockedFiles() {
68
+ const config = await loadConfig();
69
+ if (config.lockedFiles.length === 0) {
70
+ console.log(chalk.blue('📝 当前没有锁定的文件'));
71
+ } else {
72
+ console.log(chalk.blue('🔒 已锁定的文件:'));
73
+ config.lockedFiles.forEach((file, index) => {
74
+ console.log(chalk.gray(` ${index + 1}. ${file}`));
75
+ });
76
+ }
77
+ return config.lockedFiles;
78
+ }
79
+
80
+ async function getLockedFiles() {
81
+ const config = await loadConfig();
82
+ return config.lockedFiles || [];
83
+ }
84
+
28
85
  // 添加配置管理函数
29
86
  async function handleConfigCommands() {
30
87
  if (process.argv.includes('get-config')) {
@@ -47,5 +104,10 @@ async function handleConfigCommands() {
47
104
  export default {
48
105
  loadConfig,
49
106
  saveConfig,
50
- handleConfigCommands
107
+ handleConfigCommands,
108
+ lockFile,
109
+ unlockFile,
110
+ isFileLocked,
111
+ listLockedFiles,
112
+ getLockedFiles
51
113
  };
package/src/gitCommit.js CHANGED
@@ -110,6 +110,56 @@ async function createGitCommit(options) {
110
110
  throw e; // 继续向上抛出错误
111
111
  }
112
112
  }
113
+ // 处理文件锁定相关命令
114
+ async function handleFileLockCommands() {
115
+ // 锁定文件命令
116
+ const lockFileArg = process.argv.find(arg => arg.startsWith('--lock-file='));
117
+ if (lockFileArg) {
118
+ const filePath = lockFileArg.split('=')[1];
119
+ if (filePath) {
120
+ await config.lockFile(filePath);
121
+ } else {
122
+ console.log(chalk.red('❌ 请指定要锁定的文件路径'));
123
+ }
124
+ process.exit();
125
+ }
126
+
127
+ // 解锁文件命令
128
+ const unlockFileArg = process.argv.find(arg => arg.startsWith('--unlock-file='));
129
+ if (unlockFileArg) {
130
+ const filePath = unlockFileArg.split('=')[1];
131
+ if (filePath) {
132
+ await config.unlockFile(filePath);
133
+ } else {
134
+ console.log(chalk.red('❌ 请指定要解锁的文件路径'));
135
+ }
136
+ process.exit();
137
+ }
138
+
139
+ // 列出锁定文件命令
140
+ if (process.argv.includes('--list-locked')) {
141
+ await config.listLockedFiles();
142
+ process.exit();
143
+ }
144
+
145
+ // 检查文件是否锁定命令
146
+ const checkLockArg = process.argv.find(arg => arg.startsWith('--check-lock='));
147
+ if (checkLockArg) {
148
+ const filePath = checkLockArg.split('=')[1];
149
+ if (filePath) {
150
+ const isLocked = await config.isFileLocked(filePath);
151
+ if (isLocked) {
152
+ console.log(chalk.yellow(`🔒 文件已锁定: ${filePath}`));
153
+ } else {
154
+ console.log(chalk.green(`🔓 文件未锁定: ${filePath}`));
155
+ }
156
+ } else {
157
+ console.log(chalk.red('❌ 请指定要检查的文件路径'));
158
+ }
159
+ process.exit();
160
+ }
161
+ }
162
+
113
163
  async function main() {
114
164
  judgePlatform()
115
165
 
@@ -139,6 +189,9 @@ async function main() {
139
189
 
140
190
  await handleConfigCommands();
141
191
 
192
+ // ========== 文件锁定功能 ==========
193
+ await handleFileLockCommands();
194
+
142
195
  // ========== 新增:自定义cmd定时/定点执行功能 ==========
143
196
  const cmdArg = process.argv.find(arg => arg.startsWith('--cmd='));
144
197
  if (cmdArg) {