<commit_before>import appConf from 'app-conf'
import pw from 'pw'
import { join as joinPath } from 'path'

import Xo from './xo'
import { generateToken } from './utils'

const recoverAccount = async ([name]) => {
  if (name === undefined || name === '--help' || name === '-h') {
    return `
xo-server-recover-account <user name or email>

    If the user does not exist, it is created, if it exists, updates
    its password, remove any configured OTP and resets its permission to Admin.
`
  }

  let password = await new Promise(resolve => {
    process.stdout.write('Password (leave empty for random): ')
    pw(resolve)
  })

  if (password === '') {
    password = await generateToken(10)
    console.log('The generated password is', password)
  }

  const xo = new Xo(
    await appConf.load('xo-server', {
      appDir: joinPath(__dirname, '..'),
      ignoreUnknownFormats: true,
    })
  )

  const user = await xo.getUserByName(name, true)
  if (user !== null) {
    await xo.updateUser(user.id, {
      password,
      permission: 'admin',
      preferences: { otp: null },
    })
    console.log(`user ${name} has been successfully updated`)
  } else {
    await xo.createUser({ name, password, permission: 'admin' })
    console.log(`user ${name} has been successfully created`)
  }
}
export { recoverAccount as default }<commit_msg>fix(xo-server/recover-account): pass config as named param<commit_after>import appConf from 'app-conf'
import pw from 'pw'
import { join as joinPath } from 'path'

import Xo from './xo'
import { generateToken } from './utils'

const recoverAccount = async ([name]) => {
  if (name === undefined || name === '--help' || name === '-h') {
    return `
xo-server-recover-account <user name or email>

    If the user does not exist, it is created, if it exists, updates
    its password, remove any configured OTP and resets its permission to Admin.
`
  }

  let password = await new Promise(resolve => {
    process.stdout.write('Password (leave empty for random): ')
    pw(resolve)
  })

  if (password === '') {
    password = await generateToken(10)
    console.log('The generated password is', password)
  }

  const xo = new Xo({
    config: await appConf.load('xo-server', {
      appDir: joinPath(__dirname, '..'),
      ignoreUnknownFormats: true,
    }),
  })

  const user = await xo.getUserByName(name, true)
  if (user !== null) {
    await xo.updateUser(user.id, {
      password,
      permission: 'admin',
      preferences: { otp: null },
    })
    console.log(`user ${name} has been successfully updated`)
  } else {
    await xo.createUser({ name, password, permission: 'admin' })
    console.log(`user ${name} has been successfully created`)
  }
}
export { recoverAccount as default }
{'fraction_non_alphanumeric': 0.13828238719068414, 'fraction_numerical': 0.001455604075691412, 'mean_word_length': 3.229230769230769, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5891342', 'n_tokens_mistral': 845, 'n_tokens_neox': 837, 'n_words': 274}