MCPcopy Index your code
hub / github.com/coder/code-server / readConfigFile

Function readConfigFile

src/node/cli.ts:723–748  ·  view source on GitHub ↗
(configPath?: string)

Source from the content-addressed store, hash-verified

721 * @param configPath Read the config from configPath instead of $CODE_SERVER_CONFIG or the default.
722 */
723export async function readConfigFile(configPath?: string): Promise<ConfigArgs> {
724 if (!configPath) {
725 configPath = process.env.CODE_SERVER_CONFIG
726 if (!configPath) {
727 configPath = path.join(paths.config, "config.yaml")
728 }
729 }
730
731 await fs.mkdir(path.dirname(configPath), { recursive: true })
732
733 try {
734 const generatedPassword = await generatePassword()
735 await fs.writeFile(configPath, defaultConfigFile(generatedPassword), {
736 flag: "wx", // wx means to fail if the path exists.
737 })
738 logger.info(`Wrote default config file to ${configPath}`)
739 } catch (error: any) {
740 // EEXIST is fine; we don't want to overwrite existing configurations.
741 if (error.code !== "EEXIST") {
742 throw error
743 }
744 }
745
746 const configFile = await fs.readFile(configPath, "utf8")
747 return parseConfigFile(configFile, configPath)
748}
749
750/**
751 * parseConfigFile parses configFile into ConfigArgs.

Callers 1

entryFunction · 0.90

Calls 3

generatePasswordFunction · 0.90
defaultConfigFileFunction · 0.85
parseConfigFileFunction · 0.85

Tested by

no test coverage detected