Skip to content

Commit 24ae875

Browse files
committed
feat: Add initializeApp function to handle application initialization
1 parent b3db6d6 commit 24ae875

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

src/lib/initialization.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { FetchError } from "ofetch"
55
import { ENV } from "~/config/env"
66
import { getGitHubUser } from "~/services/github/get-user/service"
77

8+
import type { parseCli } from "./cli"
9+
810
import { PATHS } from "../config/paths"
911
import { TOKENS } from "../config/tokens"
1012
import { getModels } from "../services/copilot/get-models/service"
@@ -103,6 +105,18 @@ async function logUser() {
103105
consola.info(`Logged in as ${JSON.stringify(user.login)}`)
104106
}
105107

108+
export async function initializeApp(
109+
options: Awaited<ReturnType<typeof parseCli>>,
110+
) {
111+
ENV.EMULATE_STREAMING = options["emulate-streaming"]
112+
113+
await initialize()
114+
115+
return {
116+
port: parseInt(options.port, 10),
117+
}
118+
}
119+
106120
export async function initialize() {
107121
for (const step of initSteps) {
108122
try {

src/main.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
import type { Serve } from "bun"
22

3-
import { ENV } from "./config/env"
43
import { parseCli } from "./lib/cli"
5-
import { initialize } from "./lib/initialization"
4+
import { initializeApp } from "./lib/initialization"
65
import { server } from "./server"
76

87
const options = await parseCli()
9-
ENV.EMULATE_STREAMING = options["emulate-streaming"]
108

11-
await initialize()
9+
const { port } = await initializeApp(options)
1210

1311
export default {
1412
fetch: server.fetch,
15-
port: parseInt(options.port, 10),
13+
port,
1614
} satisfies Serve

0 commit comments

Comments
 (0)