cli: organize file structure

This commit is contained in:
Aman Varshney
2025-05-26 00:13:08 +05:30
parent b9c9690e61
commit 1e9c6b2210
40 changed files with 900 additions and 928 deletions

View File

@@ -1,18 +1,18 @@
import { cancel, isCancel, multiselect } from "@clack/prompts";
import pc from "picocolors";
import { DEFAULT_CONFIG } from "../constants";
import type { ProjectAddons, ProjectFrontend } from "../types";
import type { Addons, Frontend } from "../types";
type AddonOption = {
value: ProjectAddons;
value: Addons;
label: string;
hint: string;
};
export async function getAddonsChoice(
addons?: ProjectAddons[],
frontends?: ProjectFrontend[],
): Promise<ProjectAddons[]> {
addons?: Addons[],
frontends?: Frontend[],
): Promise<Addons[]> {
if (addons !== undefined) return addons;
const hasCompatiblePwaFrontend =

View File

@@ -1,12 +1,12 @@
import { cancel, isCancel, select } from "@clack/prompts";
import pc from "picocolors";
import type { ProjectApi, ProjectBackend, ProjectFrontend } from "../types";
import type { API, Backend, Frontend } from "../types";
export async function getApiChoice(
Api?: ProjectApi | undefined,
frontend?: ProjectFrontend[],
backend?: ProjectBackend,
): Promise<ProjectApi> {
Api?: API | undefined,
frontend?: Frontend[],
backend?: Backend,
): Promise<API> {
if (backend === "convex" || backend === "none") {
return "none";
}
@@ -52,7 +52,7 @@ export async function getApiChoice(
];
}
const apiType = await select<ProjectApi>({
const apiType = await select<API>({
message: "Select API type",
options: apiOptions,
initialValue: apiOptions[0].value,

View File

@@ -1,12 +1,12 @@
import { cancel, confirm, isCancel } from "@clack/prompts";
import pc from "picocolors";
import { DEFAULT_CONFIG } from "../constants";
import type { ProjectBackend } from "../types";
import type { Backend } from "../types";
export async function getAuthChoice(
auth: boolean | undefined,
hasDatabase: boolean,
backend?: ProjectBackend,
backend?: Backend,
): Promise<boolean> {
if (backend === "convex") {
return false;

View File

@@ -1,12 +1,12 @@
import { cancel, isCancel, select } from "@clack/prompts";
import pc from "picocolors";
import { DEFAULT_CONFIG } from "../constants";
import type { ProjectBackend, ProjectFrontend } from "../types";
import type { Backend, Frontend } from "../types";
export async function getBackendFrameworkChoice(
backendFramework?: ProjectBackend,
frontends?: ProjectFrontend[],
): Promise<ProjectBackend> {
backendFramework?: Backend,
frontends?: Frontend[],
): Promise<Backend> {
if (backendFramework !== undefined) return backendFramework;
const hasIncompatibleFrontend = frontends?.some(
@@ -14,7 +14,7 @@ export async function getBackendFrameworkChoice(
);
const backendOptions: Array<{
value: ProjectBackend;
value: Backend;
label: string;
hint: string;
}> = [
@@ -26,7 +26,7 @@ export async function getBackendFrameworkChoice(
{
value: "next" as const,
label: "Next.js",
hint: "Full-stack framework with API routes",
hint: "Nextjs API routes",
},
{
value: "express" as const,
@@ -56,7 +56,7 @@ export async function getBackendFrameworkChoice(
backendOptions.push({
value: "none" as const,
label: "None",
hint: "No backend server (e.g., for a static site or client-only app)",
hint: "No backend server",
});
let initialValue = DEFAULT_CONFIG.backend;
@@ -64,8 +64,8 @@ export async function getBackendFrameworkChoice(
initialValue = "hono";
}
const response = await select<ProjectBackend>({
message: "Select backend framework",
const response = await select<Backend>({
message: "Select backend",
options: backendOptions,
initialValue,
});

View File

@@ -1,26 +1,26 @@
import { cancel, group } from "@clack/prompts";
import pc from "picocolors";
import type {
ProjectAddons,
ProjectApi,
ProjectBackend,
API,
Addons,
Backend,
Database,
DatabaseSetup,
Examples,
Frontend,
ORM,
PackageManager,
ProjectConfig,
ProjectDBSetup,
ProjectDatabase,
ProjectExamples,
ProjectFrontend,
ProjectOrm,
ProjectPackageManager,
ProjectRuntime,
Runtime,
} from "../types";
import { getAddonsChoice } from "./addons";
import { getApiChoice } from "./api";
import { getAuthChoice } from "./auth";
import { getBackendFrameworkChoice } from "./backend-framework";
import { getBackendFrameworkChoice } from "./backend";
import { getDatabaseChoice } from "./database";
import { getDBSetupChoice } from "./db-setup";
import { getDBSetupChoice } from "./database-setup";
import { getExamplesChoice } from "./examples";
import { getFrontendChoice } from "./frontend-option";
import { getFrontendChoice } from "./frontend";
import { getGitChoice } from "./git";
import { getinstallChoice } from "./install";
import { getORMChoice } from "./orm";
@@ -28,18 +28,18 @@ import { getPackageManagerChoice } from "./package-manager";
import { getRuntimeChoice } from "./runtime";
type PromptGroupResults = {
frontend: ProjectFrontend[];
backend: ProjectBackend;
runtime: ProjectRuntime;
database: ProjectDatabase;
orm: ProjectOrm;
api: ProjectApi;
frontend: Frontend[];
backend: Backend;
runtime: Runtime;
database: Database;
orm: ORM;
api: API;
auth: boolean;
addons: ProjectAddons[];
examples: ProjectExamples[];
dbSetup: ProjectDBSetup;
addons: Addons[];
examples: Examples[];
dbSetup: DatabaseSetup;
git: boolean;
packageManager: ProjectPackageManager;
packageManager: PackageManager;
install: boolean;
};

View File

@@ -1,18 +1,18 @@
import { cancel, isCancel, select } from "@clack/prompts";
import pc from "picocolors";
import type { ProjectBackend, ProjectDBSetup, ProjectOrm } from "../types";
import type { Backend, DatabaseSetup, ORM } from "../types";
export async function getDBSetupChoice(
databaseType: string,
dbSetup: ProjectDBSetup | undefined,
orm?: ProjectOrm,
backend?: ProjectBackend,
): Promise<ProjectDBSetup> {
dbSetup: DatabaseSetup | undefined,
orm?: ORM,
backend?: Backend,
): Promise<DatabaseSetup> {
if (backend === "convex") {
return "none";
}
if (dbSetup !== undefined) return dbSetup as ProjectDBSetup;
if (dbSetup !== undefined) return dbSetup as DatabaseSetup;
if (databaseType === "none") {
return "none";
@@ -22,7 +22,7 @@ export async function getDBSetupChoice(
return "none";
}
let options: Array<{ value: ProjectDBSetup; label: string; hint: string }> =
let options: Array<{ value: DatabaseSetup; label: string; hint: string }> =
[];
if (databaseType === "sqlite") {
@@ -70,7 +70,7 @@ export async function getDBSetupChoice(
return "none";
}
const response = await select<ProjectDBSetup>({
const response = await select<DatabaseSetup>({
message: `Select ${databaseType} setup option`,
options,
initialValue: "none",

View File

@@ -1,19 +1,19 @@
import { cancel, isCancel, select } from "@clack/prompts";
import pc from "picocolors";
import { DEFAULT_CONFIG } from "../constants";
import type { ProjectBackend, ProjectDatabase } from "../types";
import type { Backend, Database } from "../types";
export async function getDatabaseChoice(
database?: ProjectDatabase,
backend?: ProjectBackend,
): Promise<ProjectDatabase> {
database?: Database,
backend?: Backend,
): Promise<Database> {
if (backend === "convex" || backend === "none") {
return "none";
}
if (database !== undefined) return database;
const response = await select<ProjectDatabase>({
const response = await select<Database>({
message: "Select database",
options: [
{

View File

@@ -1,21 +1,15 @@
import { cancel, isCancel, multiselect } from "@clack/prompts";
import pc from "picocolors";
import { DEFAULT_CONFIG } from "../constants";
import type {
ProjectApi,
ProjectBackend,
ProjectDatabase,
ProjectExamples,
ProjectFrontend,
} from "../types";
import type { API, Backend, Database, Examples, Frontend } from "../types";
export async function getExamplesChoice(
examples?: ProjectExamples[],
database?: ProjectDatabase,
frontends?: ProjectFrontend[],
backend?: ProjectBackend,
api?: ProjectApi,
): Promise<ProjectExamples[]> {
examples?: Examples[],
database?: Database,
frontends?: Frontend[],
backend?: Backend,
api?: API,
): Promise<Examples[]> {
if (api === "none") {
return [];
}
@@ -56,8 +50,8 @@ export async function getExamplesChoice(
if (!hasWebFrontend && !noFrontendSelected) return [];
let response: ProjectExamples[] | symbol = [];
const options: { value: ProjectExamples; label: string; hint: string }[] = [
let response: Examples[] | symbol = [];
const options: { value: Examples; label: string; hint: string }[] = [
{
value: "todo" as const,
label: "Todo App",
@@ -73,7 +67,7 @@ export async function getExamplesChoice(
});
}
response = await multiselect<ProjectExamples>({
response = await multiselect<Examples>({
message: "Include examples",
options: options,
required: false,

View File

@@ -1,12 +1,12 @@
import { cancel, isCancel, multiselect, select } from "@clack/prompts";
import pc from "picocolors";
import { DEFAULT_CONFIG } from "../constants";
import type { ProjectBackend, ProjectFrontend } from "../types";
import type { Backend, Frontend } from "../types";
export async function getFrontendChoice(
frontendOptions?: ProjectFrontend[],
backend?: ProjectBackend,
): Promise<ProjectFrontend[]> {
frontendOptions?: Frontend[],
backend?: Backend,
): Promise<Frontend[]> {
if (frontendOptions !== undefined) return frontendOptions;
const frontendTypes = await multiselect({
@@ -32,7 +32,7 @@ export async function getFrontendChoice(
process.exit(0);
}
const result: ProjectFrontend[] = [];
const result: Frontend[] = [];
if (frontendTypes.includes("web")) {
const allWebOptions = [
@@ -80,8 +80,8 @@ export async function getFrontendChoice(
return true;
});
const webFramework = await select<ProjectFrontend>({
message: "Choose frontend framework",
const webFramework = await select<Frontend>({
message: "Choose frontend",
options: webOptions,
initialValue: DEFAULT_CONFIG.frontend[0],
});
@@ -95,7 +95,7 @@ export async function getFrontendChoice(
}
if (frontendTypes.includes("native")) {
const nativeFramework = await select<ProjectFrontend>({
const nativeFramework = await select<Frontend>({
message: "Choose native framework",
options: [
{

View File

@@ -1,7 +1,7 @@
import { cancel, isCancel, select } from "@clack/prompts";
import pc from "picocolors";
import { DEFAULT_CONFIG } from "../constants";
import type { ProjectBackend, ProjectDatabase, ProjectOrm } from "../types";
import type { Backend, Database, ORM } from "../types";
const ormOptions = {
prisma: {
@@ -22,11 +22,11 @@ const ormOptions = {
};
export async function getORMChoice(
orm: ProjectOrm | undefined,
orm: ORM | undefined,
hasDatabase: boolean,
database?: ProjectDatabase,
backend?: ProjectBackend,
): Promise<ProjectOrm> {
database?: Database,
backend?: Backend,
): Promise<ORM> {
if (backend === "convex") {
return "none";
}
@@ -40,7 +40,7 @@ export async function getORMChoice(
: [ormOptions.drizzle, ormOptions.prisma]),
];
const response = await select<ProjectOrm>({
const response = await select<ORM>({
message: "Select ORM",
options,
initialValue: database === "mongodb" ? "prisma" : DEFAULT_CONFIG.orm,

View File

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

View File

@@ -1,12 +1,12 @@
import { cancel, isCancel, select } from "@clack/prompts";
import pc from "picocolors";
import { DEFAULT_CONFIG } from "../constants";
import type { ProjectBackend, ProjectRuntime } from "../types";
import type { Backend, Runtime } from "../types";
export async function getRuntimeChoice(
runtime?: ProjectRuntime,
backend?: ProjectBackend,
): Promise<ProjectRuntime> {
runtime?: Runtime,
backend?: Backend,
): Promise<Runtime> {
if (backend === "convex" || backend === "none") {
return "none";
}
@@ -17,7 +17,7 @@ export async function getRuntimeChoice(
return "node";
}
const response = await select<ProjectRuntime>({
const response = await select<Runtime>({
message: "Select runtime",
options: [
{