@ijuantm/simpl-addon 2.6.1 → 2.6.3

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.
Files changed (2) hide show
  1. package/install.js +42 -49
  2. package/package.json +1 -1
package/install.js CHANGED
@@ -147,37 +147,54 @@ const closestMatch = (input, options) => {
147
147
 
148
148
  // --- Fuzzy addon resolution with interactive prompts ---
149
149
 
150
- const resolveAddon = async (input, addons) => {
151
- if (addons.includes(input)) return input;
150
+ const promptAddon = async (addons, firstInput = null) => {
151
+ const askSuggestion = async (input) => {
152
+ const suggestion = closestMatch(input, addons);
153
+ console.log();
154
+ log(` ${COLORS.red}✗${COLORS.reset} Add-on ${COLORS.bold}${input}${COLORS.reset} not found`, 'red');
152
155
 
153
- const suggestion = closestMatch(input, addons);
154
- console.log();
155
- log(` ${COLORS.red}✗${COLORS.reset} Add-on ${COLORS.bold}${input}${COLORS.reset} not found`, 'red');
156
+ if (suggestion) {
157
+ log(` ${COLORS.yellow}Did you mean:${COLORS.reset} ${COLORS.cyan}${suggestion}${COLORS.reset}?`);
158
+ console.log();
156
159
 
157
- if (suggestion) {
158
- log(` ${COLORS.yellow}Did you mean:${COLORS.reset} ${COLORS.cyan}${suggestion}${COLORS.reset}?`);
159
- console.log();
160
+ while (true) {
161
+ const answer = await promptUser(` Use "${suggestion}"? ${COLORS.dim}(yes / no — no lists available add-ons)${COLORS.reset}`);
162
+ const a = answer.toLowerCase();
160
163
 
161
- while (true) {
162
- const answer = await promptUser(` Use "${suggestion}"? ${COLORS.dim}(yes / no / list)${COLORS.reset}`);
163
- const a = answer.toLowerCase();
164
+ if (a === 'yes' || a === 'y') return suggestion;
165
+ if (a === 'no' || a === 'n') break;
164
166
 
165
- if (a === 'yes' || a === 'y') return suggestion;
166
- if (a === 'list') {
167
- listAddons(addons);
168
- break;
167
+ log(` ${COLORS.dim}Please answer yes or no${COLORS.reset}`);
169
168
  }
170
- if (a === 'no' || a === 'n') break;
169
+ }
171
170
 
172
- log(` ${COLORS.dim}Please answer yes, no, or list${COLORS.reset}`);
171
+ console.log();
172
+ log(` ${COLORS.bold}Available add-ons:${COLORS.reset}`, 'blue');
173
+ listAddons(addons);
174
+ console.log();
175
+
176
+ return null;
177
+ };
178
+
179
+ let pending = firstInput;
180
+
181
+ while (true) {
182
+ const input = pending || await promptUser(` Add-on to install ${COLORS.dim}(name or number)${COLORS.reset}`);
183
+ pending = null;
184
+
185
+ if (!input) {
186
+ log(` ${COLORS.red}✗${COLORS.reset} Selection cannot be empty`, 'red');
187
+ console.log();
188
+ continue;
173
189
  }
174
- }
175
190
 
176
- console.log();
177
- log(` ${COLORS.bold}Available add-ons:${COLORS.reset}`, 'blue');
178
- listAddons(addons);
179
- console.log();
180
- process.exit(1);
191
+ const numInput = parseInt(input, 10);
192
+ if (!isNaN(numInput) && numInput >= 1 && numInput <= addons.length) return addons[numInput - 1];
193
+ if (addons.includes(input)) return input;
194
+
195
+ const resolved = await askSuggestion(input);
196
+ if (resolved) return resolved;
197
+ }
181
198
  };
182
199
 
183
200
  const listAddons = (addons) => addons.forEach((name, i) => log(` ${COLORS.cyan}${i + 1}.${COLORS.reset} ${name}`));
@@ -595,7 +612,7 @@ const main = async () => {
595
612
  let addonName;
596
613
 
597
614
  if (parsed.addon) {
598
- addonName = await resolveAddon(parsed.addon, addons);
615
+ addonName = await promptAddon(addons, parsed.addon);
599
616
  printAnswer(' Add-on to install', addonName);
600
617
  } else {
601
618
  console.log();
@@ -603,31 +620,7 @@ const main = async () => {
603
620
  listAddons(addons);
604
621
  console.log();
605
622
 
606
- while (true) {
607
- const input = await promptUser(` Add-on to install ${COLORS.dim}(name or number)${COLORS.reset}`);
608
-
609
- if (!input) {
610
- log(` ${COLORS.red}✗${COLORS.reset} Selection cannot be empty`, 'red');
611
- console.log();
612
- continue;
613
- }
614
-
615
- const numInput = parseInt(input, 10);
616
- if (!isNaN(numInput) && numInput >= 1 && numInput <= addons.length) {
617
- addonName = addons[numInput - 1];
618
- break;
619
- }
620
-
621
- if (addons.includes(input)) {
622
- addonName = input;
623
- break;
624
- }
625
-
626
- const suggestion = closestMatch(input, addons);
627
- log(` ${COLORS.red}✗${COLORS.reset} Invalid selection ${COLORS.bold}${input}${COLORS.reset}`, 'red');
628
- if (suggestion) log(` ${COLORS.dim}Did you mean ${COLORS.reset}${COLORS.cyan}${suggestion}${COLORS.reset}${COLORS.dim}?${COLORS.reset}`);
629
- console.log();
630
- }
623
+ addonName = await promptAddon(addons);
631
624
  }
632
625
 
633
626
  console.log();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ijuantm/simpl-addon",
3
3
  "description": "CLI tool to install Simpl framework add-ons.",
4
- "version": "2.6.1",
4
+ "version": "2.6.3",
5
5
  "scripts": {
6
6
  "link": "npm link",
7
7
  "unlink": "npm unlink -g @ijuantm/simpl-addon"