MCPcopy Index your code
hub / github.com/coder/mux / initializeProjectDirect

Function initializeProjectDirect

src/cli/server.ts:273–319  ·  view source on GitHub ↗
(
  projectPath: string,
  serviceContainer: ServiceContainer
)

Source from the content-addressed store, hash-verified

271});
272
273async function initializeProjectDirect(
274 projectPath: string,
275 serviceContainer: ServiceContainer
276): Promise<void> {
277 try {
278 let normalizedPath = projectPath.replace(/\/+$/, "");
279 const validation = await validateProjectPath(normalizedPath);
280 if (!validation.valid || !validation.expandedPath) {
281 console.error(
282 `Invalid project path provided via --add-project: ${validation.error ?? "unknown error"}`
283 );
284 return;
285 }
286 normalizedPath = validation.expandedPath;
287
288 const projects = serviceContainer.projectService.list();
289 const shouldSetLaunchProject = shouldExposeLaunchProject(projects);
290 const alreadyExists = Array.isArray(projects)
291 ? projects.some(([path]) => path === normalizedPath)
292 : false;
293
294 if (alreadyExists) {
295 console.log(`Project already exists: ${normalizedPath}`);
296 if (shouldSetLaunchProject) {
297 launchProjectPath = normalizedPath;
298 }
299 return;
300 }
301
302 console.log(`Creating project via --add-project: ${normalizedPath}`);
303 const result = await serviceContainer.projectService.create(normalizedPath);
304 if (result.success) {
305 console.log(`Project created at ${normalizedPath}`);
306 if (shouldSetLaunchProject) {
307 launchProjectPath = normalizedPath;
308 }
309 } else {
310 const errorMsg =
311 typeof result.error === "string"
312 ? result.error
313 : JSON.stringify(result.error ?? "unknown error");
314 console.error(`Failed to create project at ${normalizedPath}: ${errorMsg}`);
315 }
316 } catch (error) {
317 console.error(`initializeProject failed for ${projectPath}:`, error);
318 }
319}

Callers 1

mainFunction · 0.85

Calls 4

validateProjectPathFunction · 0.90
createMethod · 0.65
listMethod · 0.45

Tested by

no test coverage detected