@@ -4,8 +4,7 @@ import * as path from "path"
4
4
import { field , logger , Level } from "@coder/logger"
5
5
import { Args as VsArgs } from "../../lib/vscode/src/vs/server/ipc"
6
6
import { AuthType } from "./http"
7
- import { xdgLocalDir } from "./util"
8
- import xdgBasedir from "xdg-basedir"
7
+ import { paths , uxPath } from "./util"
9
8
10
9
export class Optional < T > {
11
10
public constructor ( public readonly value ?: T ) { }
@@ -272,7 +271,7 @@ export const parse = (argv: string[]): Args => {
272
271
}
273
272
274
273
if ( ! args [ "user-data-dir" ] ) {
275
- args [ "user-data-dir" ] = xdgLocalDir
274
+ args [ "user-data-dir" ] = paths . data
276
275
}
277
276
278
277
if ( ! args [ "extensions-dir" ] ) {
@@ -282,6 +281,11 @@ export const parse = (argv: string[]): Args => {
282
281
return args
283
282
}
284
283
284
+ const defaultConfigFile = `
285
+ auth: password
286
+ bind-addr: 127.0.0.1:8080
287
+ ` . trimLeft ( )
288
+
285
289
// readConfigFile reads the config file specified in the config flag
286
290
// and loads it's configuration.
287
291
//
@@ -291,37 +295,39 @@ export const parse = (argv: string[]): Args => {
291
295
// to ~/.config/code-server/config.yaml.
292
296
export async function readConfigFile ( args : Args ) : Promise < Args > {
293
297
const configPath = getConfigPath ( args )
294
- if ( configPath === undefined ) {
295
- return args
296
- }
297
298
298
299
if ( ! ( await fs . pathExists ( configPath ) ) ) {
299
- await fs . outputFile ( configPath , `default: hello` )
300
+ await fs . outputFile ( configPath , defaultConfigFile )
301
+ logger . info ( `Wrote default config file to ${ uxPath ( configPath ) } ` )
300
302
}
301
303
304
+ logger . info ( `Using config file from ${ uxPath ( configPath ) } ` )
305
+
302
306
const configFile = await fs . readFile ( configPath )
303
307
const config = yaml . safeLoad ( configFile . toString ( ) , {
304
308
filename : args . config ,
305
309
} )
306
310
307
311
// We convert the config file into a set of flags.
308
312
// This is a temporary measure until we add a proper CLI library.
309
- const configFileArgv = Object . entries ( config ) . map ( ( [ optName , opt ] ) => `--${ optName } =${ opt } ` )
313
+ const configFileArgv = Object . entries ( config ) . map ( ( [ optName , opt ] ) => {
314
+ if ( opt === null ) {
315
+ return `--${ optName } `
316
+ }
317
+ return `--${ optName } =${ opt } `
318
+ } )
310
319
const configFileArgs = parse ( configFileArgv )
311
320
312
321
// This prioritizes the flags set in args over the ones in the config file.
313
322
return Object . assign ( configFileArgs , args )
314
323
}
315
324
316
- function getConfigPath ( args : Args ) : string | undefined {
325
+ function getConfigPath ( args : Args ) : string {
317
326
if ( args . config !== undefined ) {
318
327
return args . config
319
328
}
320
329
if ( process . env . CODE_SERVER_CONFIG !== undefined ) {
321
330
return process . env . CODE_SERVER_CONFIG
322
331
}
323
- if ( xdgBasedir . config !== undefined ) {
324
- return `${ xdgBasedir . config } /code-server/config.yaml`
325
- }
326
- return undefined
332
+ return path . join ( paths . config , "config.yaml" )
327
333
}
0 commit comments