Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

projectScripts.ts

37 lines917 Bytes

1import type { ProjectScript } from "@workbench/contracts";
2​
3interface ProjectScriptRuntimeEnvInput {
4 project: {
5 cwd: string;
6 };
7 worktreePath?: string | null;
8 extraEnv?: Record<string, string>;
9}
10​
11export function projectScriptCwd(input: {
12 project: {
13 cwd: string;
14 };
15 worktreePath?: string | null;
16}): string {
17 return input.worktreePath ?? input.project.cwd;
19​
20export function projectScriptRuntimeEnv(
21 input: ProjectScriptRuntimeEnvInput,
22): Record<string, string> {
23 const env: Record<string, string> = {
24 T3CODE_PROJECT_ROOT: input.project.cwd,
25 };
26 if (input.worktreePath) {
27 env.T3CODE_WORKTREE_PATH = input.worktreePath;
28 }
29 if (input.extraEnv) {
30 return { ...env, ...input.extraEnv };
31 }
32 return env;
34​
35export function setupProjectScript(scripts: readonly ProjectScript[]): ProjectScript | null {
36 return scripts.find((script) => script.runOnWorktreeCreate) ?? null;