Skip to content

Commit 98a0ab9

Browse files
chore(cli): add tests (#576)
1 parent d39fa6e commit 98a0ab9

29 files changed

+5720
-4611
lines changed

apps/cli/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@
5252
"dev": "tsdown --watch",
5353
"check-types": "tsc --noEmit",
5454
"check": "biome check --write .",
55-
"test": "bun run build && vitest run",
55+
"test": "bun run build && vitest run; rm -rf .smoke || true",
5656
"test:ui": "bun run build && vitest --ui",
57-
"test:with-build": "bun run build && WITH_BUILD=1 vitest --ui",
5857
"prepublishOnly": "npm run build"
5958
},
6059
"exports": {
@@ -87,4 +86,4 @@
8786
"typescript": "^5.9.2",
8887
"vitest": "^3.2.4"
8988
}
90-
}
89+
}

apps/cli/src/helpers/core/command-handlers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ export async function createProjectHandler(
174174
);
175175
}
176176

177-
await createProject(config);
177+
await createProject(config, { manualDb: input.manualDb });
178178

179179
const reproducibleCommand = generateReproducibleCommand(config);
180180
log.success(

apps/cli/src/helpers/core/create-project.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ import {
3232
setupFrontendTemplates,
3333
} from "./template-manager";
3434

35-
export async function createProject(options: ProjectConfig) {
35+
export async function createProject(
36+
options: ProjectConfig,
37+
cliInput?: { manualDb?: boolean },
38+
) {
3639
const projectDir = options.projectDir;
3740
const isConvex = options.backend === "convex";
3841

@@ -58,7 +61,7 @@ export async function createProject(options: ProjectConfig) {
5861

5962
if (!isConvex) {
6063
await setupBackendDependencies(options);
61-
await setupDatabase(options);
64+
await setupDatabase(options, cliInput);
6265
await setupRuntime(options);
6366
if (options.examples.length > 0 && options.examples[0] !== "none") {
6467
await setupExamples(options);

apps/cli/src/helpers/core/db-setup.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ import { setupPrismaPostgres } from "../database-providers/prisma-postgres-setup
1414
import { setupSupabase } from "../database-providers/supabase-setup";
1515
import { setupTurso } from "../database-providers/turso-setup";
1616

17-
export async function setupDatabase(config: ProjectConfig) {
17+
export async function setupDatabase(
18+
config: ProjectConfig,
19+
cliInput?: { manualDb?: boolean },
20+
) {
1821
const { database, orm, dbSetup, backend, projectDir } = config;
1922

2023
if (backend === "convex" || database === "none") {
@@ -113,25 +116,25 @@ export async function setupDatabase(config: ProjectConfig) {
113116
if (dbSetup === "docker") {
114117
await setupDockerCompose(config);
115118
} else if (database === "sqlite" && dbSetup === "turso") {
116-
await setupTurso(config);
119+
await setupTurso(config, cliInput);
117120
} else if (database === "sqlite" && dbSetup === "d1") {
118121
await setupCloudflareD1(config);
119122
} else if (database === "postgres") {
120123
if (dbSetup === "prisma-postgres") {
121-
await setupPrismaPostgres(config);
124+
await setupPrismaPostgres(config, cliInput);
122125
} else if (dbSetup === "neon") {
123-
await setupNeonPostgres(config);
126+
await setupNeonPostgres(config, cliInput);
124127
} else if (dbSetup === "planetscale") {
125128
await setupPlanetScale(config);
126129
} else if (dbSetup === "supabase") {
127-
await setupSupabase(config);
130+
await setupSupabase(config, cliInput);
128131
}
129132
} else if (database === "mysql") {
130133
if (dbSetup === "planetscale") {
131134
await setupPlanetScale(config);
132135
}
133136
} else if (database === "mongodb" && dbSetup === "mongodb-atlas") {
134-
await setupMongoDBAtlas(config);
137+
await setupMongoDBAtlas(config, cliInput);
135138
}
136139
} catch (error) {
137140
s.stop(pc.red("Failed to set up database"));

apps/cli/src/helpers/database-providers/mongodb-atlas-setup.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,26 @@ ${pc.green("MongoDB Atlas Manual Setup Instructions:")}
120120
`);
121121
}
122122

123-
export async function setupMongoDBAtlas(config: ProjectConfig) {
123+
export async function setupMongoDBAtlas(
124+
config: ProjectConfig,
125+
cliInput?: { manualDb?: boolean },
126+
) {
124127
const { projectDir } = config;
128+
const manualDb = cliInput?.manualDb ?? false;
125129
const mainSpinner = spinner();
126130
mainSpinner.start("Setting up MongoDB Atlas...");
127131

128132
const serverDir = path.join(projectDir, "apps/server");
129133
try {
130134
await fs.ensureDir(serverDir);
131135

136+
if (manualDb) {
137+
mainSpinner.stop("MongoDB Atlas manual setup selected");
138+
await writeEnvFile(projectDir);
139+
displayManualSetupInstructions();
140+
return;
141+
}
142+
132143
const mode = await select({
133144
message: "MongoDB Atlas setup: choose mode",
134145
options: [

apps/cli/src/helpers/database-providers/neon-setup.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,20 @@ function displayManualSetupInstructions() {
154154
DATABASE_URL="your_connection_string"`);
155155
}
156156

157-
export async function setupNeonPostgres(config: ProjectConfig) {
157+
export async function setupNeonPostgres(
158+
config: ProjectConfig,
159+
cliInput?: { manualDb?: boolean },
160+
) {
158161
const { packageManager, projectDir } = config;
162+
const manualDb = cliInput?.manualDb ?? false;
159163

160164
try {
165+
if (manualDb) {
166+
await writeEnvFile(projectDir);
167+
displayManualSetupInstructions();
168+
return;
169+
}
170+
161171
const mode = await select({
162172
message: "Neon setup: choose mode",
163173
options: [

apps/cli/src/helpers/database-providers/prisma-postgres-setup.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,23 @@ async function addPrismaAccelerateExtension(serverDir: string) {
212212
}
213213
}
214214

215-
export async function setupPrismaPostgres(config: ProjectConfig) {
215+
export async function setupPrismaPostgres(
216+
config: ProjectConfig,
217+
cliInput?: { manualDb?: boolean },
218+
) {
216219
const { packageManager, projectDir, orm } = config;
220+
const manualDb = cliInput?.manualDb ?? false;
217221
const serverDir = path.join(projectDir, "apps/server");
218222

219223
try {
220224
await fs.ensureDir(serverDir);
221225

226+
if (manualDb) {
227+
await writeEnvFile(projectDir);
228+
displayManualSetupInstructions();
229+
return;
230+
}
231+
222232
const mode = await select({
223233
message: "Prisma Postgres setup: choose mode",
224234
options: [

apps/cli/src/helpers/database-providers/supabase-setup.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,24 @@ ${pc.dim(output)}`
152152
);
153153
}
154154

155-
export async function setupSupabase(config: ProjectConfig) {
155+
export async function setupSupabase(
156+
config: ProjectConfig,
157+
cliInput?: { manualDb?: boolean },
158+
) {
156159
const { projectDir, packageManager } = config;
160+
const manualDb = cliInput?.manualDb ?? false;
157161

158162
const serverDir = path.join(projectDir, "apps", "server");
159163

160164
try {
161165
await fs.ensureDir(serverDir);
162166

167+
if (manualDb) {
168+
displayManualSupabaseInstructions();
169+
await writeSupabaseEnvFile(projectDir, "");
170+
return;
171+
}
172+
163173
const mode = await select({
164174
message: "Supabase setup: choose mode",
165175
options: [

apps/cli/src/helpers/database-providers/turso-setup.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,22 @@ DATABASE_URL=your_database_url
186186
DATABASE_AUTH_TOKEN=your_auth_token`);
187187
}
188188

189-
export async function setupTurso(config: ProjectConfig) {
189+
export async function setupTurso(
190+
config: ProjectConfig,
191+
cliInput?: { manualDb?: boolean },
192+
) {
190193
const { orm, projectDir } = config;
194+
const manualDb = cliInput?.manualDb ?? false;
191195
const _isDrizzle = orm === "drizzle";
192196
const setupSpinner = spinner();
193197

194198
try {
199+
if (manualDb) {
200+
await writeEnvFile(projectDir);
201+
displayManualSetupInstructions();
202+
return;
203+
}
204+
195205
const mode = await select({
196206
message: "Turso setup: choose mode",
197207
options: [

apps/cli/src/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ export const router = t.router({
9999
.optional()
100100
.default(false)
101101
.describe("Disable analytics"),
102+
manualDb: z
103+
.boolean()
104+
.optional()
105+
.default(false)
106+
.describe(
107+
"Skip automatic/manual database setup prompt and use manual setup",
108+
),
102109
}),
103110
]),
104111
)

0 commit comments

Comments
 (0)