feat: add ai chat example and update flags structure

This commit is contained in:
Aman Varshney
2025-03-31 22:52:21 +05:30
parent d6c4127bf5
commit a6ac5dc86c
32 changed files with 485 additions and 263 deletions

View File

@@ -1,14 +1,14 @@
import { cancel, isCancel, select } from "@clack/prompts";
import pc from "picocolors";
import { DEFAULT_CONFIG } from "../constants";
import type { BackendFramework } from "../types";
import type { ProjectBackend } from "../types";
export async function getBackendFrameworkChoice(
backendFramework?: BackendFramework,
): Promise<BackendFramework> {
backendFramework?: ProjectBackend,
): Promise<ProjectBackend> {
if (backendFramework !== undefined) return backendFramework;
const response = await select<BackendFramework>({
const response = await select<ProjectBackend>({
message: "Which backend framework would you like to use?",
options: [
{
@@ -22,7 +22,7 @@ export async function getBackendFrameworkChoice(
hint: "TypeScript framework with end-to-end type safety)",
},
],
initialValue: DEFAULT_CONFIG.backendFramework,
initialValue: DEFAULT_CONFIG.backend,
});
if (isCancel(response)) {

View File

@@ -1,15 +1,15 @@
import { cancel, group } from "@clack/prompts";
import pc from "picocolors";
import type {
BackendFramework,
PackageManager,
ProjectAddons,
ProjectBackend,
ProjectConfig,
ProjectDatabase,
ProjectExamples,
ProjectFrontend,
ProjectOrm,
Runtime,
ProjectPackageManager,
ProjectRuntime,
} from "../types";
import { getAddonsChoice } from "./addons";
import { getAuthChoice } from "./auth";
@@ -33,11 +33,11 @@ type PromptGroupResults = {
addons: ProjectAddons[];
examples: ProjectExamples[];
git: boolean;
packageManager: PackageManager;
packageManager: ProjectPackageManager;
noInstall: boolean;
turso: boolean;
backendFramework: BackendFramework;
runtime: Runtime;
backend: ProjectBackend;
runtime: ProjectRuntime;
frontend: ProjectFrontend[];
};
@@ -50,7 +50,7 @@ export async function gatherConfig(
return getProjectName(flags.projectName);
},
frontend: () => getFrontendChoice(flags.frontend),
backendFramework: () => getBackendFrameworkChoice(flags.backendFramework),
backend: () => getBackendFrameworkChoice(flags.backend),
runtime: () => getRuntimeChoice(flags.runtime),
database: () => getDatabaseChoice(flags.database),
orm: ({ results }) =>
@@ -67,7 +67,12 @@ export async function gatherConfig(
: Promise.resolve(false),
addons: ({ results }) => getAddonsChoice(flags.addons, results.frontend),
examples: ({ results }) =>
getExamplesChoice(flags.examples, results.database, results.frontend),
getExamplesChoice(
flags.examples,
results.database,
results.frontend,
results.backend,
),
git: () => getGitChoice(flags.git),
packageManager: () => getPackageManagerChoice(flags.packageManager),
noInstall: () => getNoInstallChoice(flags.noInstall),
@@ -92,7 +97,7 @@ export async function gatherConfig(
packageManager: result.packageManager,
noInstall: result.noInstall,
turso: result.turso,
backendFramework: result.backendFramework,
backend: result.backend,
runtime: result.runtime,
};
}

View File

@@ -2,6 +2,7 @@ import { cancel, isCancel, multiselect } from "@clack/prompts";
import pc from "picocolors";
import { DEFAULT_CONFIG } from "../constants";
import type {
ProjectBackend,
ProjectDatabase,
ProjectExamples,
ProjectFrontend,
@@ -11,6 +12,7 @@ export async function getExamplesChoice(
examples?: ProjectExamples[],
database?: ProjectDatabase,
frontends?: ProjectFrontend[],
backend?: ProjectBackend,
): Promise<ProjectExamples[]> {
if (examples !== undefined) return examples;
@@ -19,18 +21,42 @@ export async function getExamplesChoice(
const hasWebFrontend = frontends?.includes("web");
if (!hasWebFrontend) return [];
const response = await multiselect<ProjectExamples>({
message: "Which examples would you like to include?",
options: [
{
value: "todo",
label: "Todo App",
hint: "A simple CRUD example app",
},
],
required: false,
initialValues: DEFAULT_CONFIG.examples,
});
let response: ProjectExamples[] | symbol = [];
if (backend === "elysia") {
response = await multiselect<ProjectExamples>({
message: "Which examples would you like to include?",
options: [
{
value: "todo",
label: "Todo App",
hint: "A simple CRUD example app",
},
],
required: false,
initialValues: DEFAULT_CONFIG.examples,
});
}
if (backend === "hono") {
response = await multiselect<ProjectExamples>({
message: "Which examples would you like to include?",
options: [
{
value: "todo",
label: "Todo App",
hint: "A simple CRUD example app",
},
{
value: "ai",
label: "AI Chat",
hint: "A simple AI chat interface using AI SDK",
},
],
required: false,
initialValues: DEFAULT_CONFIG.examples,
});
}
if (isCancel(response)) {
cancel(pc.red("Operation cancelled"));

View File

@@ -1,16 +1,16 @@
import { cancel, isCancel, select } from "@clack/prompts";
import pc from "picocolors";
import type { PackageManager, Runtime } from "../types";
import type { ProjectPackageManager, ProjectRuntime } from "../types";
import { getUserPkgManager } from "../utils/get-package-manager";
export async function getPackageManagerChoice(
packageManager?: PackageManager,
): Promise<PackageManager> {
packageManager?: ProjectPackageManager,
): Promise<ProjectPackageManager> {
if (packageManager !== undefined) return packageManager;
const detectedPackageManager = getUserPkgManager();
const response = await select<PackageManager>({
const response = await select<ProjectPackageManager>({
message: "Which package manager do you want to use?",
options: [
{ value: "npm", label: "npm", hint: "Node Package Manager" },

View File

@@ -1,12 +1,14 @@
import { cancel, isCancel, select } from "@clack/prompts";
import pc from "picocolors";
import { DEFAULT_CONFIG } from "../constants";
import type { Runtime } from "../types";
import type { ProjectRuntime } from "../types";
export async function getRuntimeChoice(runtime?: Runtime): Promise<Runtime> {
export async function getRuntimeChoice(
runtime?: ProjectRuntime,
): Promise<ProjectRuntime> {
if (runtime !== undefined) return runtime;
const response = await select<Runtime>({
const response = await select<ProjectRuntime>({
message: "Which runtime would you like to use?",
options: [
{