xw-devtool-cli 1.0.35 → 1.0.36

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xw-devtool-cli",
3
- "version": "1.0.35",
3
+ "version": "1.0.36",
4
4
  "type": "module",
5
5
  "description": "基于node的开发者助手cli",
6
6
  "main": "index.js",
@@ -124,8 +124,8 @@ async function pickPreserveStructure() {
124
124
  return choice;
125
125
  }
126
126
 
127
- async function pickTimestampSuffix() {
128
- const choice = await selectFromMenu(i18next.t('imgCompress.timestampPrompt'), [
127
+ async function pickSuffixOption() {
128
+ const choice = await selectFromMenu(i18next.t('imgCompress.suffixPrompt'), [
129
129
  { name: i18next.t('imgCompress.yes'), value: true },
130
130
  { name: i18next.t('imgCompress.no'), value: false }
131
131
  ], true, i18next.t('common.back'));
@@ -133,20 +133,7 @@ async function pickTimestampSuffix() {
133
133
  return choice;
134
134
  }
135
135
 
136
- function uniqueOutPath(dir, baseName) {
137
- let candidate = path.join(dir, baseName);
138
- if (!fs.existsSync(candidate)) return candidate;
139
- let idx = 1;
140
- const ext = path.extname(baseName);
141
- const name = path.basename(baseName, ext);
142
- while (true) {
143
- candidate = path.join(dir, `${name}_${idx}${ext}`);
144
- if (!fs.existsSync(candidate)) return candidate;
145
- idx++;
146
- }
147
- }
148
-
149
- async function compressOne(inputPath, quality, outDir, baseDir, preserveStructure, addTimestamp) {
136
+ async function compressOne(inputPath, quality, outDir, baseDir, preserveStructure, addSuffix) {
150
137
  const ext = path.extname(inputPath).toLowerCase();
151
138
  const name = path.basename(inputPath, ext);
152
139
  const ts = dayjs().format('YYYYMMDD_HHmmss');
@@ -156,7 +143,7 @@ async function compressOne(inputPath, quality, outDir, baseDir, preserveStructur
156
143
  targetDir = path.join(outDir, rel);
157
144
  fs.mkdirSync(targetDir, { recursive: true });
158
145
  }
159
- let outPath = addTimestamp ? path.join(targetDir, `${name}_compressed_${ts}${ext}`) : uniqueOutPath(targetDir, `${name}_compressed${ext}`);
146
+ const outPath = addSuffix ? path.join(targetDir, `${name}_compressed_${ts}${ext}`) : path.join(targetDir, `${name}${ext}`);
160
147
  const image = sharp(inputPath, { failOnError: false });
161
148
  if (ext === '.jpg' || ext === '.jpeg') {
162
149
  await image.jpeg({ quality, mozjpeg: true }).toFile(outPath);
@@ -200,19 +187,19 @@ export async function imgCompressHandler() {
200
187
  const outDir = path.resolve(baseDir, `compressed_${dayjs().format('YYYYMMDD_HHmmss')}`);
201
188
  fs.mkdirSync(outDir, { recursive: true });
202
189
  let preserveStructure = false;
203
- let addTimestamp = true;
190
+ let addSuffix = input.type === 'folder';
204
191
  if (input.type === 'folder') {
205
192
  const preserveChoice = await pickPreserveStructure();
206
193
  if (preserveChoice === '__BACK__') return;
207
194
  preserveStructure = preserveChoice;
208
- const tsChoice = await pickTimestampSuffix();
209
- if (tsChoice === '__BACK__') return;
210
- addTimestamp = tsChoice;
195
+ const suffixChoice = await pickSuffixOption();
196
+ if (suffixChoice === '__BACK__') return;
197
+ addSuffix = suffixChoice;
211
198
  }
212
199
  const results = [];
213
200
  for (const f of files) {
214
201
  try {
215
- const out = await compressOne(f, quality, outDir, baseDir, preserveStructure, addTimestamp);
202
+ const out = await compressOne(f, quality, outDir, baseDir, preserveStructure, addSuffix);
216
203
  if (out) results.push(out);
217
204
  } catch (e) {
218
205
  console.error(`${i18next.t('imgCompress.fail')}: ${f} -> ${e.message}`);
package/src/locales/en.js CHANGED
@@ -156,6 +156,6 @@ export default {
156
156
  opened: 'Opened output directory',
157
157
  scanResult: 'Images found',
158
158
  preservePrompt: 'Preserve original directory structure in output?',
159
- timestampPrompt: 'Append timestamp suffix to filename for folder compression?'
159
+ suffixPrompt: 'Append filename suffix (compressed + timestamp)?'
160
160
  }
161
161
  };
package/src/locales/zh.js CHANGED
@@ -155,7 +155,8 @@ export default {
155
155
  openFail: '打开目录失败',
156
156
  opened: '已打开输出目录',
157
157
  scanResult: '扫描到图片数量',
158
- preservePrompt: '递归时是否按原始目录结构输出',
159
- timestampPrompt: '文件夹压缩是否在文件名添加时间戳后缀'
158
+ preservePrompt: '递归时是否按原始目录结构输出'
159
+ ,
160
+ suffixPrompt: '是否在文件名添加后缀(compressed+时间戳)'
160
161
  }
161
162
  };