Cache package metadata in main package.json file

This commit is contained in:
Kevin Sawicki
2014-07-30 10:49:25 -07:00
parent c931071c91
commit 50e27854cc
3 changed files with 58 additions and 9 deletions

View File

@@ -13,6 +13,11 @@ $ = null # Defer require in case this is in the window-less browser process
ModuleCache = require './module-cache'
ScopedProperties = require './scoped-properties'
try
packagesCache = require('../package.json')
catch
packagesCache = {}
# Loads and activates a package's main module and resources such as
# stylesheets, keymaps, grammar, editor properties, and menus.
module.exports =
@@ -22,13 +27,16 @@ class Package
@stylesheetsDir: 'stylesheets'
@loadMetadata: (packagePath, ignoreErrors=false) ->
if metadataPath = CSON.resolve(path.join(packagePath, 'package'))
try
metadata = CSON.readFileSync(metadataPath)
catch error
throw error unless ignoreErrors
packageName = path.basename(packagePath)
metadata = packagesCache[packageName]?.metadata
unless metadata?
if metadataPath = CSON.resolve(path.join(packagePath, 'package'))
try
metadata = CSON.readFileSync(metadataPath)
catch error
throw error unless ignoreErrors
metadata ?= {}
metadata.name = path.basename(packagePath)
metadata.name = packageName
metadata
keymaps: null
@@ -177,10 +185,16 @@ class Package
@scopedPropertiesActivated = true
loadKeymaps: ->
@keymaps = @getKeymapPaths().map (keymapPath) -> [keymapPath, CSON.readFileSync(keymapPath)]
if packagesCache[@name]?
@keymaps = ([keymapPath, keymapObject] for keymapPath, keymapObject of packagesCache[@name].keymaps)
else
@keymaps = @getKeymapPaths().map (keymapPath) -> [keymapPath, CSON.readFileSync(keymapPath)]
loadMenus: ->
@menus = @getMenuPaths().map (menuPath) -> [menuPath, CSON.readFileSync(menuPath)]
if packagesCache[@name]?
@menus = ([menuPath, menuObject] for menuPath, menuObject of packagesCache[@name].menus)
else
@menus = @getMenuPaths().map (menuPath) -> [menuPath, CSON.readFileSync(menuPath)]
getKeymapPaths: ->
keymapsDirPath = path.join(@path, 'keymaps')