refactor: make password param to defaultConfigFile
This commit is contained in:
@ -505,17 +505,18 @@ export async function setDefaults(cliArgs: Args, configArgs?: ConfigArgs): Promi
|
||||
/**
|
||||
* Helper function to return the default config file.
|
||||
*
|
||||
* @param {string} password - Password passed in (usually from generatePassword())
|
||||
* @returns The default config file:
|
||||
*
|
||||
* - bind-addr: 127.0.0.1:8080
|
||||
* - auth: password
|
||||
* - password: <generated-password>
|
||||
* - password: <password>
|
||||
* - cert: false
|
||||
*/
|
||||
export async function defaultConfigFile(): Promise<string> {
|
||||
export function defaultConfigFile(password: string): string {
|
||||
return `bind-addr: 127.0.0.1:8080
|
||||
auth: password
|
||||
password: ${await generatePassword()}
|
||||
password: ${password}
|
||||
cert: false
|
||||
`
|
||||
}
|
||||
@ -540,7 +541,8 @@ export async function readConfigFile(configPath?: string): Promise<ConfigArgs> {
|
||||
await fs.mkdir(path.dirname(configPath), { recursive: true })
|
||||
|
||||
try {
|
||||
await fs.writeFile(configPath, await defaultConfigFile(), {
|
||||
const generatedPassword = await generatePassword()
|
||||
await fs.writeFile(configPath, defaultConfigFile(generatedPassword), {
|
||||
flag: "wx", // wx means to fail if the path exists.
|
||||
})
|
||||
logger.info(`Wrote default config file to ${humanPath(configPath)}`)
|
||||
|
Reference in New Issue
Block a user