<commit_before>const config = require('application-config')('PeerTube/CLI')
const netrc = require('netrc-parser').default

const version = require('../../../package.json').version

let settings = {
  remotes: [],
  default: 0
}

interface Settings {
  remotes: any[],
  default: number
}

async function getSettings () {
  return new Promise<Settings>((res, rej) => {
    let settings = {
      remotes: [],
      default: 0
    } as Settings
    config.read((err, data) => {
      if (err) {
        return rej(err)
      }
      return res(data || settings)
    })
  })
}

async function writeSettings (settings) {
  return new Promise((res, rej) => {
    config.write(settings, function (err) {
      if (err) {
        return rej(err)
      }
      return res()
    })
  })
}

netrc.loadSync()

// ---------------------------------------------------------------------------

export {
  version,
  config,
  settings,
  getSettings,
  writeSettings,
  netrc
}
<commit_msg>Fix #1328 - application-config initialisation in CLI tools (#1343)<commit_after>const config = require('application-config')('PeerTube/CLI')
const netrc = require('netrc-parser').default

const version = require('../../../package.json').version

let settings = {
  remotes: [],
  default: 0
}

interface Settings {
  remotes: any[],
  default: number
}

async function getSettings () {
  return new Promise<Settings>((res, rej) => {
    let settings = {
      remotes: [],
      default: 0
    } as Settings
    config.read((err, data) => {
      if (err) {
        return rej(err)
      }
      return res(Object.keys(data).length === 0 ? settings : data)
    })
  })
}

async function writeSettings (settings) {
  return new Promise((res, rej) => {
    config.write(settings, function (err) {
      if (err) {
        return rej(err)
      }
      return res()
    })
  })
}

netrc.loadSync()

// ---------------------------------------------------------------------------

export {
  version,
  config,
  settings,
  getSettings,
  writeSettings,
  netrc
}

{'fraction_non_alphanumeric': 0.21375921375921375, 'fraction_numerical': 0.0063882063882063885, 'mean_word_length': 2.052473763118441, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '4511289', 'n_tokens_mistral': 626, 'n_tokens_neox': 615, 'n_words': 145}