2021-12-17 22:06:52 +03:00
|
|
|
import { promises as fs } from "fs"
|
|
|
|
import * as path from "path"
|
2021-05-05 20:20:38 +03:00
|
|
|
import { parse, parseConfigFile, setDefaults } from "../../src/node/cli"
|
|
|
|
import { runCodeServer } from "../../src/node/main"
|
2021-12-17 22:06:52 +03:00
|
|
|
import { workspaceDir } from "./constants"
|
|
|
|
import { tmpdir } from "./helpers"
|
2021-03-10 02:36:56 +03:00
|
|
|
import * as httpserver from "./httpserver"
|
|
|
|
|
2021-05-05 20:20:38 +03:00
|
|
|
export async function setup(argv: string[], configFile?: string): Promise<httpserver.HttpServer> {
|
2021-12-17 22:06:52 +03:00
|
|
|
// This will be used as the data directory to ensure instances do not bleed
|
|
|
|
// into each other.
|
|
|
|
const dir = await tmpdir(workspaceDir)
|
2021-03-10 02:36:56 +03:00
|
|
|
|
2021-12-17 22:06:52 +03:00
|
|
|
// VS Code complains if the logs dir is missing which spams the output.
|
|
|
|
// TODO: Does that mean we are not creating it when we should be?
|
|
|
|
await fs.mkdir(path.join(dir, "logs"))
|
|
|
|
|
|
|
|
const cliArgs = parse([
|
|
|
|
`--config=${path.join(dir, "config.yaml")}`,
|
|
|
|
`--user-data-dir=${dir}`,
|
|
|
|
"--bind-addr=localhost:0",
|
|
|
|
"--log=warn",
|
|
|
|
...argv,
|
|
|
|
])
|
2021-03-10 02:36:56 +03:00
|
|
|
const configArgs = parseConfigFile(configFile || "", "test/integration.ts")
|
|
|
|
const args = await setDefaults(cliArgs, configArgs)
|
|
|
|
|
2021-05-05 20:20:38 +03:00
|
|
|
const server = await runCodeServer(args)
|
2021-03-10 02:36:56 +03:00
|
|
|
|
2021-05-05 20:20:38 +03:00
|
|
|
return new httpserver.HttpServer(server)
|
2021-03-10 02:36:56 +03:00
|
|
|
}
|