Archived
1
0
This repository has been archived on 2024-09-09. You can view files and clone it, but cannot push or open issues or pull requests.
code-server/src/node/entry.ts

76 lines
2.0 KiB
TypeScript
Raw Normal View History

import { logger } from "@coder/logger"
import {
optionDescriptions,
parse,
readConfigFile,
setDefaults,
shouldOpenInExistingInstance,
shouldRunVsCodeCli,
} from "./cli"
2020-10-16 21:45:49 +02:00
import { commit, version } from "./constants"
import { openInExistingInstance, runCodeServer, runVsCodeCli } from "./main"
2020-12-04 08:08:55 +01:00
import * as proxyAgent from "./proxy_agent"
import { isChild, wrapper } from "./wrapper"
2020-02-04 20:27:46 +01:00
async function entry(): Promise<void> {
proxyAgent.monkeyPatch(false)
// There's no need to check flags like --help or to spawn in an existing
// instance for the child process because these would have already happened in
2020-11-18 20:01:46 +01:00
// the parent and the child wouldn't have been spawned. We also get the
// arguments from the parent so we don't have to parse twice and to account
// for environment manipulation (like how PASSWORD gets removed to avoid
// leaking to child processes).
if (isChild(wrapper)) {
2020-11-18 20:01:46 +01:00
const args = await wrapper.handshake()
wrapper.preventExit()
await runCodeServer(args)
return
}
2020-11-18 20:01:46 +01:00
const cliArgs = parse(process.argv.slice(2))
const configArgs = await readConfigFile(cliArgs.config)
const args = await setDefaults(cliArgs, configArgs)
if (args.help) {
console.log("code-server", version, commit)
console.log("")
console.log(`Usage: code-server [options] [path]`)
console.log("")
console.log("Options")
optionDescriptions().forEach((description) => {
console.log("", description)
})
return
}
if (args.version) {
if (args.json) {
console.log({
codeServer: version,
commit,
vscode: require("../../lib/vscode/package.json").version,
})
} else {
console.log(version, commit)
}
return
}
if (shouldRunVsCodeCli(args)) {
return runVsCodeCli(args)
}
const socketPath = await shouldOpenInExistingInstance(cliArgs)
if (socketPath) {
return openInExistingInstance(args, socketPath)
}
2020-11-18 20:01:46 +01:00
return wrapper.start(args)
}
entry().catch((error) => {
logger.error(error.message)
wrapper.exit(error)
})