Skip to content

Commit de5fa73

Browse files
committed
refactor: move cancelable and spinnerify into @solid-cli/utils
feat: add interactive prompt for `route` subcommand
1 parent 2cfc25b commit de5fa73

File tree

6 files changed

+31
-17
lines changed

6 files changed

+31
-17
lines changed

packages/create/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { defineCommand } from "citty";
22
import { createVanilla } from "./create-vanilla";
33
import * as p from "@clack/prompts";
4-
import { cancelable, spinnerify } from "./utils/ui";
4+
import { cancelable, spinnerify } from "@solid-cli/utils/ui";
55
import { createStart } from "./create-start";
66
import { getTemplatesList, StartTemplate, VanillaTemplate } from "./utils/constants";
77
import { detectPackageManager } from "@solid-cli/utils/package-manager";

packages/full-solid/src/start/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { createRoute } from "@solid-cli/utils";
22
import { defineCommand } from "citty";
33
import * as p from "@clack/prompts";
44
import { green } from "picocolors";
5+
import { cancelable } from "@solid-cli/utils/ui"
56
export const startCommands = defineCommand({
67
meta: { description: "Start-specific commands" }, subCommands: {
78
route: defineCommand({
@@ -13,6 +14,11 @@ export const startCommands = defineCommand({
1314
},
1415
},
1516
async run({ args: { path } }) {
17+
path ||= await cancelable(p.text({
18+
message: "Route name", validate(value) {
19+
if (value.length === 0) return "A route name is required"
20+
},
21+
}))
1622
await createRoute(path as string);
1723
p.log.success(`Route ${green(path as string)} successfully created!`)
1824
},

packages/utils/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@
5555
"types": "./types/package-manager/index.d.ts",
5656
"import": "./dist/package-manager/index.mjs",
5757
"require": "./dist/package-manager/index.mjs"
58+
},
59+
"./ui": {
60+
"types": "./types/ui/index.d.ts",
61+
"import": "./dist/ui/index.mjs",
62+
"require": "./dist/ui/index.mjs"
5863
}
5964
},
6065
"scripts": {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { log } from "@clack/prompts";
2+
export const cancelable = async <T = unknown>(
3+
prompt: Promise<T | symbol>,
4+
cancelMessage: string = "Canceled",
5+
): Promise<T> => {
6+
const value = await prompt;
7+
8+
if (typeof value === "symbol") {
9+
log.warn(cancelMessage);
10+
process.exit(0);
11+
}
12+
13+
return value;
14+
};

packages/utils/src/ui/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { cancelable } from "./cancelable";
2+
import { spinnerify } from "./spinnerify";
3+
export { cancelable, spinnerify }
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { log, spinner } from "@clack/prompts";
1+
import { spinner } from "@clack/prompts";
22
type SpinnerItem<T> = {
33
startText: string;
44
finishText: string;
@@ -16,18 +16,4 @@ export async function spinnerify<T>(spinners: SpinnerItem<any>[] | SpinnerItem<T
1616
s.stop(finishText);
1717
}
1818
return results.length === 1 ? results[0] : results;
19-
}
20-
21-
export const cancelable = async <T = unknown>(
22-
prompt: Promise<T | symbol>,
23-
cancelMessage: string = "Canceled",
24-
): Promise<T> => {
25-
const value = await prompt;
26-
27-
if (typeof value === "symbol") {
28-
log.warn(cancelMessage);
29-
process.exit(0);
30-
}
31-
32-
return value;
33-
};
19+
}

0 commit comments

Comments
 (0)