Skip to content

Commit 210de35

Browse files
committed
feat(build-server): add option to specify pre-build command
Adds an option to specify a pre-build command in the build settings. Can be useful for projects that need a step before the build, e.g., to generate a prisma client. Also, remove the install directory in favor of simplicity. Both pre-build and install commands are run from the root of the repo. Users that need to run the commands in a different dir can just prepend to the command, e.g., `cd apps/web && pnpm run primsa:migrate`
1 parent 679b41d commit 210de35

File tree

2 files changed

+29
-23
lines changed

2 files changed

+29
-23
lines changed

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.settings/route.tsx

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -156,23 +156,25 @@ const UpdateBuildSettingsFormSchema = z.object({
156156
.refine((val) => !val || val.length <= 255, {
157157
message: "Config file path must not exceed 255 characters",
158158
}),
159-
installDirectory: z
159+
installCommand: z
160160
.string()
161161
.trim()
162162
.optional()
163-
.transform((val) => (val ? val.replace(/^\/+/, "") : val))
164-
.refine((val) => !val || val.length <= 255, {
165-
message: "Install directory must not exceed 255 characters",
163+
.refine((val) => !val || !val.includes("\n"), {
164+
message: "Install command must be a single line",
165+
})
166+
.refine((val) => !val || val.length <= 500, {
167+
message: "Install command must not exceed 500 characters",
166168
}),
167-
installCommand: z
169+
preBuildCommand: z
168170
.string()
169171
.trim()
170172
.optional()
171173
.refine((val) => !val || !val.includes("\n"), {
172-
message: "Install command must be a single line",
174+
message: "Pre-build command must be a single line",
173175
})
174176
.refine((val) => !val || val.length <= 500, {
175-
message: "Install command must not exceed 500 characters",
177+
message: "Pre-build command must not exceed 500 characters",
176178
}),
177179
});
178180

@@ -401,11 +403,11 @@ export const action: ActionFunction = async ({ request, params }) => {
401403
});
402404
}
403405
case "update-build-settings": {
404-
const { installDirectory, installCommand, triggerConfigFilePath } = submission.value;
406+
const { installCommand, preBuildCommand, triggerConfigFilePath } = submission.value;
405407

406408
const resultOrFail = await projectSettingsService.updateBuildSettings(projectId, {
407-
installDirectory: installDirectory || undefined,
408409
installCommand: installCommand || undefined,
410+
preBuildCommand: preBuildCommand || undefined,
409411
triggerConfigFilePath: triggerConfigFilePath || undefined,
410412
});
411413

@@ -1100,14 +1102,14 @@ function BuildSettingsForm({ buildSettings }: { buildSettings: BuildSettings })
11001102

11011103
const [hasBuildSettingsChanges, setHasBuildSettingsChanges] = useState(false);
11021104
const [buildSettingsValues, setBuildSettingsValues] = useState({
1103-
installDirectory: buildSettings?.installDirectory || "",
1105+
preBuildCommand: buildSettings?.preBuildCommand || "",
11041106
installCommand: buildSettings?.installCommand || "",
11051107
triggerConfigFilePath: buildSettings?.triggerConfigFilePath || "",
11061108
});
11071109

11081110
useEffect(() => {
11091111
const hasChanges =
1110-
buildSettingsValues.installDirectory !== (buildSettings?.installDirectory || "") ||
1112+
buildSettingsValues.preBuildCommand !== (buildSettings?.preBuildCommand || "") ||
11111113
buildSettingsValues.installCommand !== (buildSettings?.installCommand || "") ||
11121114
buildSettingsValues.triggerConfigFilePath !== (buildSettings?.triggerConfigFilePath || "");
11131115
setHasBuildSettingsChanges(hasChanges);
@@ -1157,34 +1159,38 @@ function BuildSettingsForm({ buildSettings }: { buildSettings: BuildSettings })
11571159
<Input
11581160
{...conform.input(fields.installCommand, { type: "text" })}
11591161
defaultValue={buildSettings?.installCommand || ""}
1160-
placeholder="e.g., `npm install`, or `bun install`"
1162+
placeholder="e.g., `npm install`, `pnpm install`, or `bun install`"
11611163
onChange={(e) => {
11621164
setBuildSettingsValues((prev) => ({
11631165
...prev,
11641166
installCommand: e.target.value,
11651167
}));
11661168
}}
11671169
/>
1168-
<Hint>Command to install your project dependencies. Auto-detected by default.</Hint>
1170+
<Hint>
1171+
Command to install your project dependencies. This will be run from the root directory
1172+
of your repo. Auto-detected by default.
1173+
</Hint>
11691174
<FormError id={fields.installCommand.errorId}>{fields.installCommand.error}</FormError>
11701175
</InputGroup>
11711176
<InputGroup fullWidth>
1172-
<Label htmlFor={fields.installDirectory.id}>Install directory</Label>
1177+
<Label htmlFor={fields.preBuildCommand.id}>Pre-build command</Label>
11731178
<Input
1174-
{...conform.input(fields.installDirectory, { type: "text" })}
1175-
defaultValue={buildSettings?.installDirectory || ""}
1176-
placeholder=""
1179+
{...conform.input(fields.preBuildCommand, { type: "text" })}
1180+
defaultValue={buildSettings?.preBuildCommand || ""}
1181+
placeholder="e.g., `npm run prisma:generate`"
11771182
onChange={(e) => {
11781183
setBuildSettingsValues((prev) => ({
11791184
...prev,
1180-
installDirectory: e.target.value,
1185+
preBuildCommand: e.target.value,
11811186
}));
11821187
}}
11831188
/>
1184-
<Hint>The directory where the install command is run in. Auto-detected by default.</Hint>
1185-
<FormError id={fields.installDirectory.errorId}>
1186-
{fields.installDirectory.error}
1187-
</FormError>
1189+
<Hint>
1190+
Any commands that needs to run before we build and deploy your project. This will be run
1191+
from the root directory of your repo.
1192+
</Hint>
1193+
<FormError id={fields.preBuildCommand.errorId}>{fields.preBuildCommand.error}</FormError>
11881194
</InputGroup>
11891195
<FormError>{buildSettingsForm.error}</FormError>
11901196
<FormButtons

apps/webapp/app/v3/buildSettings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { z } from "zod";
22

33
export const BuildSettingsSchema = z.object({
44
triggerConfigFilePath: z.string().optional(),
5-
installDirectory: z.string().optional(),
65
installCommand: z.string().optional(),
6+
preBuildCommand: z.string().optional(),
77
});
88

99
export type BuildSettings = z.infer<typeof BuildSettingsSchema>;

0 commit comments

Comments
 (0)