Move loadPackages to atom global. Handle '-tmbundle' in regex.

This simplifies the loading of TextMate bundles in the spec and benchmark helpers. Since `loadBundle` was already implemented on `atom`, it made sense to move this logic here. Config is now more focused on its core job of handling configuration, not loading bundles.
This commit is contained in:
Nathan Sobo
2012-12-20 21:32:33 -07:00
parent dd8597cc9c
commit c7605b8aa6
4 changed files with 29 additions and 37 deletions

View File

@@ -11,12 +11,14 @@ TextMateTheme = require 'text-mate-theme'
require 'window'
requireStylesheet "jasmine.css"
# Load TextMate bundles, which specs rely on (but not other packages)
atom.loadPackages(atom.getAvailableTextMateBundles())
beforeEach ->
# don't load user configuration
# reset config after each benchmark; don't load or save from/to `config.json`
window.config = new Config()
spyOn(config, 'load')
spyOn(config, 'save')
config.assignDefaults()
keymap = new Keymap
keymap.bindDefaultKeys()

View File

@@ -19,20 +19,17 @@ requireStylesheet "jasmine.css"
require.paths.unshift(require.resolve('fixtures/packages'))
# Temporary solution to load textmate bundles for specs
window.config = new Config()
config.assignDefaults()
config.loadPackages(config.getAvailableTextMateBundles())
# Load TextMate bundles, which specs rely on (but not other packages)
atom.loadPackages(atom.getAvailableTextMateBundles())
beforeEach ->
window.fixturesProject = new Project(require.resolve('fixtures'))
window.resetTimeouts()
# don't load or save user configuration
# reset config after each spec; don't load or save from/to `config.json`
window.config = new Config()
spyOn(config, 'load')
spyOn(config, 'save')
config.assignDefaults()
config.set "editor.fontSize", 16
# make editor display updates synchronous

View File

@@ -10,9 +10,26 @@ _.extend atom,
pendingBrowserProcessCallbacks: {}
getAvailablePackages: ->
allPackageNames = []
for packageDirPath in config.packageDirPaths
packageNames = fs.list(packageDirPath).map (packagePath) -> fs.base(packagePath)
allPackageNames.push(packageNames...)
_.unique(allPackageNames)
getAvailableTextMateBundles: ->
@getAvailablePackages().filter (packageName) => @isTextMateBundle(packageName)
loadPackages: (packageNames=@getAvailablePackages()) ->
disabledPackages = config.get("core.disabledPackages") ? []
console.log packageNames
for packageName in packageNames
@loadPackage(packageName) unless _.contains(disabledPackages, packageName)
loadPackage: (name) ->
try
if /\.tmbundle$/.test name
if @isTextMateBundle(name)
TextMateBundle.load(name)
else
packagePath = require.resolve(name, verifyExistence: false)
@@ -90,3 +107,5 @@ _.extend atom,
[messageId, callbackIndex] = data.shift()
@pendingBrowserProcessCallbacks[messageId]?[callbackIndex]?(data...)
isTextMateBundle: (packageName) ->
/(\.|_|-)tmbundle$/.test(packageName)

View File

@@ -13,6 +13,7 @@ require.paths.unshift userPackagesDirPath
module.exports =
class Config
configDirPath: configDirPath
packageDirPaths: [userPackagesDirPath, bundledPackagesDirPath]
settings: null
constructor: ->
@@ -22,38 +23,14 @@ class Config
load: ->
@loadUserConfig()
@loadPackages(@getAvailableTextMateBundles())
@loadPackages(@getAvailableAtomPackages())
@requireUserInitScript()
atom.loadPackages()
loadUserConfig: ->
if fs.exists(configJsonPath)
userConfig = JSON.parse(fs.read(configJsonPath))
_.extend(@settings, userConfig)
assignDefaults: ->
@settings ?= {}
@setDefaults "core", require('root-view').configDefaults
@setDefaults "editor", require('editor').configDefaults
getAvailablePackages: ->
atomPackages = fs.list(bundledPackagesDirPath)
userPackages = fs.list(userPackagesDirPath)
allPackageNames = atomPackages.concat(userPackages).map (path) -> fs.base(path)
_.unique(allPackageNames)
getAvailableTextMateBundles: ->
@getAvailablePackages().filter (packageName) => @isTextMateBundle(packageName)
getAvailableAtomPackages: ->
@getAvailablePackages().filter (packageName) => not @isTextMateBundle(packageName)
loadPackages: (packageNames) ->
disabledPackages = config.get("core.disabledPackages") ? []
for packageName in packageNames
continue if _.contains disabledPackages, packageName
atom.loadPackage(packageName)
get: (keyPath) ->
keys = @keysForKeyPath(keyPath)
value = @settings
@@ -116,7 +93,4 @@ class Config
catch error
console.error "Failed to load `#{userInitScriptPath}`", error.stack, error
isTextMateBundle: (packageName) ->
/(\.|_)tmbundle$/.test(packageName)
_.extend Config.prototype, EventEmitter