MCPcopy
hub / github.com/inkeep/open-knowledge / runStartCommand

Function runStartCommand

packages/cli/src/commands/start.ts:583–732  ·  view source on GitHub ↗
(config: Config, opts: StartCommandOptions)

Source from the content-addressed store, hash-verified

581}
582
583export async function runStartCommand(config: Config, opts: StartCommandOptions): Promise<void> {
584 const startConsoleLevel = resolveStartConsoleLevel(process.env);
585 if (startConsoleLevel !== null) process.env.OK_CONSOLE_LEVEL = startConsoleLevel;
586
587 const { renderBanner } = await import('../ui/banner.ts');
588 const { accent, dim, error, warning } = await import('../ui/colors.ts');
589
590 const cwd = process.cwd();
591 const activeConfig = config;
592
593 process.title = deriveServerProcessTitle(cwd);
594
595 const host = resolveHost(opts, process.env as { HOST?: string | undefined });
596 const portFromCli = opts.port !== undefined ? Number(opts.port) : undefined;
597 const portFromEnv = process.env.PORT ? Number(process.env.PORT) : undefined;
598 const requestedUiPort = opts.uiPort !== undefined ? Number(opts.uiPort) : undefined;
599 const port = resolveCollabPort(portFromCli, portFromEnv, requestedUiPort);
600
601 if (requestedUiPort !== undefined) {
602 const { readServerLock, resolveLockDir } = await import('@inkeep/open-knowledge-server');
603 const liveServer = readServerLock(resolveLockDir(cwd));
604 if (shouldConnectToExistingServer(requestedUiPort, liveServer)) {
605 await connectUiSibling({ cwd, uiPort: requestedUiPort });
606 return;
607 }
608 }
609
610 let booted: BootedStartServer;
611 try {
612 booted = await bootStartServer({
613 config: activeConfig,
614 cwd,
615 host,
616 port,
617 ...(requestedUiPort !== undefined ? { uiPort: requestedUiPort } : {}),
618 ...(opts.serveContentAssets ? { serveContentAssets: true } : {}),
619 ...(opts.reactShellDistDir ? { reactShellDistDir: opts.reactShellDistDir } : {}),
620 ...(opts.singleFile ? { singleFile: opts.singleFile } : {}),
621 ...(opts.projectDir ? { projectDir: opts.projectDir } : {}),
622 });
623 } catch (err) {
624 if (err instanceof OkDirMissingError) {
625 console.error(error(err.message));
626 process.exit(1);
627 }
628
629 const serverModule = await import('@inkeep/open-knowledge-server');
630 if (
631 err instanceof serverModule.GitNotAvailableError ||
632 err instanceof serverModule.GitTooOldError
633 ) {
634 process.exit(78);
635 }
636
637 if (
638 err instanceof serverModule.SingleFileNotFoundError ||
639 err instanceof serverModule.SingleFileNotAFileError ||
640 err instanceof serverModule.SingleFileNotMarkdownError

Callers 2

cli.tsFile · 0.90
startCommandFunction · 0.85

Calls 15

resolveStartConsoleLevelFunction · 0.85
deriveServerProcessTitleFunction · 0.85
resolveHostFunction · 0.85
resolveCollabPortFunction · 0.85
readServerLockFunction · 0.85
connectUiSiblingFunction · 0.85
bootStartServerFunction · 0.85
isServerLockCollisionFunction · 0.85
tryDescribeLockCollisionFunction · 0.85
renderBannerFunction · 0.85
warningFunction · 0.85

Tested by

no test coverage detected