<commit_before>fs = require 'fs'
_ = require 'underscore'
EventEmitter = require 'event-emitter'

configDirPath = fs.absolute("~/.atom")
configJsonPath = fs.join(configDirPath, "config.json")
userInitScriptPath = fs.join(configDirPath, "atom.coffee")
bundledExtensionsDirPath = fs.join(resourcePath, "src/extensions")
userExtensionsDirPath = fs.join(configDirPath, "extensions")

module.exports =
class Config
  configDirPath: configDirPath

  load: ->
    if fs.exists(configJsonPath)
      userConfig = JSON.parse(fs.read(configJsonPath))
      _.extend(this, userConfig)
    @assignDefaults()
    @registerNewExtensions()
    @requireUserInitScript()

  assignDefaults: ->
    @core ?= {}
    _.defaults(@core, require('root-view').configDefaults)
    @editor ?= {}
    _.defaults(@editor, require('editor').configDefaults)

  registerNewExtensions: ->
    registeredExtensions = _.pluck(@core.extensions, 'name')
    for extensionName in _.unique(@listExtensionNames())
      unless _.contains(registeredExtensions, extensionName)
        console.log "registering", extensionName
        @core.extensions.push(name: extensionName, enabled: true)
        @update()

  listExtensionNames: ->
    fs.list(bundledExtensionsDirPath).concat(fs.list(userExtensionsDirPath)).map (path) ->
      fs.base(path)

  update: (keyPathString, value) ->
    @setValueAtKeyPath(keyPathString.split('.'), value) if keyPathString
    @save()<commit_msg>Only call  once after registering extensions<commit_after>fs = require 'fs'
_ = require 'underscore'
EventEmitter = require 'event-emitter'

configDirPath = fs.absolute("~/.atom")
configJsonPath = fs.join(configDirPath, "config.json")
userInitScriptPath = fs.join(configDirPath, "atom.coffee")
bundledExtensionsDirPath = fs.join(resourcePath, "src/extensions")
userExtensionsDirPath = fs.join(configDirPath, "extensions")

module.exports =
class Config
  configDirPath: configDirPath

  load: ->
    if fs.exists(configJsonPath)
      userConfig = JSON.parse(fs.read(configJsonPath))
      _.extend(this, userConfig)
    @assignDefaults()
    @registerNewExtensions()
    @requireUserInitScript()

  assignDefaults: ->
    @core ?= {}
    _.defaults(@core, require('root-view').configDefaults)
    @editor ?= {}
    _.defaults(@editor, require('editor').configDefaults)

  registerNewExtensions: ->
    registeredExtensions = _.pluck(@core.extensions, 'name')
    shouldUpdate = false
    for extensionName in _.unique(@listExtensionNames())
      unless _.contains(registeredExtensions, extensionName)
        @core.extensions.push(name: extensionName, enabled: true)
        shouldUpdate = true
    @update() if shouldUpdate

  listExtensionNames: ->
    fs.list(bundledExtensionsDirPath).concat(fs.list(userExtensionsDirPath)).map (path) ->
      fs.base(path)

  update: (keyPathString, value) ->
    @setValueAtKeyPath(keyPathString.split('.'), value) if keyPathString
    @save()
{'fraction_non_alphanumeric': 0.13068764967499144, 'fraction_numerical': 0.0, 'mean_word_length': 4.590822179732314, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '1740038', 'n_tokens_mistral': 870, 'n_tokens_neox': 846, 'n_words': 157}