-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:
route
command can now also add API routes
- Loading branch information
Showing
2 changed files
with
19 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!`) | ||
}, | ||
}) | ||
}), | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters