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 +1 -1
- package/src/commands/imgCompress.js +9 -22
- package/src/locales/en.js +1 -1
- package/src/locales/zh.js +3 -2
package/package.json
CHANGED
|
@@ -124,8 +124,8 @@ async function pickPreserveStructure() {
|
|
|
124
124
|
return choice;
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
async function
|
|
128
|
-
const choice = await selectFromMenu(i18next.t('imgCompress.
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
|
209
|
-
if (
|
|
210
|
-
|
|
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,
|
|
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
|
-
|
|
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
|
-
|
|
158
|
+
preservePrompt: '递归时是否按原始目录结构输出'
|
|
159
|
+
,
|
|
160
|
+
suffixPrompt: '是否在文件名添加后缀(compressed+时间戳)'
|
|
160
161
|
}
|
|
161
162
|
};
|