xw-devtool-cli 1.0.40 → 1.0.41
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/README.md +3 -1
- package/README_EN.md +1 -1
- package/package.json +1 -1
- package/src/index.js +63 -3
- package/src/locales/en.js +6 -1
- package/src/locales/zh.js +6 -1
package/README.md
CHANGED
|
@@ -96,7 +96,7 @@ xw-devtool --zh # 中文启动
|
|
|
96
96
|
xw-devtool --en # 英文启动 (Start in English)
|
|
97
97
|
```
|
|
98
98
|
|
|
99
|
-
|
|
99
|
+
启动后将显示交互式菜单,通过键盘输入对应的数字或字母选择功能,也支持直接输入关键字搜索(如 `json`、`图片`、`git`):
|
|
100
100
|
|
|
101
101
|
```text
|
|
102
102
|
=================================
|
|
@@ -446,6 +446,8 @@ v. Git Helper (Branch/Commit Template) w. Settings / Language
|
|
|
446
446
|
=================================
|
|
447
447
|
```
|
|
448
448
|
|
|
449
|
+
You can enter a feature key directly, or type a keyword (e.g. `json`, `image`, `git`) to search features and then choose from matched results.
|
|
450
|
+
|
|
449
451
|
### 📖 Detailed Usage
|
|
450
452
|
|
|
451
453
|
#### 1. Image <-> Base64
|
package/README_EN.md
CHANGED
|
@@ -93,7 +93,7 @@ xw-devtool --en # Start in English
|
|
|
93
93
|
xw-devtool --zh # Start in Chinese
|
|
94
94
|
```
|
|
95
95
|
|
|
96
|
-
The interactive menu will appear:
|
|
96
|
+
The interactive menu will appear. You can enter a feature key directly, or type a keyword (e.g. `json`, `image`, `git`) to search and then choose from matched results:
|
|
97
97
|
|
|
98
98
|
```text
|
|
99
99
|
=================================
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -131,6 +131,46 @@ function getFeatureIndex(key) {
|
|
|
131
131
|
return -1;
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
+
function findFeaturesByKeyword(features, keyword) {
|
|
135
|
+
const normalizedKeyword = keyword.trim().toLowerCase();
|
|
136
|
+
if (!normalizedKeyword) return [];
|
|
137
|
+
return features.filter((feature) => {
|
|
138
|
+
const name = feature.name.toLowerCase();
|
|
139
|
+
const value = feature.value.toLowerCase();
|
|
140
|
+
return name.includes(normalizedKeyword) || value.includes(normalizedKeyword);
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
async function selectFeatureFromSearchResults(matchedFeatures) {
|
|
145
|
+
console.log(`\n${i18next.t('menu.searchResultTitle')}`);
|
|
146
|
+
matchedFeatures.forEach((feature, index) => {
|
|
147
|
+
console.log(`${index + 1}. ${feature.name}`);
|
|
148
|
+
});
|
|
149
|
+
console.log(`0. ${i18next.t('common.back')}`);
|
|
150
|
+
console.log('');
|
|
151
|
+
|
|
152
|
+
const { selected } = await inquirer.prompt([
|
|
153
|
+
{
|
|
154
|
+
type: 'input',
|
|
155
|
+
name: 'selected',
|
|
156
|
+
message: i18next.t('menu.searchPrompt'),
|
|
157
|
+
validate: (input) => {
|
|
158
|
+
if (input === '0') return true;
|
|
159
|
+
const index = parseInt(input);
|
|
160
|
+
if (index >= 1 && index <= matchedFeatures.length) {
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
return i18next.t('menu.invalid');
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
]);
|
|
167
|
+
|
|
168
|
+
if (selected === '0') {
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
return matchedFeatures[parseInt(selected) - 1];
|
|
172
|
+
}
|
|
173
|
+
|
|
134
174
|
async function showMenu() {
|
|
135
175
|
const features = getFeatures();
|
|
136
176
|
|
|
@@ -176,7 +216,10 @@ async function showMenu() {
|
|
|
176
216
|
if (index >= 0 && index < features.length) {
|
|
177
217
|
return true;
|
|
178
218
|
}
|
|
179
|
-
|
|
219
|
+
if (findFeaturesByKeyword(features, input).length > 0) {
|
|
220
|
+
return true;
|
|
221
|
+
}
|
|
222
|
+
return i18next.t('menu.invalidWithSearch');
|
|
180
223
|
}
|
|
181
224
|
}
|
|
182
225
|
]);
|
|
@@ -187,10 +230,27 @@ async function showMenu() {
|
|
|
187
230
|
}
|
|
188
231
|
|
|
189
232
|
const index = getFeatureIndex(choice);
|
|
190
|
-
|
|
233
|
+
let selectedFeature = null;
|
|
234
|
+
if (index >= 0 && index < features.length) {
|
|
235
|
+
selectedFeature = features[index];
|
|
236
|
+
} else {
|
|
237
|
+
const matchedFeatures = findFeaturesByKeyword(features, choice);
|
|
238
|
+
if (matchedFeatures.length === 0) {
|
|
239
|
+
console.log(i18next.t('menu.searchNoMatch', { keyword: choice }));
|
|
240
|
+
return showMenu();
|
|
241
|
+
}
|
|
242
|
+
if (matchedFeatures.length === 1) {
|
|
243
|
+
selectedFeature = matchedFeatures[0];
|
|
244
|
+
console.log(i18next.t('menu.searchAutoSelect', { feature: selectedFeature.name }));
|
|
245
|
+
} else {
|
|
246
|
+
selectedFeature = await selectFeatureFromSearchResults(matchedFeatures);
|
|
247
|
+
if (!selectedFeature) {
|
|
248
|
+
return showMenu();
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
191
252
|
|
|
192
253
|
try {
|
|
193
|
-
// console.log('Handling action:', selectedFeature.value);
|
|
194
254
|
await handleAction(selectedFeature.value);
|
|
195
255
|
} catch (error) {
|
|
196
256
|
console.error('Error:', error.message);
|
package/src/locales/en.js
CHANGED
|
@@ -29,7 +29,12 @@ export default {
|
|
|
29
29
|
menu: {
|
|
30
30
|
title: 'xw-devtool-cli Menu',
|
|
31
31
|
exit: 'Exit',
|
|
32
|
-
prompt: 'Please enter feature key',
|
|
32
|
+
prompt: 'Please enter feature key or search keyword',
|
|
33
|
+
searchPrompt: 'Enter number to select result',
|
|
34
|
+
searchResultTitle: 'Search Results',
|
|
35
|
+
invalidWithSearch: 'Invalid input. Please enter a valid menu key or searchable keyword.',
|
|
36
|
+
searchNoMatch: 'No feature matches "{{keyword}}". Please try again.',
|
|
37
|
+
searchAutoSelect: 'Matched feature: {{feature}}',
|
|
33
38
|
invalid: 'Invalid selection. Please enter a valid menu key.',
|
|
34
39
|
bye: 'Bye!',
|
|
35
40
|
features: {
|
package/src/locales/zh.js
CHANGED
|
@@ -29,7 +29,12 @@ export default {
|
|
|
29
29
|
menu: {
|
|
30
30
|
title: 'xw-devtool-cli 菜单',
|
|
31
31
|
exit: '退出',
|
|
32
|
-
prompt: '
|
|
32
|
+
prompt: '请输入功能键或搜索关键字',
|
|
33
|
+
searchPrompt: '请输入序号选择结果',
|
|
34
|
+
searchResultTitle: '搜索结果',
|
|
35
|
+
invalidWithSearch: '无效输入,请输入有效菜单键或可匹配的搜索关键字。',
|
|
36
|
+
searchNoMatch: '未找到与“{{keyword}}”匹配的功能,请重试。',
|
|
37
|
+
searchAutoSelect: '已匹配到功能:{{feature}}',
|
|
33
38
|
invalid: '无效选择,请输入有效的菜单键。',
|
|
34
39
|
bye: '再见!',
|
|
35
40
|
features: {
|