easc 0.0.23 → 0.0.25

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/package.json +1 -1
  2. package/src/utils/cli.ts +29 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "easc",
3
- "version": "0.0.23",
3
+ "version": "0.0.25",
4
4
  "description": "Expo App Services for Cloudflare - Deploy tool for Expo OTA updates to Cloudflare Workers",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/utils/cli.ts CHANGED
@@ -2,6 +2,14 @@ import yargs, { type Argv, type CommandModule, type Options } from "yargs";
2
2
  import { select } from "@inquirer/prompts";
3
3
  import chalk from "chalk";
4
4
 
5
+ // Custom error to signal going back to menu
6
+ class BackToMenuError extends Error {
7
+ constructor() {
8
+ super("Back to menu");
9
+ this.name = "BackToMenuError";
10
+ }
11
+ }
12
+
5
13
  interface CommandInfo {
6
14
  command: string;
7
15
  describe: string;
@@ -137,8 +145,16 @@ class InteractiveCLI {
137
145
  return y;
138
146
  },
139
147
  handler: async (argv: any) => {
140
- await this._promptForMissingArgs(argv, cmd.options);
141
- return cmd.handler(argv);
148
+ try {
149
+ await this._promptForMissingArgs(argv, cmd.options);
150
+ return cmd.handler(argv);
151
+ } catch (error) {
152
+ if (error instanceof BackToMenuError) {
153
+ this.args = [];
154
+ return this.parse();
155
+ }
156
+ throw error;
157
+ }
142
158
  },
143
159
  });
144
160
  }
@@ -173,10 +189,19 @@ class InteractiveCLI {
173
189
  if (opt.default !== undefined) continue;
174
190
  if (!opt.choices || !Array.isArray(opt.choices)) continue;
175
191
 
176
- argv[key] = await select({
192
+ const selected = await select({
177
193
  message: `Select ${key.replace(/-/g, " ")}:`,
178
- choices: opt.choices.map((c: string) => ({ name: c, value: c })),
194
+ choices: [
195
+ ...opt.choices.map((c: string) => ({ name: c, value: c })),
196
+ { name: "← Back", value: "__back__" },
197
+ ],
179
198
  });
199
+
200
+ if (selected === "__back__") {
201
+ throw new BackToMenuError();
202
+ }
203
+
204
+ argv[key] = selected;
180
205
  argv[camelKey] = argv[key];
181
206
  }
182
207
  }