easc 0.0.24 → 0.0.26
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/index.ts +1 -1
- package/package.json +1 -1
- package/src/utils/cli.ts +22 -5
package/index.ts
CHANGED
|
@@ -8,9 +8,9 @@ import { update } from "./src/commands/update";
|
|
|
8
8
|
cli(hideBin(process.argv))
|
|
9
9
|
.scriptName("easc")
|
|
10
10
|
.usage("$0 <command> [options]")
|
|
11
|
+
.command(update)
|
|
11
12
|
.command(build)
|
|
12
13
|
.command(buildRun)
|
|
13
|
-
.command(update)
|
|
14
14
|
.demandCommand(1, "")
|
|
15
15
|
.help()
|
|
16
16
|
.alias("help", "h")
|
package/package.json
CHANGED
package/src/utils/cli.ts
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import yargs, { type Argv, type CommandModule, type Options } from "yargs";
|
|
2
|
-
import { select } from "@inquirer/prompts";
|
|
2
|
+
import { select, Separator } 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;
|
|
@@ -114,6 +122,7 @@ class InteractiveCLI {
|
|
|
114
122
|
name: `${cmd.command.padEnd(12)} ${cmd.describe}`,
|
|
115
123
|
value: cmd.command,
|
|
116
124
|
})),
|
|
125
|
+
new Separator(),
|
|
117
126
|
{ name: "Exit", value: "exit" },
|
|
118
127
|
],
|
|
119
128
|
});
|
|
@@ -137,8 +146,16 @@ class InteractiveCLI {
|
|
|
137
146
|
return y;
|
|
138
147
|
},
|
|
139
148
|
handler: async (argv: any) => {
|
|
140
|
-
|
|
141
|
-
|
|
149
|
+
try {
|
|
150
|
+
await this._promptForMissingArgs(argv, cmd.options);
|
|
151
|
+
return cmd.handler(argv);
|
|
152
|
+
} catch (error) {
|
|
153
|
+
if (error instanceof BackToMenuError) {
|
|
154
|
+
this.args = [];
|
|
155
|
+
return this.parse();
|
|
156
|
+
}
|
|
157
|
+
throw error;
|
|
158
|
+
}
|
|
142
159
|
},
|
|
143
160
|
});
|
|
144
161
|
}
|
|
@@ -177,13 +194,13 @@ class InteractiveCLI {
|
|
|
177
194
|
message: `Select ${key.replace(/-/g, " ")}:`,
|
|
178
195
|
choices: [
|
|
179
196
|
...opt.choices.map((c: string) => ({ name: c, value: c })),
|
|
197
|
+
new Separator(),
|
|
180
198
|
{ name: "← Back", value: "__back__" },
|
|
181
199
|
],
|
|
182
200
|
});
|
|
183
201
|
|
|
184
202
|
if (selected === "__back__") {
|
|
185
|
-
|
|
186
|
-
return this.parse();
|
|
203
|
+
throw new BackToMenuError();
|
|
187
204
|
}
|
|
188
205
|
|
|
189
206
|
argv[key] = selected;
|