mirror of
https://github.com/atom/atom.git
synced 2026-01-24 06:18:03 -05:00
Register extensions in core.extensions on Config.load
This commit is contained in:
@@ -2,17 +2,22 @@ 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: fs.absolute("~/.atom")
|
||||
configJsonPath: fs.absolute("~/.atom/config.json")
|
||||
userInitScriptPath: fs.absolute("~/.atom/atom.coffee")
|
||||
configDirPath: configDirPath
|
||||
|
||||
load: ->
|
||||
if fs.exists(@configJsonPath)
|
||||
userConfig = JSON.parse(fs.read(@configJsonPath))
|
||||
if fs.exists(configJsonPath)
|
||||
userConfig = JSON.parse(fs.read(configJsonPath))
|
||||
_.extend(this, userConfig)
|
||||
@assignDefaults()
|
||||
@registerNewExtensions()
|
||||
@requireUserInitScript()
|
||||
|
||||
assignDefaults: ->
|
||||
@@ -21,6 +26,18 @@ class Config
|
||||
@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()
|
||||
@@ -31,14 +48,12 @@ class Config
|
||||
delete keysToWrite.eventHandlersByEventName
|
||||
delete keysToWrite.eventHandlersByNamespace
|
||||
delete keysToWrite.configDirPath
|
||||
delete keysToWrite.configJsonPath
|
||||
delete keysToWrite.userInitScriptPath
|
||||
fs.write(@configJsonPath, JSON.stringify(keysToWrite, undefined, 2) + "\n")
|
||||
fs.write(configJsonPath, JSON.stringify(keysToWrite, undefined, 2) + "\n")
|
||||
|
||||
requireUserInitScript: ->
|
||||
try
|
||||
console.log @userInitScriptPath
|
||||
require @userInitScriptPath if fs.exists(@userInitScriptPath)
|
||||
require userInitScriptPath if fs.exists(userInitScriptPath)
|
||||
catch error
|
||||
console.error "Failed to load `#{@userInitScriptPath}`", error.stack, error
|
||||
|
||||
|
||||
@@ -15,7 +15,9 @@ TextMateTheme = require 'text-mate-theme'
|
||||
|
||||
module.exports =
|
||||
class RootView extends View
|
||||
@configDefaults: {}
|
||||
@configDefaults: {
|
||||
extensions: []
|
||||
}
|
||||
|
||||
@content: ->
|
||||
@div id: 'root-view', tabindex: -1, =>
|
||||
|
||||
Reference in New Issue
Block a user