|
1 | | -import * as FileSystem from "@effect/platform/FileSystem" |
2 | | -import * as Path from "@effect/platform/Path" |
| 1 | +import * as FsPlatform from "@effect/platform/FileSystem" |
| 2 | +import * as PathPlatform from "@effect/platform/Path" |
3 | 3 | import { Effect } from "effect" |
4 | 4 |
|
| 5 | +import { |
| 6 | + buildCreateProjectRequest, |
| 7 | + createProjectRequestAllowsImmediateUp, |
| 8 | + createProjectRequestNeedsFollowUpUp, |
| 9 | + decodeProjectResponse, |
| 10 | + upCreatedProjectWithAuthorizedKeys |
| 11 | +} from "./api-client-create.js" |
5 | 12 | import { readProjectOutput, resolveCreateRequestPaths } from "./api-client-helpers.js" |
6 | 13 | import { request, requestTextStream, requestVoid } from "./api-http.js" |
7 | | -import { asArray, asObject, type JsonRequest } from "./api-json.js" |
| 14 | +import { asArray, asObject } from "./api-json.js" |
8 | 15 | import { decodeProjectDetails, decodeProjectSummary } from "./api-project-codec.js" |
9 | 16 | import { decodeTerminalSession } from "./api-terminal-codec.js" |
10 | 17 | import type { |
@@ -85,46 +92,38 @@ export const getProject = (projectId: string) => |
85 | 92 | }) |
86 | 93 | ) |
87 | 94 |
|
| 95 | +const createProjectWithResolvedPaths = ( |
| 96 | + command: CreateCommand, |
| 97 | + resolvedPaths: { |
| 98 | + readonly authorizedKeysPath: string |
| 99 | + readonly authorizedKeysContents?: string | undefined |
| 100 | + } |
| 101 | +) => |
| 102 | + Effect.gen(function*(_) { |
| 103 | + const createRequest = buildCreateProjectRequest( |
| 104 | + command, |
| 105 | + resolvedPaths, |
| 106 | + createProjectRequestAllowsImmediateUp(command, resolvedPaths) |
| 107 | + ) |
| 108 | + const payload = yield* _(request("POST", "/projects", createRequest)) |
| 109 | + const createdProject = decodeProjectResponse(payload) |
| 110 | + if ( |
| 111 | + createdProject === null || |
| 112 | + resolvedPaths.authorizedKeysContents === undefined || |
| 113 | + !createProjectRequestNeedsFollowUpUp(command, resolvedPaths) |
| 114 | + ) { |
| 115 | + return createdProject |
| 116 | + } |
| 117 | + |
| 118 | + return yield* _( |
| 119 | + upCreatedProjectWithAuthorizedKeys(createdProject.projectDir, resolvedPaths.authorizedKeysContents) |
| 120 | + ) |
| 121 | + }) |
| 122 | + |
88 | 123 | export const createProject = (command: CreateCommand) => |
89 | 124 | Effect.gen(function*(_) { |
90 | | - const config = command.config |
91 | 125 | const resolvedPaths = yield* _(resolveCreateRequestPaths(command)) |
92 | | - const body = { |
93 | | - repoUrl: config.repoUrl, |
94 | | - repoRef: config.repoRef, |
95 | | - targetDir: config.targetDir, |
96 | | - sshPort: String(config.sshPort), |
97 | | - sshUser: config.sshUser, |
98 | | - containerName: config.containerName, |
99 | | - serviceName: config.serviceName, |
100 | | - volumeName: config.volumeName, |
101 | | - authorizedKeysPath: resolvedPaths.authorizedKeysPath, |
102 | | - envGlobalPath: config.envGlobalPath, |
103 | | - envProjectPath: config.envProjectPath, |
104 | | - codexAuthPath: config.codexAuthPath, |
105 | | - codexHome: config.codexHome, |
106 | | - cpuLimit: config.cpuLimit, |
107 | | - ramLimit: config.ramLimit, |
108 | | - dockerNetworkMode: config.dockerNetworkMode, |
109 | | - dockerSharedNetworkName: config.dockerSharedNetworkName, |
110 | | - enableMcpPlaywright: config.enableMcpPlaywright, |
111 | | - outDir: command.outDir, |
112 | | - gitTokenLabel: config.gitTokenLabel, |
113 | | - skipGithubAuth: config.skipGithubAuth, |
114 | | - useManagedAuthorizedKeys: true, |
115 | | - codexTokenLabel: config.codexAuthLabel, |
116 | | - claudeTokenLabel: config.claudeAuthLabel, |
117 | | - agentAutoMode: config.agentAuto ? (config.agentMode ?? "auto") : undefined, |
118 | | - up: command.runUp, |
119 | | - openSsh: false, |
120 | | - force: command.force, |
121 | | - forceEnv: command.forceEnv, |
122 | | - waitForClone: command.waitForClone |
123 | | - } satisfies JsonRequest |
124 | | - |
125 | | - const payload = yield* _(request("POST", "/projects", body)) |
126 | | - const object = asObject(payload) |
127 | | - return object === null ? decodeProjectDetails(payload) : decodeProjectDetails(object["project"] ?? payload) |
| 126 | + return yield* _(createProjectWithResolvedPaths(command, resolvedPaths)) |
128 | 127 | }) |
129 | 128 |
|
130 | 129 | export const deleteProject = (projectId: string) => requestVoid("DELETE", projectPath(projectId)) |
@@ -286,8 +285,8 @@ export const codexLogin = (command: AuthCodexLoginCommand) => |
286 | 285 |
|
287 | 286 | const readCodexAuthText = (command: AuthCodexImportCommand) => |
288 | 287 | Effect.gen(function*(_) { |
289 | | - const fs = yield* _(FileSystem.FileSystem) |
290 | | - const path = yield* _(Path.Path) |
| 288 | + const fs = yield* _(FsPlatform.FileSystem) |
| 289 | + const path = yield* _(PathPlatform.Path) |
291 | 290 | const resolvedCodexAuthDir = resolvePathFromCwd(path, process.cwd(), command.codexAuthPath) |
292 | 291 | const authFilePath = path.join(resolvedCodexAuthDir, "auth.json") |
293 | 292 | return yield* _(fs.readFileString(authFilePath)) |
|
0 commit comments