function configManager (filepath) {
  let config

  try {
    const data = fs.readFileSync(filepath)
    config = JSON.parse(data)
  } catch (err) {
    config = defaultConfig
  }

  // always use the default siad path after an upgrade
  if (typeof config.version === 'undefined') {
    config.version = version
    config.siad.path = defaultSiadPath
  } else if (semver.lt(config.version, version)) {
    config.version = version
    config.siad.path = defaultSiadPath
  }

  // fill out default values if config is incomplete
  config = Object.assign(defaultConfig, config)

  /**
   * Gets or sets a config attribute
   * @param {object} key - key to get or set
   * @param {object} value - value to set config[key] as
   */
  config.attr = function (key, value) {
    if (value !== undefined) {
      config[key] = value
    }
    if (config[key] === undefined) {
      config[key] = null
    }
    return config[key]
  }

  /**
   * Writes the current config to defaultConfigPath
   * @param {string} path - UI's defaultConfigPath
   */
  config.save = function () {
    fs.writeFileSync(filepath, JSON.stringify(config, null, '\t'))
  }

  /**
   * Sets config to what it was on disk
   */
  config.reset = function () {
    config = configManager(filepath)
  }

  // expose the default siad path
  config.defaultSiadPath = defaultSiadPath

  // Save to disk immediately when loaded
  try {
    config.save()
  } catch (err) {
    console.error('couldnt save config.json: ' + err.toString())
  }

  // Return the config object with the above 3 member functions
  return config
}
/**
 * Holds all config.json related logic
 * @module configManager
 */
Holds all config.json related logic
@module configManager
Holds all config . json related logic @module configManager
function configManager (filepath) {
  let config
  try {
    const data = fs.readFileSync(filepath)
    config = JSON.parse(data)
  } catch (err) {
    config = defaultConfig
  }
  if (typeof config.version === 'undefined') {
    config.version = version
    config.siad.path = defaultSiadPath
  } else if (semver.lt(config.version, version)) {
    config.version = version
    config.siad.path = defaultSiadPath
  }
  config = Object.assign(defaultConfig, config)
  config.attr = function (key, value) {
    if (value !== undefined) {
      config[key] = value
    }
    if (config[key] === undefined) {
      config[key] = null
    }
    return config[key]
  }
  config.save = function () {
    fs.writeFileSync(filepath, JSON.stringify(config, null, '\t'))
  }
  config.reset = function () {
    config = configManager(filepath)
  }
  config.defaultSiadPath = defaultSiadPath
  try {
    config.save()
  } catch (err) {
    console.error('couldnt save config.json: ' + err.toString())
  }
  return config
}
function configManager ( filepath ) { let config try { const data = fs . readFileSync ( filepath ) config = JSON . parse ( data ) } catch ( err ) { config = defaultConfig } if ( typeof config . version === 'undefined' ) { config . version = version config . siad . path = defaultSiadPath } else if ( semver . lt ( config . version , version ) ) { config . version = version config . siad . path = defaultSiadPath } config = Object . assign ( defaultConfig , config ) config . attr = function ( key , value ) { if ( value !== undefined ) { config [ key ] = value } if ( config [ key ] === undefined ) { config [ key ] = null } return config [ key ] } config . save = function ( ) { fs . writeFileSync ( filepath , JSON . stringify ( config , null , '\t' ) ) } config . reset = function ( ) { config = configManager ( filepath ) } config . defaultSiadPath = defaultSiadPath try { config . save ( ) } catch ( err ) { console . error ( 'couldnt save config.json: ' + err . toString ( ) ) } return config }
Holds all config.json related logic
 @module configManager
Holds all config . json related logic @module configManager
// always use the default siad path after an upgrade // fill out default values if config is incomplete /**
   * Gets or sets a config attribute
   * @param {object} key - key to get or set
   * @param {object} value - value to set config[key] as
   */ /**
   * Writes the current config to defaultConfigPath
   * @param {string} path - UI's defaultConfigPath
   */ /**
   * Sets config to what it was on disk
   */ // expose the default siad path // Save to disk immediately when loaded // Return the config object with the above 3 member functions