@ijuantm/simpl-addon 2.6.2 → 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 +33 -53
  2. package/package.json +1 -1
package/install.js CHANGED
@@ -147,49 +147,53 @@ 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;
152
-
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
-
157
- if (suggestion) {
158
- log(` ${COLORS.yellow}Did you mean:${COLORS.reset} ${COLORS.cyan}${suggestion}${COLORS.reset}?`);
150
+ const promptAddon = async (addons, firstInput = null) => {
151
+ const askSuggestion = async (input) => {
152
+ const suggestion = closestMatch(input, addons);
159
153
  console.log();
154
+ log(` ${COLORS.red}✗${COLORS.reset} Add-on ${COLORS.bold}${input}${COLORS.reset} not found`, 'red');
160
155
 
161
- const answer = await promptUser(` Use "${suggestion}"? ${COLORS.dim}(y/n — n shows available add-ons)${COLORS.reset}`);
162
- const a = answer.toLowerCase();
156
+ if (suggestion) {
157
+ log(` ${COLORS.yellow}Did you mean:${COLORS.reset} ${COLORS.cyan}${suggestion}${COLORS.reset}?`);
158
+ console.log();
163
159
 
164
- if (a === 'yes' || a === 'y') return suggestion;
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();
165
163
 
166
- if (a !== 'no' && a !== 'n') {
167
- log(` ${COLORS.dim}Please answer y or n${COLORS.reset}`);
164
+ if (a === 'yes' || a === 'y') return suggestion;
165
+ if (a === 'no' || a === 'n') break;
166
+
167
+ log(` ${COLORS.dim}Please answer yes or no${COLORS.reset}`);
168
+ }
168
169
  }
169
- }
170
170
 
171
- console.log();
172
- log(` ${COLORS.bold}Available add-ons:${COLORS.reset}`, 'blue');
173
- listAddons(addons);
174
- console.log();
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;
175
180
 
176
181
  while (true) {
177
- const input2 = await promptUser(` Add-on to install ${COLORS.dim}(name or number)${COLORS.reset}`);
182
+ const input = pending || await promptUser(` Add-on to install ${COLORS.dim}(name or number)${COLORS.reset}`);
183
+ pending = null;
178
184
 
179
- if (!input2) {
185
+ if (!input) {
180
186
  log(` ${COLORS.red}✗${COLORS.reset} Selection cannot be empty`, 'red');
181
187
  console.log();
182
188
  continue;
183
189
  }
184
190
 
185
- const numInput = parseInt(input2, 10);
191
+ const numInput = parseInt(input, 10);
186
192
  if (!isNaN(numInput) && numInput >= 1 && numInput <= addons.length) return addons[numInput - 1];
187
- if (addons.includes(input2)) return input2;
193
+ if (addons.includes(input)) return input;
188
194
 
189
- const suggestion2 = closestMatch(input2, addons);
190
- log(` ${COLORS.red}✗${COLORS.reset} Invalid selection ${COLORS.bold}${input2}${COLORS.reset}`, 'red');
191
- if (suggestion2) log(` ${COLORS.dim}Did you mean ${COLORS.reset}${COLORS.cyan}${suggestion2}${COLORS.reset}${COLORS.dim}?${COLORS.reset}`);
192
- console.log();
195
+ const resolved = await askSuggestion(input);
196
+ if (resolved) return resolved;
193
197
  }
194
198
  };
195
199
 
@@ -608,7 +612,7 @@ const main = async () => {
608
612
  let addonName;
609
613
 
610
614
  if (parsed.addon) {
611
- addonName = await resolveAddon(parsed.addon, addons);
615
+ addonName = await promptAddon(addons, parsed.addon);
612
616
  printAnswer(' Add-on to install', addonName);
613
617
  } else {
614
618
  console.log();
@@ -616,31 +620,7 @@ const main = async () => {
616
620
  listAddons(addons);
617
621
  console.log();
618
622
 
619
- while (true) {
620
- const input = await promptUser(` Add-on to install ${COLORS.dim}(name or number)${COLORS.reset}`);
621
-
622
- if (!input) {
623
- log(` ${COLORS.red}✗${COLORS.reset} Selection cannot be empty`, 'red');
624
- console.log();
625
- continue;
626
- }
627
-
628
- const numInput = parseInt(input, 10);
629
- if (!isNaN(numInput) && numInput >= 1 && numInput <= addons.length) {
630
- addonName = addons[numInput - 1];
631
- break;
632
- }
633
-
634
- if (addons.includes(input)) {
635
- addonName = input;
636
- break;
637
- }
638
-
639
- const suggestion = closestMatch(input, addons);
640
- log(` ${COLORS.red}✗${COLORS.reset} Invalid selection ${COLORS.bold}${input}${COLORS.reset}`, 'red');
641
- if (suggestion) log(` ${COLORS.dim}Did you mean ${COLORS.reset}${COLORS.cyan}${suggestion}${COLORS.reset}${COLORS.dim}?${COLORS.reset}`);
642
- console.log();
643
- }
623
+ addonName = await promptAddon(addons);
644
624
  }
645
625
 
646
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.2",
4
+ "version": "2.6.3",
5
5
  "scripts": {
6
6
  "link": "npm link",
7
7
  "unlink": "npm unlink -g @ijuantm/simpl-addon"