change-image-suffix 2.1.12 → 2.1.13

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,15 @@
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.13](https://github.com/GuoSirius/change-image-suffix/compare/v2.1.12...v2.1.13) (2026-05-25)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * only pause on --pause when there are failures ([131b316](https://github.com/GuoSirius/change-image-suffix/commit/131b3163ef7752bb987915b5d17ec4e19bc02c0d))
11
+ * reconstruct paths split by Windows at spaces in context menu args ([5173554](https://github.com/GuoSirius/change-image-suffix/commit/5173554733b13f80b490e695d9ba6343d8ad192a))
12
+ * use -p %V for Directory Background, rely on resolveSplitPath ([85bf5b9](https://github.com/GuoSirius/change-image-suffix/commit/85bf5b9cefb362422db1a587368a8d983eaa3dda))
13
+
5
14
  ### [2.1.12](https://github.com/GuoSirius/change-image-suffix/compare/v2.1.11...v2.1.12) (2026-05-25)
6
15
 
7
16
 
package/dist/index.js CHANGED
@@ -69,7 +69,7 @@ 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 .' },
72
+ { base: 'HKCU\\Software\\Classes\\Directory\\Background\\shell\\cis', subMenu: 'Directory\\ContextMenus\\cis', arg: '-p %V' },
73
73
  { base: 'HKCU\\Software\\Classes\\Directory\\shell\\cis', subMenu: 'Directory\\ContextMenus\\cis_dir', arg: '-p %1' },
74
74
  { base: 'HKCU\\Software\\Classes\\*\\shell\\cis', subMenu: 'Directory\\ContextMenus\\cis_file', arg: '-f %1' },
75
75
  ];
@@ -179,6 +179,24 @@ 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
+ if (fs.existsSync(parts[0]))
189
+ return path.resolve(parts[0]);
190
+ // 逐段拼接,直到找到存在的路径
191
+ let joined = parts[0];
192
+ for (let j = 1; j < parts.length; j++) {
193
+ joined += ' ' + parts[j];
194
+ if (fs.existsSync(joined))
195
+ return path.resolve(joined);
196
+ }
197
+ // 都不存在,返回全拼接结果(后续流程会报 "不存在")
198
+ return path.resolve(joined);
199
+ }
182
200
  function parseArgs() {
183
201
  const args = process.argv.slice(2);
184
202
  const options = {
@@ -249,30 +267,34 @@ function parseArgs() {
249
267
  process.exit(0);
250
268
  }
251
269
  if (arg === '-p' || arg === '--path') {
252
- // 收集 -p 后的目录
270
+ // 收集 -p 后的目录(Windows 右键菜单可能将含空格的路径拆成多段,需尝试拼接)
271
+ const parts = [];
253
272
  const start = i + 1;
254
273
  while (i + 1 < args.length && !args[i + 1].startsWith('-')) {
255
274
  i++;
256
- dirsFromFlag.push(path.resolve(args[i]));
275
+ parts.push(args[i]);
257
276
  }
258
- // 如果 -p 后面没有参数,用当前目录
259
- if (start > i) {
277
+ if (parts.length === 0) {
260
278
  dirsFromFlag.push(path.resolve('.'));
261
279
  }
280
+ else {
281
+ dirsFromFlag.push(resolveSplitPath(parts));
282
+ }
262
283
  i++;
263
284
  continue;
264
285
  }
265
286
  if (arg === '-f' || arg === '--file') {
266
- // 收集 -f 后的所有文件
287
+ const parts = [];
267
288
  const start = i + 1;
268
289
  while (i + 1 < args.length && !args[i + 1].startsWith('-')) {
269
290
  i++;
270
- filesFromFlag.push(path.resolve(args[i]));
291
+ parts.push(args[i]);
271
292
  }
272
- if (start > i) {
293
+ if (parts.length === 0) {
273
294
  console.error('❌ -f/--file 需要指定至少一个文件路径');
274
295
  process.exit(1);
275
296
  }
297
+ filesFromFlag.push(resolveSplitPath(parts));
276
298
  i++;
277
299
  continue;
278
300
  }
@@ -591,18 +613,21 @@ async function main() {
591
613
  }
592
614
  return { success: totalSuccess, fail: totalFail };
593
615
  }
616
+ let totalFail = 0;
594
617
  // ─── 混合模式:同时有文件和目录 ───
595
618
  if (options.multiFiles && options.multiFiles.length > 0 && options.multiPaths && options.multiPaths.length > 0) {
596
619
  console.log('\n🖼️ change-image-suffix - 混合模式(文件+目录)\n');
597
620
  const fileResult = await processFiles(options.multiFiles, '图片转换工具');
598
621
  console.log('\n');
599
622
  const dirResult = await processDirs(options.multiPaths);
623
+ totalFail = fileResult.fail + dirResult.fail;
600
624
  console.log('\n----------------------------------------');
601
- console.log(`📊 转换完成!成功: ${fileResult.success + dirResult.success}, 失败: ${fileResult.fail + dirResult.fail}\n`);
625
+ console.log(`📊 转换完成!成功: ${fileResult.success + dirResult.success}, 失败: ${totalFail}\n`);
602
626
  }
603
627
  else if (options.multiFiles && options.multiFiles.length > 0) {
604
628
  // ─── 单/多文件模式 ───
605
629
  const result = await processFiles(options.multiFiles, '图片转换工具');
630
+ totalFail = result.fail;
606
631
  console.log('\n----------------------------------------\n');
607
632
  console.log(`📊 转换完成!成功: ${result.success}, 失败: ${result.fail}\n`);
608
633
  }
@@ -610,6 +635,7 @@ async function main() {
610
635
  // ─── 多路径模式 ───
611
636
  console.log(`\n🖼️ change-image-suffix - 批量转换工具\n`);
612
637
  const result = await processDirs(options.multiPaths);
638
+ totalFail = result.fail;
613
639
  console.log('\n----------------------------------------');
614
640
  console.log(`📊 转换完成!成功: ${result.success}, 失败: ${result.fail}\n`);
615
641
  }
@@ -645,6 +671,7 @@ async function main() {
645
671
  failCount++;
646
672
  }
647
673
  }
674
+ totalFail = failCount;
648
675
  console.log('\n----------------------------------------');
649
676
  console.log(`\n📊 转换完成!成功: ${successCount}, 失败: ${failCount}\n`);
650
677
  if (failCount > 0) {
@@ -655,8 +682,8 @@ async function main() {
655
682
  }
656
683
  }
657
684
  }
658
- // 右键菜单调用时暂停,让用户看到输出
659
- if (process.argv.includes('--pause')) {
685
+ // 右键菜单调用时,仅在有失败时暂停让用户查看
686
+ if (process.argv.includes('--pause') && totalFail > 0) {
660
687
  console.log('\n按任意键退出...');
661
688
  process.stdin.setRawMode(true);
662
689
  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.13",
4
4
  "type": "module",
5
5
  "description": "批量转换图片格式的CLI工具,支持递归搜索、深度限制、指定后缀、Windows右键菜单等功能",
6
6
  "main": "dist/index.js",