Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions apps/web/src/components/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ import { stackedThreadToast, toastManager } from "./ui/toast";
import { decodeProjectScriptKeybindingRule } from "~/lib/projectScriptKeybindings";
import { type NewProjectScriptInput } from "./ProjectScriptsControl";
import {
buildProjectScript,
commandForProjectScript,
nextProjectScriptId,
projectScriptIdFromCommand,
Expand Down Expand Up @@ -2603,13 +2604,7 @@ function ChatViewContent(props: ChatViewProps) {
input.name,
activeProject.scripts.map((script) => script.id),
);
const nextScript: ProjectScript = {
id: nextId,
name: input.name,
command: input.command,
icon: input.icon,
runOnWorktreeCreate: input.runOnWorktreeCreate,
};
const nextScript = buildProjectScript(nextId, input);
const nextScripts = input.runOnWorktreeCreate
? [
...activeProject.scripts.map((script) =>
Expand Down Expand Up @@ -2643,13 +2638,7 @@ function ChatViewContent(props: ChatViewProps) {
return AsyncResult.failure(Cause.fail(new Error("Script not found.")));
}

const updatedScript: ProjectScript = {
...existingScript,
name: input.name,
command: input.command,
icon: input.icon,
runOnWorktreeCreate: input.runOnWorktreeCreate,
};
const updatedScript = buildProjectScript(existingScript.id, input);
const nextScripts = activeProject.scripts.map((script) =>
script.id === scriptId
? updatedScript
Expand Down
41 changes: 41 additions & 0 deletions apps/web/src/projectScripts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,54 @@ import {
} from "@t3tools/shared/projectScripts";

import {
buildProjectScript,
commandForProjectScript,
nextProjectScriptId,
primaryProjectScript,
projectScriptIdFromCommand,
} from "./projectScripts";

describe("projectScripts helpers", () => {
it("builds scripts with preview settings", () => {
expect(
buildProjectScript("dev", {
name: "Dev server",
command: "pnpm dev",
icon: "debug",
runOnWorktreeCreate: false,
previewUrl: "http://localhost:5733",
autoOpenPreview: true,
}),
).toEqual({
id: "dev",
name: "Dev server",
command: "pnpm dev",
icon: "debug",
runOnWorktreeCreate: false,
previewUrl: "http://localhost:5733",
autoOpenPreview: true,
});
});

it("omits preview settings when no preview URL is configured", () => {
expect(
buildProjectScript("test", {
name: "Test",
command: "pnpm test",
icon: "test",
runOnWorktreeCreate: false,
previewUrl: null,
autoOpenPreview: false,
}),
).toEqual({
id: "test",
name: "Test",
command: "pnpm test",
icon: "test",
runOnWorktreeCreate: false,
});
});

it("builds and parses script run commands", () => {
const command = commandForProjectScript("lint");
expect(command).toBe("script.lint.run");
Expand Down
25 changes: 25 additions & 0 deletions apps/web/src/projectScripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,31 @@ import {
import * as Schema from "effect/Schema";
const isScriptRunCommand = Schema.is(SCRIPT_RUN_COMMAND_PATTERN);

export interface ProjectScriptInput {
readonly name: ProjectScript["name"];
readonly command: ProjectScript["command"];
readonly icon: ProjectScript["icon"];
readonly runOnWorktreeCreate: ProjectScript["runOnWorktreeCreate"];
readonly previewUrl: Exclude<ProjectScript["previewUrl"], undefined> | null;
readonly autoOpenPreview: boolean;
}

export function buildProjectScript(id: string, input: ProjectScriptInput): ProjectScript {
return {
id,
name: input.name,
command: input.command,
icon: input.icon,
runOnWorktreeCreate: input.runOnWorktreeCreate,
...(input.previewUrl === null
? {}
: {
previewUrl: input.previewUrl,
autoOpenPreview: input.autoOpenPreview,
}),
};
}

function normalizeScriptId(value: string): string {
const cleaned = value
.trim()
Expand Down
Loading