Create an empty ~/.atom/config.cson when missing

Closes #614
This commit is contained in:
Kevin Sawicki
2013-07-05 09:17:44 -07:00
parent 0448ba5ceb
commit 651bbaa3ce
3 changed files with 22 additions and 10 deletions

View File

@@ -1,3 +1,4 @@
* Fixed: Atom can now be launched when ~/.atom/config.cson doesn't exist
* Added: Initial collaboration sessions
* Fixed: Empty lines being deleted via uppercase/downcase command
* Fixed: Keybindings not working when using non-English keyboard language

View File

@@ -1,6 +1,7 @@
fs = require 'fs'
fsUtils = require 'fs-utils'
path = require 'path'
CSON = require 'season'
describe "Config", ->
describe ".get(keyPath)", ->
@@ -210,6 +211,13 @@ describe "Config", ->
config.set("hair", "blonde") # trigger a save
expect(config.save).not.toHaveBeenCalled()
describe "when the config file does not exist", ->
it "creates it with an empty object", ->
fsUtils.makeTree(config.configDirPath)
config.loadUserConfig()
expect(fsUtils.exists(config.configFilePath)).toBe true
expect(CSON.readFileSync(config.configFilePath)).toEqual {}
describe ".observeUserConfig()", ->
updatedHandler = null

View File

@@ -66,16 +66,19 @@ class Config
@observeUserConfig()
loadUserConfig: ->
if fsUtils.exists(@configFilePath)
try
userConfig = CSON.readFileSync(@configFilePath)
_.extend(@settings, userConfig)
@configFileHasErrors = false
@trigger 'updated'
catch e
@configFileHasErrors = true
console.error "Failed to load user config '#{@configFilePath}'", e.message
console.error e.stack
if !fsUtils.exists(@configFilePath)
fsUtils.makeTree(path.dirname(@configFilePath))
CSON.writeFileSync(@configFilePath, {})
try
userConfig = CSON.readFileSync(@configFilePath)
_.extend(@settings, userConfig)
@configFileHasErrors = false
@trigger 'updated'
catch e
@configFileHasErrors = true
console.error "Failed to load user config '#{@configFilePath}'", e.message
console.error e.stack
observeUserConfig: ->
@watchSubscription ?= pathWatcher.watch @configFilePath, (eventType) =>