|
1 | | -import { select, text } from "./prompts"; |
| 1 | +import * as clack from "@clack/prompts"; |
2 | 2 |
|
3 | 3 | /** Platform option metadata shown in the setup wizard. */ |
4 | 4 | export const PLATFORMS = [ |
@@ -57,33 +57,51 @@ export interface WizardAnswers { |
57 | 57 | port: string; |
58 | 58 | } |
59 | 59 |
|
| 60 | +function handleCancel(value: unknown): void { |
| 61 | + if (!clack.isCancel(value)) return; |
| 62 | + clack.cancel("cancelled"); |
| 63 | + process.exit(0); |
| 64 | +} |
| 65 | + |
60 | 66 | /** Runs the interactive setup wizard. */ |
61 | 67 | export async function askQuestions(): Promise<WizardAnswers> { |
62 | | - const platform = await select<Platform>( |
63 | | - "which platform are you integrating?", |
64 | | - PLATFORMS, |
65 | | - ); |
| 68 | + const platform = await clack.select<Platform>({ |
| 69 | + message: "which platform are you integrating?", |
| 70 | + options: [...PLATFORMS], |
| 71 | + }); |
| 72 | + handleCancel(platform); |
66 | 73 |
|
67 | | - const framework = await select<Framework>( |
68 | | - "which framework are you using?", |
69 | | - FRAMEWORKS, |
70 | | - ); |
| 74 | + const framework = await clack.select<Framework>({ |
| 75 | + message: "which framework are you using?", |
| 76 | + options: [...FRAMEWORKS], |
| 77 | + }); |
| 78 | + handleCancel(framework); |
71 | 79 |
|
72 | | - const action = await select<Action>("what would you like to do?", [ |
73 | | - { value: "both", label: "set up webhook handler + test locally" }, |
74 | | - { value: "handler", label: "set up webhook handler only" }, |
75 | | - { value: "tunnel", label: "test locally only" }, |
76 | | - ]); |
| 80 | + const action = await clack.select<Action>({ |
| 81 | + message: "what would you like to do?", |
| 82 | + options: [ |
| 83 | + { value: "both", label: "set up webhook handler + test locally" }, |
| 84 | + { value: "handler", label: "set up webhook handler only" }, |
| 85 | + { value: "tunnel", label: "test locally only" }, |
| 86 | + ], |
| 87 | + }); |
| 88 | + handleCancel(action); |
77 | 89 |
|
78 | 90 | let port = "3000"; |
79 | 91 | if (action !== "handler") { |
80 | | - port = await text("which port is your app running on?", "3000", (v: string) => { |
81 | | - const n = Number(v); |
82 | | - if (!Number.isInteger(n) || n < 1 || n > 65535) { |
83 | | - return "enter a valid port number"; |
84 | | - } |
85 | | - return undefined; |
| 92 | + const entered = await clack.text({ |
| 93 | + message: "which port is your app running on?", |
| 94 | + placeholder: "3000", |
| 95 | + defaultValue: "3000", |
| 96 | + validate: (v: string) => { |
| 97 | + const n = Number(v); |
| 98 | + if (!Number.isInteger(n) || n < 1 || n > 65535) |
| 99 | + return "enter a valid port number"; |
| 100 | + return undefined; |
| 101 | + }, |
86 | 102 | }); |
| 103 | + handleCancel(entered); |
| 104 | + port = entered; |
87 | 105 | } |
88 | 106 |
|
89 | 107 | return { platform, framework, action, port }; |
|
0 commit comments