change-image-suffix 2.1.12 → 2.1.14

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,22 @@
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.14](https://github.com/GuoSirius/change-image-suffix/compare/v2.1.13...v2.1.14) (2026-05-25)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * add quotes around %V/%1 in context menu, make resolveSplitPath return string[] ([28ccc83](https://github.com/GuoSirius/change-image-suffix/commit/28ccc83d39f4441eac31a8985509ac49a8ab7019))
11
+
12
+ ### [2.1.13](https://github.com/GuoSirius/change-image-suffix/compare/v2.1.12...v2.1.13) (2026-05-25)
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * only pause on --pause when there are failures ([131b316](https://github.com/GuoSirius/change-image-suffix/commit/131b3163ef7752bb987915b5d17ec4e19bc02c0d))
18
+ * reconstruct paths split by Windows at spaces in context menu args ([5173554](https://github.com/GuoSirius/change-image-suffix/commit/5173554733b13f80b490e695d9ba6343d8ad192a))
19
+ * use -p %V for Directory Background, rely on resolveSplitPath ([85bf5b9](https://github.com/GuoSirius/change-image-suffix/commit/85bf5b9cefb362422db1a587368a8d983eaa3dda))
20
+
5
21
  ### [2.1.12](https://github.com/GuoSirius/change-image-suffix/compare/v2.1.11...v2.1.12) (2026-05-25)
6
22
 
7
23
 
package/dist/index.js CHANGED
@@ -69,9 +69,9 @@ function installContextMenu() {
69
69
  ];
70
70
  // ── 使用 ExtendedSubCommandsKey,直接调用 node.exe(无 bat 中转)──
71
71
  const menuBases = [
72
- { base: 'HKCU\\Software\\Classes\\Directory\\Background\\shell\\cis', subMenu: 'Directory\\ContextMenus\\cis', arg: '-p .' },
73
- { base: 'HKCU\\Software\\Classes\\Directory\\shell\\cis', subMenu: 'Directory\\ContextMenus\\cis_dir', arg: '-p %1' },
74
- { base: 'HKCU\\Software\\Classes\\*\\shell\\cis', subMenu: 'Directory\\ContextMenus\\cis_file', arg: '-f %1' },
72
+ { base: 'HKCU\\Software\\Classes\\Directory\\Background\\shell\\cis', subMenu: 'Directory\\ContextMenus\\cis', arg: '-p "%V"' },
73
+ { base: 'HKCU\\Software\\Classes\\Directory\\shell\\cis', subMenu: 'Directory\\ContextMenus\\cis_dir', arg: '-p "%1"' },
74
+ { base: 'HKCU\\Software\\Classes\\*\\shell\\cis', subMenu: 'Directory\\ContextMenus\\cis_file', arg: '-f "%1"' },
75
75
  ];
76
76
  // 1. 注册格式子菜单
77
77
  const REG_ROOT = 'HKCU\\Software\\Classes\\';
@@ -127,13 +127,13 @@ function uninstallContextMenu() {
127
127
  }
128
128
  catch { /* ignore */ }
129
129
  }
130
- // 删除批处理文件、图标和版本标记
130
+ // 删除遗留文件(旧版 bat 脚本、图标、版本标记)
131
131
  const appDataDir = path.join(os.homedir(), 'AppData', 'Roaming', 'change-image-suffix');
132
132
  const batPath = path.join(appDataDir, 'cis_file.bat');
133
133
  try {
134
134
  fs.unlinkSync(batPath);
135
135
  }
136
- catch { /* ignore */ }
136
+ catch { /* ignore */ } // 旧版残留清理
137
137
  const iconPath = path.join(appDataDir, 'icon.ico');
138
138
  try {
139
139
  fs.unlinkSync(iconPath);
@@ -179,6 +179,18 @@ function autoUpdateContextMenu() {
179
179
  // ─────────────────────────────────────────
180
180
  // 参数解析
181
181
  // ─────────────────────────────────────────
182
+ // Windows ExtendedSubCommandsKey 会将含空格的路径拆成多段参数,
183
+ // 此函数尝试将拆散的片段拼接回完整路径。
184
+ function resolveSplitPath(parts) {
185
+ if (parts.length === 1)
186
+ return [path.resolve(parts[0])];
187
+ // 尝试将拆散的片段用空格拼接回完整路径(右键菜单可能将含空格的路径拆成多段)
188
+ const fullJoin = parts.join(' ');
189
+ if (fs.existsSync(fullJoin))
190
+ return [path.resolve(fullJoin)];
191
+ // 无法拼接为单个存在的路径 → 各段视为独立路径(用户主动传了多个路径)
192
+ return parts.map(p => path.resolve(p));
193
+ }
182
194
  function parseArgs() {
183
195
  const args = process.argv.slice(2);
184
196
  const options = {
@@ -249,30 +261,34 @@ function parseArgs() {
249
261
  process.exit(0);
250
262
  }
251
263
  if (arg === '-p' || arg === '--path') {
252
- // 收集 -p 后的目录
264
+ // 收集 -p 后的目录(Windows 右键菜单可能将含空格的路径拆成多段,需尝试拼接)
265
+ const parts = [];
253
266
  const start = i + 1;
254
267
  while (i + 1 < args.length && !args[i + 1].startsWith('-')) {
255
268
  i++;
256
- dirsFromFlag.push(path.resolve(args[i]));
269
+ parts.push(args[i]);
257
270
  }
258
- // 如果 -p 后面没有参数,用当前目录
259
- if (start > i) {
271
+ if (parts.length === 0) {
260
272
  dirsFromFlag.push(path.resolve('.'));
261
273
  }
274
+ else {
275
+ dirsFromFlag.push(...resolveSplitPath(parts));
276
+ }
262
277
  i++;
263
278
  continue;
264
279
  }
265
280
  if (arg === '-f' || arg === '--file') {
266
- // 收集 -f 后的所有文件
281
+ const parts = [];
267
282
  const start = i + 1;
268
283
  while (i + 1 < args.length && !args[i + 1].startsWith('-')) {
269
284
  i++;
270
- filesFromFlag.push(path.resolve(args[i]));
285
+ parts.push(args[i]);
271
286
  }
272
- if (start > i) {
287
+ if (parts.length === 0) {
273
288
  console.error('❌ -f/--file 需要指定至少一个文件路径');
274
289
  process.exit(1);
275
290
  }
291
+ filesFromFlag.push(...resolveSplitPath(parts));
276
292
  i++;
277
293
  continue;
278
294
  }
@@ -591,18 +607,21 @@ async function main() {
591
607
  }
592
608
  return { success: totalSuccess, fail: totalFail };
593
609
  }
610
+ let totalFail = 0;
594
611
  // ─── 混合模式:同时有文件和目录 ───
595
612
  if (options.multiFiles && options.multiFiles.length > 0 && options.multiPaths && options.multiPaths.length > 0) {
596
613
  console.log('\n🖼️ change-image-suffix - 混合模式(文件+目录)\n');
597
614
  const fileResult = await processFiles(options.multiFiles, '图片转换工具');
598
615
  console.log('\n');
599
616
  const dirResult = await processDirs(options.multiPaths);
617
+ totalFail = fileResult.fail + dirResult.fail;
600
618
  console.log('\n----------------------------------------');
601
- console.log(`📊 转换完成!成功: ${fileResult.success + dirResult.success}, 失败: ${fileResult.fail + dirResult.fail}\n`);
619
+ console.log(`📊 转换完成!成功: ${fileResult.success + dirResult.success}, 失败: ${totalFail}\n`);
602
620
  }
603
621
  else if (options.multiFiles && options.multiFiles.length > 0) {
604
622
  // ─── 单/多文件模式 ───
605
623
  const result = await processFiles(options.multiFiles, '图片转换工具');
624
+ totalFail = result.fail;
606
625
  console.log('\n----------------------------------------\n');
607
626
  console.log(`📊 转换完成!成功: ${result.success}, 失败: ${result.fail}\n`);
608
627
  }
@@ -610,6 +629,7 @@ async function main() {
610
629
  // ─── 多路径模式 ───
611
630
  console.log(`\n🖼️ change-image-suffix - 批量转换工具\n`);
612
631
  const result = await processDirs(options.multiPaths);
632
+ totalFail = result.fail;
613
633
  console.log('\n----------------------------------------');
614
634
  console.log(`📊 转换完成!成功: ${result.success}, 失败: ${result.fail}\n`);
615
635
  }
@@ -645,6 +665,7 @@ async function main() {
645
665
  failCount++;
646
666
  }
647
667
  }
668
+ totalFail = failCount;
648
669
  console.log('\n----------------------------------------');
649
670
  console.log(`\n📊 转换完成!成功: ${successCount}, 失败: ${failCount}\n`);
650
671
  if (failCount > 0) {
@@ -655,8 +676,8 @@ async function main() {
655
676
  }
656
677
  }
657
678
  }
658
- // 右键菜单调用时暂停,让用户看到输出
659
- if (process.argv.includes('--pause')) {
679
+ // 右键菜单调用时,仅在有失败时暂停让用户查看
680
+ if (process.argv.includes('--pause') && totalFail > 0) {
660
681
  console.log('\n按任意键退出...');
661
682
  process.stdin.setRawMode(true);
662
683
  process.stdin.resume();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "change-image-suffix",
3
- "version": "2.1.12",
3
+ "version": "2.1.14",
4
4
  "type": "module",
5
5
  "description": "批量转换图片格式的CLI工具,支持递归搜索、深度限制、指定后缀、Windows右键菜单等功能",
6
6
  "main": "dist/index.js",