Skip to content

Commit d344b85

Browse files
Prevent web-deploy when no web frontend is selected
1 parent dd31abd commit d344b85

File tree

6 files changed

+64
-15
lines changed

6 files changed

+64
-15
lines changed

.changeset/clean-eyes-remain.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-better-t-stack": patch
3+
---
4+
5+
Prevent web-deploy when no web frontend is selected

apps/cli/src/constants.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path from "node:path";
22
import { fileURLToPath } from "node:url";
3-
import type { ProjectConfig } from "./types";
3+
import type { ProjectConfig, Frontend } from "./types";
44
import { getUserPkgManager } from "./utils/get-package-manager";
55

66
const __filename = fileURLToPath(import.meta.url);
@@ -126,3 +126,14 @@ export const ADDON_COMPATIBILITY = {
126126
starlight: [],
127127
none: [],
128128
} as const;
129+
130+
// TODO: need to refactor this
131+
export const WEB_FRAMEWORKS: readonly Frontend[] = [
132+
"tanstack-router",
133+
"react-router",
134+
"tanstack-start",
135+
"next",
136+
"nuxt",
137+
"svelte",
138+
"solid",
139+
];

apps/cli/src/prompts/web-deploy.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import { cancel, isCancel, select } from "@clack/prompts";
22
import pc from "picocolors";
3-
import { DEFAULT_CONFIG } from "../constants";
3+
import { DEFAULT_CONFIG, WEB_FRAMEWORKS } from "../constants";
44
import type { Backend, Frontend, Runtime, WebDeploy } from "../types";
55

6+
function hasWebFrontend(frontends: Frontend[]): boolean {
7+
return frontends.some((f) => WEB_FRAMEWORKS.includes(f));
8+
}
9+
610
type DeploymentOption = {
711
value: WebDeploy;
812
label: string;
@@ -29,15 +33,18 @@ export async function getDeploymentChoice(
2933
deployment?: WebDeploy,
3034
_runtime?: Runtime,
3135
_backend?: Backend,
32-
_frontend: Frontend[] = [],
36+
frontend: Frontend[] = [],
3337
): Promise<WebDeploy> {
3438
if (deployment !== undefined) return deployment;
39+
if (!hasWebFrontend(frontend)) {
40+
return "none";
41+
}
3542

3643
const options: DeploymentOption[] = [
3744
{
3845
value: "workers",
3946
label: "Cloudflare Workers",
40-
hint: "Deploy to Cloudflare Workers using Wrangler",
47+
hint: "Deploy to Cloudflare Workers using Wrangler",
4148
},
4249
{ value: "none", label: "None", hint: "Manual setup" },
4350
];
@@ -57,9 +64,13 @@ export async function getDeploymentChoice(
5764
}
5865

5966
export async function getDeploymentToAdd(
60-
_frontend: Frontend[],
67+
frontend: Frontend[],
6168
existingDeployment?: WebDeploy,
6269
): Promise<WebDeploy> {
70+
if (!hasWebFrontend(frontend)) {
71+
return "none";
72+
}
73+
6374
const options: DeploymentOption[] = [];
6475

6576
if (existingDeployment !== "workers") {

apps/cli/src/validation.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
type Runtime,
1717
type WebDeploy,
1818
} from "./types";
19+
import { WEB_FRAMEWORKS } from "./constants";
1920

2021
export function processAndValidateFlags(
2122
options: CLIInput,
@@ -125,15 +126,8 @@ export function processAndValidateFlags(
125126
const validOptions = options.frontend.filter(
126127
(f): f is Frontend => f !== "none",
127128
);
128-
const webFrontends = validOptions.filter(
129-
(f) =>
130-
f === "tanstack-router" ||
131-
f === "react-router" ||
132-
f === "tanstack-start" ||
133-
f === "next" ||
134-
f === "nuxt" ||
135-
f === "svelte" ||
136-
f === "solid",
129+
const webFrontends = validOptions.filter((f) =>
130+
WEB_FRAMEWORKS.includes(f),
137131
);
138132
const nativeFrontends = validOptions.filter(
139133
(f) => f === "native-nativewind" || f === "native-unistyles",
@@ -451,6 +445,16 @@ export function processAndValidateFlags(
451445
process.exit(1);
452446
}
453447

448+
const hasWebFrontendFlag = (config.frontend ?? []).some((f) =>
449+
WEB_FRAMEWORKS.includes(f),
450+
);
451+
if (config.webDeploy && config.webDeploy !== "none" && !hasWebFrontendFlag) {
452+
consola.fatal(
453+
"'--web-deploy' requires a web frontend. Please select a web frontend or set '--web-deploy none'.",
454+
);
455+
process.exit(1);
456+
}
457+
454458
return config;
455459
}
456460

apps/cli/templates/auth/server/base/src/lib/auth.ts.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ import { drizzleAdapter } from "better-auth/adapters/drizzle";
6868
{{#if (or (includes frontend "native-nativewind") (includes frontend "native-unistyles"))}}
6969
import { expo } from "@better-auth/expo";
7070
{{/if}}
71-
import { db } from "@/db";
71+
import { db } from "../db";
7272
import * as schema from "../db/schema/auth";
7373
import { env } from "cloudflare:workers";
7474

apps/web/src/app/(home)/_components/stack-builder.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,24 @@ const analyzeStackCompatibility = (stack: StackState): CompatibilityResult => {
805805
}
806806
}
807807

808+
const webFrontendsSelected = nextStack.webFrontend.some((f) => f !== "none");
809+
if (!webFrontendsSelected && nextStack.webDeploy !== "none") {
810+
notes.webDeploy.notes.push(
811+
"Web deployment requires a web frontend. It will be disabled.",
812+
);
813+
notes.webFrontend.notes.push(
814+
"No web frontend selected: Deployment has been disabled.",
815+
);
816+
notes.webDeploy.hasIssue = true;
817+
notes.webFrontend.hasIssue = true;
818+
nextStack.webDeploy = "none";
819+
changed = true;
820+
changes.push({
821+
category: "webDeploy",
822+
message: "Web deployment set to 'none' (requires web frontend)",
823+
});
824+
}
825+
808826
return {
809827
adjustedStack: changed ? nextStack : null,
810828
notes,

0 commit comments

Comments
 (0)