Skip to content

Commit

Permalink
feat: route command can now also add API routes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tommypop2 committed Jan 24, 2025
1 parent ea71f17 commit efa5262
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
25 changes: 18 additions & 7 deletions packages/full-solid/src/start/index.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,38 @@
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";
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!`)
},
})
}),
}
});
2 changes: 1 addition & 1 deletion packages/utils/src/start/add_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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("/"), "");
};

0 comments on commit efa5262

Please sign in to comment.