Skip to content

Commit

Permalink
updated prompts for generate
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoalbanese committed Dec 15, 2023
1 parent b4c755f commit 11b1d0e
Showing 1 changed file with 123 additions and 23 deletions.
146 changes: 123 additions & 23 deletions src/commands/generate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,55 @@ type TResource =
| "views_and_components_server_actions"
| "server_actions";

type TResourceGroup = "model" | "controller" | "view";

async function askForResourceType() {
const { packages, orm } = readConfigFile();

const resourcesRequested = (await checkbox({
// const resourcesRequested = (await checkbox({
// message: "Please select the resources you would like to generate:",
// choices: [
// {
// name: "Model",
// value: "model",
// disabled:
// orm === null
// ? "[You need to have an orm installed. Run 'kirimase add']"
// : false,
// },
// { name: "API Route", value: "api_route" },
// {
// name: "TRPC Route",
// value: "trpc_route",
// disabled: !packages.includes("trpc")
// ? "[You need to have trpc installed. Run 'kirimase add']"
// : false,
// },
// {
// name: "Views + Components (with Shadcn UI, requires TRPC route)",
// value: "views_and_components_trpc",
// disabled:
// !packages.includes("shadcn-ui") || !packages.includes("trpc")
// ? "[You need to have shadcn-ui and trpc installed. Run 'kirimase add']"
// : false,
// },
// {
// name: "Server Actions",
// value: "server_actions",
// },
// {
// name: "Views + Components (with server actions)",
// value: "views_and_components_server_actions",
// },
// ],
// })) as TResource[];
// return resourcesRequested;
// }

let resourcesRequested: TResource[] = [];
let viewRequested: TResource;
let controllersRequested: TResource[];
const resourcesTypesRequested = (await checkbox({
message: "Please select the resources you would like to generate:",
choices: [
{
Expand All @@ -54,32 +99,87 @@ async function askForResourceType() {
? "[You need to have an orm installed. Run 'kirimase add']"
: false,
},
{ name: "API Route", value: "api_route" },
{ name: "Controller", value: "controller" },
{
name: "TRPC Route",
value: "trpc_route",
disabled: !packages.includes("trpc")
? "[You need to have trpc installed. Run 'kirimase add']"
name: "View",
value: "view",
disabled: !packages.includes("shadcn-ui")
? "[You need to have shadcn-ui installed. Run 'kirimase add']"
: false,
},
{
name: "Views + Components (with Shadcn UI, requires TRPC route)",
value: "views_and_components_trpc",
disabled:
!packages.includes("shadcn-ui") || !packages.includes("trpc")
? "[You need to have shadcn-ui and trpc installed. Run 'kirimase add']"
: false,
},
{
name: "Server Actions",
value: "server_actions",
},
{
name: "Views + Components (with server actions)",
value: "views_and_components_server_actions",
},
],
})) as TResource[];
})) as TResourceGroup[];

if (resourcesTypesRequested.includes("model"))
resourcesRequested.push("model");

if (resourcesTypesRequested.includes("view")) {
viewRequested = (await select({
message: "Please select the type of view you would like to generate:",
choices: [
{
name: "Server Actions with Optimistic UI",
value: "views_and_components_server_actions",
},
{
name: "tRPC with React Hook Form",
value: "views_and_components_trpc",
disabled: !packages.includes("trpc")
? "[You need to have tRPC installed. Run 'kirimase add']"
: false,
},
],
})) as TResource;
if (
viewRequested === "views_and_components_server_actions" &&
resourcesTypesRequested.includes("controller")
)
resourcesRequested.push("server_actions");
if (
viewRequested === "views_and_components_trpc" &&
resourcesTypesRequested.includes("controller")
)
resourcesRequested.push("trpc_route");
}

if (resourcesTypesRequested.includes("controller")) {
controllersRequested = (await checkbox({
message: viewRequested
? "Please select any additional controllers you would like to generate:"
: "Please select which controllers you would like to generate:",
choices: [
{
name: "Server Actions",
value: "server_actions",
disabled:
viewRequested === "views_and_components_server_actions"
? "[Already generated with your selected view]"
: false,
},
{
name: "API Route",
value: "api_route",
},
{
name: "tRPC",
value: "trpc_route",
disabled: !packages.includes("trpc")
? "[You need to have tRPC installed. Run 'kirimase add']"
: viewRequested === "views_and_components_trpc"
? "[Already generated with your selected view]"
: false,
},
].filter((item) =>
viewRequested
? !viewRequested.includes(item.value.split("_")[0])
: item,
),
})) as TResource[];
}

viewRequested && resourcesRequested.push(viewRequested);
controllersRequested && resourcesRequested.push(...controllersRequested);

return resourcesRequested;
}

Expand Down

0 comments on commit 11b1d0e

Please sign in to comment.