Add cancelable and validate to start commands · dev-rb/solid-cli@2bc02ca · GitHub
Skip to content

Commit 2bc02ca

Browse files
committed
Add cancelable and validate to start commands
1 parent 7cda456 commit 2bc02ca

5 files changed

Lines changed: 64 additions & 20 deletions

File tree

‎packages/core/src/command_handlers/add.ts‎

Lines changed: 1 addition & 0 deletions

‎packages/core/src/command_handlers/start/adapter.ts‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { writeFile } from "fs/promises";
22
import { transformPlugins } from "../../lib/transform";
33
import * as p from "@clack/prompts";
4+
import { cancelable } from "@solid-cli/ui";
5+
46
export const supportedAdapters = [
57
"aws",
68
"cloudflare-pages",
@@ -11,14 +13,19 @@ export const supportedAdapters = [
1113
"static",
1214
"vercel",
1315
] as const;
16+
1417
type SupportedAdapters = (typeof supportedAdapters)[number];
18+
1519
const handleAutocompleteAdapter = async () => {
16-
const name = (await p.select({
17-
message: "Select an adapter",
18-
options: supportedAdapters.map((a) => ({ value: a, label: a })),
19-
})) as SupportedAdapters;
20+
const name = (await cancelable(
21+
p.select({
22+
message: "Select an adapter",
23+
options: supportedAdapters.map((a) => ({ value: a, label: a })),
24+
}),
25+
)) as SupportedAdapters;
2026
await handleAdapter(name, true);
2127
};
28+
2229
export const handleAdapter = async (name?: string, forceTransform = false) => {
2330
if (!name) {
2431
await handleAutocompleteAdapter();

‎packages/core/src/command_handlers/start/data.ts‎

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,31 @@ import { createData } from "../../lib/start/add_data";
22
import { isSolidStart } from "../../lib/utils/solid_start";
33
import * as p from "@clack/prompts";
44
import { spinnerify } from "../../lib/utils/ui";
5+
import { cancelable } from "@solid-cli/ui";
6+
57
const handleAutocompleteData = async () => {
6-
const path = (
7-
await p.text({ message: "Enter the path in which the data file will be created", placeholder: "/user/login" })
8-
).toString();
9-
const res = (await p.text({
10-
message: "Enter the name for the data file (leave this blank for the default)",
11-
})) as string;
12-
const name = !res ? undefined : res;
8+
const path = await cancelable(
9+
p.text({
10+
message: "Enter the path in which the data file will be created",
11+
placeholder: "/user/login",
12+
validate(value) {
13+
if (!value.length) return "Path is required";
14+
},
15+
}),
16+
);
17+
18+
const name = await cancelable(
19+
p.text({
20+
message: "Enter the name for the data file (leave this blank for the default)",
21+
validate(value) {
22+
if (!value.length) return "Name is required";
23+
},
24+
}),
25+
);
26+
1327
await handleData(path, name);
1428
};
29+
1530
export const handleData = async (path?: string, name?: string) => {
1631
if (!(await isSolidStart())) {
1732
p.log.error("Cannot run command. Your project doesn't include solid-start");

‎packages/core/src/command_handlers/start/mode.ts‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,21 @@ import { writeFile } from "fs/promises";
22
import { transformPlugins } from "../../lib/transform";
33
import { isSolidStart } from "../../lib/utils/solid_start";
44
import * as p from "@clack/prompts";
5+
import { cancelable } from "@solid-cli/ui";
6+
57
export const supportedModes = ["csr", "ssr", "ssg"] as const;
68
type SupportedModes = (typeof supportedModes)[number];
9+
710
const handleAutocompleteMode = async () => {
8-
const mode = (await p.select({
9-
message: "Select a mode",
10-
options: supportedModes.map((a) => ({ value: a, label: a.toUpperCase() })),
11-
})) as SupportedModes;
11+
const mode = (await cancelable(
12+
p.select({
13+
message: "Select a mode",
14+
options: supportedModes.map((a) => ({ value: a, label: a.toUpperCase() })),
15+
}),
16+
)) as SupportedModes;
1217
await handleMode(mode);
1318
};
19+
1420
export const handleMode = async (mode?: SupportedModes) => {
1521
if (!(await isSolidStart())) {
1622
p.log.error("Cannot run command. Your project doesn't include solid-start");

‎packages/core/src/command_handlers/start/route.ts‎

Lines changed: 20 additions & 5 deletions

0 commit comments

Comments
 (0)