(configPath?: string)
| 721 | * @param configPath Read the config from configPath instead of $CODE_SERVER_CONFIG or the default. |
| 722 | */ |
| 723 | export 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. |
no test coverage detected