Prompt to overwrite non-empty dirs before config

This commit is contained in:
Aman Varshney
2025-05-05 18:54:23 +05:30
parent ff13123bcb
commit 357dfbbbf9
29 changed files with 223 additions and 141 deletions

View File

@@ -8,8 +8,7 @@ import { setupTauri } from "./tauri-setup";
import type { ProjectConfig } from "../types";
export async function setupAddons(config: ProjectConfig) {
const { projectName, addons, frontend } = config;
const projectDir = path.resolve(process.cwd(), projectName);
const { projectName, addons, frontend, projectDir } = config;
const hasReactWebFrontend =
frontend.includes("react-router") || frontend.includes("tanstack-router");
const hasNuxtFrontend = frontend.includes("nuxt");

View File

@@ -5,8 +5,8 @@ import type { ProjectConfig, ProjectFrontend } from "../types";
import { addPackageDependency } from "../utils/add-package-deps";
export async function setupApi(config: ProjectConfig): Promise<void> {
const { api, projectName, frontend, backend, packageManager } = config;
const projectDir = path.resolve(process.cwd(), projectName);
const { api, projectName, frontend, backend, packageManager, projectDir } =
config;
const isConvex = backend === "convex";
const webDir = path.join(projectDir, "apps/web");
const nativeDir = path.join(projectDir, "apps/native");

View File

@@ -6,13 +6,11 @@ import type { ProjectConfig } from "../types";
import { addPackageDependency } from "../utils/add-package-deps";
export async function setupAuth(config: ProjectConfig): Promise<void> {
const { projectName, auth, frontend, backend } = config;
const { projectName, auth, frontend, backend, projectDir } = config;
if (backend === "convex" || !auth) {
return;
}
const projectDir = path.resolve(process.cwd(), projectName);
const serverDir = path.join(projectDir, "apps/server");
const clientDir = path.join(projectDir, "apps/web");
const nativeDir = path.join(projectDir, "apps/native");

View File

@@ -7,13 +7,12 @@ import type { ProjectConfig } from "../types";
export async function setupBackendDependencies(
config: ProjectConfig,
): Promise<void> {
const { projectName, backend, runtime, api } = config;
const { projectName, backend, runtime, api, projectDir } = config;
if (backend === "convex") {
return;
}
const projectDir = path.resolve(process.cwd(), projectName);
const framework = backend;
const serverDir = path.join(projectDir, "apps/server");

View File

@@ -1,5 +1,4 @@
import path from "node:path";
import { cancel, log, spinner } from "@clack/prompts";
import { cancel, log } from "@clack/prompts";
import fs from "fs-extra";
import pc from "picocolors";
import type { ProjectConfig } from "../types";
@@ -27,7 +26,7 @@ import {
} from "./template-manager";
export async function createProject(options: ProjectConfig) {
const projectDir = path.resolve(process.cwd(), options.projectName);
const projectDir = options.projectDir;
const isConvex = options.backend === "convex";
try {

View File

@@ -13,11 +13,10 @@ import { setupNeonPostgres } from "./neon-setup";
import type { ProjectConfig } from "../types";
export async function setupDatabase(config: ProjectConfig): Promise<void> {
const { projectName, database, orm, dbSetup, backend } = config;
const { projectName, database, orm, dbSetup, backend, projectDir } = config;
if (backend === "convex" || database === "none") {
if (backend !== "convex") {
const projectDir = path.resolve(process.cwd(), projectName);
const serverDir = path.join(projectDir, "apps/server");
const serverDbDir = path.join(serverDir, "src/db");
if (await fs.pathExists(serverDbDir)) {
@@ -27,7 +26,6 @@ export async function setupDatabase(config: ProjectConfig): Promise<void> {
return;
}
const projectDir = path.resolve(process.cwd(), projectName);
const s = spinner();
const serverDir = path.join(projectDir, "apps/server");

View File

@@ -65,8 +65,8 @@ export async function setupEnvironmentVariables(
auth,
examples,
dbSetup,
projectDir,
} = config;
const projectDir = path.resolve(process.cwd(), projectName);
const hasReactRouter = frontend.includes("react-router");
const hasTanStackRouter = frontend.includes("tanstack-router");

View File

@@ -5,7 +5,7 @@ import type { ProjectConfig } from "../types";
import { addPackageDependency } from "../utils/add-package-deps";
export async function setupExamples(config: ProjectConfig): Promise<void> {
const { projectName, examples, frontend, backend } = config;
const { projectName, examples, frontend, backend, projectDir } = config;
if (
backend === "convex" ||
@@ -16,8 +16,6 @@ export async function setupExamples(config: ProjectConfig): Promise<void> {
return;
}
const projectDir = path.resolve(process.cwd(), projectName);
if (examples.includes("ai")) {
const clientDir = path.join(projectDir, "apps/web");
const serverDir = path.join(projectDir, "apps/server");

View File

@@ -130,8 +130,7 @@ ${pc.green("MongoDB Atlas Manual Setup Instructions:")}
}
export async function setupMongoDBAtlas(config: ProjectConfig) {
const { projectName } = config;
const projectDir = path.resolve(process.cwd(), projectName);
const { projectName, projectDir } = config;
const mainSpinner = spinner();
mainSpinner.start("Setting up MongoDB Atlas");

View File

@@ -128,8 +128,7 @@ DATABASE_URL="your_connection_string"`);
import type { ProjectConfig } from "../types";
export async function setupNeonPostgres(config: ProjectConfig): Promise<void> {
const { projectName, packageManager } = config;
const projectDir = path.resolve(process.cwd(), projectName);
const { projectName, packageManager, projectDir } = config;
const setupSpinner = spinner();
setupSpinner.start("Setting up Neon PostgreSQL");

View File

@@ -16,6 +16,7 @@ export function displayPostInstallInstructions(
const {
database,
projectName,
relativePath,
packageManager,
depsInstalled,
orm,
@@ -27,7 +28,7 @@ export function displayPostInstallInstructions(
const isConvex = backend === "convex";
const runCmd = packageManager === "npm" ? "npm run" : packageManager;
const cdCmd = `cd ${projectName}`;
const cdCmd = `cd ${relativePath}`;
const hasHuskyOrBiome =
addons?.includes("husky") || addons?.includes("biome");
@@ -76,7 +77,7 @@ export function displayPostInstallInstructions(
!isConvex && database !== "none" && orm === "none" ? getNoOrmWarning() : "";
const hasReactRouter = frontend?.includes("react-router");
const hasSvelte = frontend?.includes("svelte"); // Keep separate for port logic
const hasSvelte = frontend?.includes("svelte");
const webPort = hasReactRouter || hasSvelte ? "5173" : "3001";
const tazeCommand = getPackageExecutionCommand(packageManager, "taze -r");

View File

@@ -154,8 +154,7 @@ export default prisma;
import type { ProjectConfig } from "../types";
export async function setupPrismaPostgres(config: ProjectConfig) {
const { projectName, packageManager } = config;
const projectDir = path.resolve(process.cwd(), projectName);
const { projectName, packageManager, projectDir } = config;
const serverDir = path.join(projectDir, "apps/server");
const s = spinner();
s.start("Setting up Prisma PostgreSQL");

View File

@@ -4,13 +4,12 @@ import type { ProjectBackend, ProjectConfig } from "../types";
import { addPackageDependency } from "../utils/add-package-deps";
export async function setupRuntime(config: ProjectConfig): Promise<void> {
const { projectName, runtime, backend } = config;
const { projectName, runtime, backend, projectDir } = config;
if (backend === "convex" || backend === "next" || runtime === "none") {
return;
}
const projectDir = path.resolve(process.cwd(), projectName);
const serverDir = path.join(projectDir, "apps/server");
if (!(await fs.pathExists(serverDir))) {

View File

@@ -7,8 +7,7 @@ import type { ProjectConfig } from "../types";
import { getPackageExecutionCommand } from "../utils/get-package-execution-command";
export async function setupStarlight(config: ProjectConfig): Promise<void> {
const { projectName, packageManager } = config;
const projectDir = path.resolve(process.cwd(), projectName);
const { projectName, packageManager, projectDir } = config;
const s = spinner();
try {

View File

@@ -10,8 +10,7 @@ import { getPackageExecutionCommand } from "../utils/get-package-execution-comma
import type { ProjectConfig } from "../types";
export async function setupTauri(config: ProjectConfig): Promise<void> {
const { projectName, packageManager, frontend } = config;
const projectDir = path.resolve(process.cwd(), projectName);
const { projectName, packageManager, frontend, projectDir } = config;
const s = spinner();
const clientPackageDir = path.join(projectDir, "apps/web");

View File

@@ -198,8 +198,7 @@ DATABASE_AUTH_TOKEN=your_auth_token`);
import type { ProjectConfig } from "../types";
export async function setupTurso(config: ProjectConfig): Promise<void> {
const { projectName, orm } = config;
const projectDir = path.resolve(process.cwd(), projectName);
const { projectName, orm, projectDir } = config;
const isDrizzle = orm === "drizzle";
const setupSpinner = spinner();
setupSpinner.start("Setting up Turso database");