diff --git a/packages/full-solid/src/start/index.ts b/packages/full-solid/src/start/index.ts index b56c1d8..62812f7 100644 --- a/packages/full-solid/src/start/index.ts +++ b/packages/full-solid/src/start/index.ts @@ -1,4 +1,4 @@ -import { createRoute } from "@solid-cli/utils"; +import { createApi, createRoute } from "@solid-cli/utils"; import { defineCommand } from "citty"; import * as p from "@clack/prompts"; import { green } from "picocolors"; @@ -6,22 +6,33 @@ import { cancelable } from "@solid-cli/utils/ui" export const startCommands = defineCommand({ meta: { description: "Start-specific commands" }, subCommands: { route: defineCommand({ + meta: { description: "Creates a new route" }, args: { path: { type: "positional", required: false, - description: "Route name", + description: "Route path", }, + api: { + type: "boolean", + required: false, + default: false, + alias: "a" + } }, - async run({ args: { path } }) { + async run({ args: { path, api } }) { path ||= await cancelable(p.text({ - message: "Route name", validate(value) { - if (value.length === 0) return "A route name is required" + message: "Route path", validate(value) { + if (value.length === 0) return "A route path is required" }, })) - await createRoute(path as string); + if (api) { + await createApi(path as string); + } else { + await createRoute(path as string); + } p.log.success(`Route ${green(path as string)} successfully created!`) }, - }) + }), } }); diff --git a/packages/utils/src/start/add_api.ts b/packages/utils/src/start/add_api.ts index 41fbf35..98ec483 100644 --- a/packages/utils/src/start/add_api.ts +++ b/packages/utils/src/start/add_api.ts @@ -8,7 +8,7 @@ export const createApi = async (path: string, name?: string) => { await mkdir(path_parts.join("/"), { recursive: true }); - path_parts.push(name ? `${name}.ts` : "hello.ts"); + path_parts.push(name ? `${name}.ts` : "index.ts"); await writeChecked(path_parts.join("/"), ""); };