mirror of
https://github.com/atom/atom.git
synced 2026-02-06 12:44:59 -05:00
Support CSON config file
Use ~/.atom/config.cson as the new default when no config file exists. ~/.atom/config.json is still the default if they both exist.
This commit is contained in:
@@ -3,7 +3,6 @@ _ = require 'underscore'
|
||||
EventEmitter = require 'event-emitter'
|
||||
|
||||
configDirPath = fs.absolute("~/.atom")
|
||||
configJsonPath = fs.join(configDirPath, "config.json")
|
||||
userInitScriptPath = fs.join(configDirPath, "user.coffee")
|
||||
bundledPackagesDirPath = fs.join(resourcePath, "src/packages")
|
||||
bundledThemesDirPath = fs.join(resourcePath, "themes")
|
||||
@@ -27,6 +26,8 @@ class Config
|
||||
core: _.clone(require('root-view').configDefaults)
|
||||
editor: _.clone(require('editor').configDefaults)
|
||||
@settings = {}
|
||||
@configFilePath = fs.resolveExtension(fs.join(configDirPath, 'config'), ['json', 'cson'])
|
||||
@configFilePath ?= fs.join(configDirPath, 'config.cson')
|
||||
|
||||
load: ->
|
||||
@loadUserConfig()
|
||||
@@ -35,8 +36,8 @@ class Config
|
||||
atom.loadPackages()
|
||||
|
||||
loadUserConfig: ->
|
||||
if fs.exists(configJsonPath)
|
||||
userConfig = JSON.parse(fs.read(configJsonPath))
|
||||
if fs.exists(@configFilePath)
|
||||
userConfig = fs.readObject(@configFilePath)
|
||||
_.extend(@settings, userConfig)
|
||||
|
||||
get: (keyPath) ->
|
||||
@@ -77,7 +78,7 @@ class Config
|
||||
@trigger 'updated'
|
||||
|
||||
save: ->
|
||||
fs.write(configJsonPath, JSON.stringify(@settings, undefined, 2) + "\n")
|
||||
fs.writeObject(@configFilePath, @settings)
|
||||
|
||||
requireUserInitScript: ->
|
||||
try
|
||||
|
||||
@@ -188,6 +188,14 @@ module.exports =
|
||||
else
|
||||
JSON.parse(contents)
|
||||
|
||||
writeObject: (path, object) ->
|
||||
if @extension(path) is '.cson'
|
||||
CSON = require 'cson'
|
||||
content = CSON.stringify(object)
|
||||
else
|
||||
content = JSON.stringify(object, undefined, 2)
|
||||
@write(path, "#{content}\n")
|
||||
|
||||
readPlist: (path) ->
|
||||
plist = require 'plist'
|
||||
object = null
|
||||
|
||||
Reference in New Issue
Block a user