change-image-suffix 2.1.1 → 2.1.3

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/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [2.1.3](https://github.com/GuoSirius/change-image-suffix/compare/v2.1.2...v2.1.3) (2026-05-21)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * **context-menu:** auto-refresh menu on version change, gate preuninstall on global ([396dc45](https://github.com/GuoSirius/change-image-suffix/commit/396dc45f1d0606a16828f8e9467194ec933487d8))
11
+
12
+ ### [2.1.2](https://github.com/GuoSirius/change-image-suffix/compare/v2.1.1...v2.1.2) (2026-05-21)
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * add stdio inherit to release.js git commands for visible output ([7644eba](https://github.com/GuoSirius/change-image-suffix/commit/7644ebab76a090fd199cf1429edc0ccfa4a25323))
18
+
5
19
  ### [2.1.1](https://github.com/GuoSirius/change-image-suffix/compare/v2.1.0...v2.1.1) (2026-05-21)
6
20
 
7
21
 
package/dist/index.js CHANGED
@@ -195,6 +195,10 @@ endlocal
195
195
  // bat 脚本会检查文件扩展名,自动忽略非图片文件
196
196
  }
197
197
  }
198
+ // 写入版本标记,用于检测 npm update 后自动刷新菜单
199
+ const versionFile = path.join(appDataDir, 'version.json');
200
+ const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf8'));
201
+ fs.writeFileSync(versionFile, JSON.stringify({ version: pkg.version }), 'utf8');
198
202
  console.log('✅ 右键菜单安装成功!');
199
203
  console.log(' 📁 文件夹空白处/图标右键 → 悬停展开格式子菜单');
200
204
  console.log(' 🖼 图片文件上右键 → 悬停展开格式子菜单');
@@ -228,15 +232,42 @@ function uninstallContextMenu() {
228
232
  }
229
233
  catch { /* ignore */ }
230
234
  }
231
- // 删除批处理文件
235
+ // 删除批处理文件和版本标记
232
236
  const appDataDir = path.join(os.homedir(), 'AppData', 'Roaming', 'change-image-suffix');
233
237
  const batPath = path.join(appDataDir, 'cis_file.bat');
234
238
  try {
235
239
  fs.unlinkSync(batPath);
236
240
  }
237
241
  catch { /* ignore */ }
242
+ const versionFile = path.join(appDataDir, 'version.json');
243
+ try {
244
+ fs.unlinkSync(versionFile);
245
+ }
246
+ catch { /* ignore */ }
238
247
  console.log('✅ 右键菜单已卸载');
239
248
  }
249
+ // 自动检测版本变化并更新右键菜单(解决 npm update 不触发 postinstall 的问题)
250
+ function autoUpdateContextMenu() {
251
+ if (os.platform() !== 'win32')
252
+ return;
253
+ const appDataDir = path.join(os.homedir(), 'AppData', 'Roaming', 'change-image-suffix');
254
+ const versionFile = path.join(appDataDir, 'version.json');
255
+ const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf8'));
256
+ const currentVersion = pkg.version;
257
+ let installedVersion = '';
258
+ try {
259
+ if (fs.existsSync(versionFile)) {
260
+ installedVersion = JSON.parse(fs.readFileSync(versionFile, 'utf8')).version || '';
261
+ }
262
+ }
263
+ catch { /* ignore */ }
264
+ if (installedVersion !== currentVersion) {
265
+ try {
266
+ installContextMenu();
267
+ }
268
+ catch { /* menu update failed silently, will retry next invocation */ }
269
+ }
270
+ }
240
271
  // ─────────────────────────────────────────
241
272
  // 参数解析
242
273
  // ─────────────────────────────────────────
@@ -522,6 +553,8 @@ async function main() {
522
553
  uninstallContextMenu();
523
554
  return;
524
555
  }
556
+ // 自动检测版本变化并刷新右键菜单(npm update 不触发 postinstall)
557
+ autoUpdateContextMenu();
525
558
  console.log('\n🖼️ change-image-suffix - 图片格式批量转换工具\n');
526
559
  const options = parseArgs();
527
560
  // ─── 辅助函数:处理文件列表 ───
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "change-image-suffix",
3
- "version": "2.1.1",
3
+ "version": "2.1.3",
4
4
  "description": "批量转换图片格式的CLI工具,支持递归搜索、深度限制、指定后缀、Windows右键菜单等功能",
5
5
  "main": "dist/index.js",
6
6
  "files": [
@@ -4,7 +4,7 @@ const os = require('os');
4
4
  const { execSync } = require('child_process');
5
5
  const path = require('path');
6
6
 
7
- if (os.platform() === 'win32') {
7
+ if (os.platform() === 'win32' && process.env.npm_config_global === 'true') {
8
8
  try {
9
9
  const indexJs = path.join(__dirname, '..', 'dist', 'index.js');
10
10
  execSync(`node "${indexJs}" uninstall-menu`, { stdio: 'inherit' });