mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
When loading a package, honor the 'keymaps' manifest in package.json
Also, add a spec to cover the loading of keymaps in `atom-spec` and reset the `keymap`'s internal data after each spec gets run to prevent test pollution with keymaps.
This commit is contained in:
@@ -3,29 +3,42 @@ fs = require 'fs'
|
||||
|
||||
module.exports =
|
||||
class AtomPackage extends Package
|
||||
metadata: null
|
||||
keymapsDirPath: null
|
||||
|
||||
constructor: (@name) ->
|
||||
super
|
||||
@module = require(@path)
|
||||
@module.name = @name
|
||||
@keymapsDirPath = fs.join(@path, 'keymaps')
|
||||
if @requireModule
|
||||
@module = require(@path)
|
||||
@module.name = @name
|
||||
|
||||
load: ->
|
||||
try
|
||||
@loadMetadata()
|
||||
@loadKeymaps()
|
||||
@loadStylesheets()
|
||||
rootView.activatePackage(@module)
|
||||
rootView.activatePackage(@module) if @module
|
||||
catch e
|
||||
console.error "Failed to load package named '#{@name}'", e.stack
|
||||
|
||||
loadMetadata: ->
|
||||
if metadataPath = fs.resolveExtension(fs.join(@path, "package"), ['cson', 'json'])
|
||||
@metadata = fs.readObject(metadataPath)
|
||||
|
||||
loadKeymaps: ->
|
||||
for keymapPath in @getKeymapPaths()
|
||||
keymap.load(keymapPath)
|
||||
|
||||
getKeymapPaths: ->
|
||||
keymapsDirPath = fs.join(@path, 'keymaps')
|
||||
if fs.exists keymapsDirPath
|
||||
fs.list keymapsDirPath
|
||||
if keymaps = @metadata?.keymaps
|
||||
keymaps.map (relativePath) =>
|
||||
fs.resolve(@keymapsDirPath, relativePath, ['cson', 'json', ''])
|
||||
else
|
||||
[]
|
||||
if fs.exists(@keymapsDirPath)
|
||||
fs.list(@keymapsDirPath)
|
||||
else
|
||||
[]
|
||||
|
||||
loadStylesheets: ->
|
||||
for stylesheetPath in @getStylesheetPaths()
|
||||
|
||||
@@ -11,10 +11,21 @@ class Package
|
||||
else
|
||||
new AtomPackage(name).load()
|
||||
|
||||
|
||||
name: null
|
||||
path: null
|
||||
requireModule: null
|
||||
module: null
|
||||
|
||||
constructor: (@name) ->
|
||||
@path = require.resolve(@name, verifyExistence: false)
|
||||
throw new Error("No package found named '#{@name}'") unless @path
|
||||
@path = fs.directory(@path) unless fs.isDirectory(@path)
|
||||
|
||||
if fs.isDirectory(@path)
|
||||
@requireModule = false
|
||||
else
|
||||
@requireModule = true
|
||||
@path = fs.directory(@path)
|
||||
|
||||
load: ->
|
||||
for grammar in @getGrammars()
|
||||
|
||||
@@ -124,11 +124,27 @@ module.exports =
|
||||
md5ForPath: (path) ->
|
||||
$native.md5ForPath(path)
|
||||
|
||||
resolve: (paths...) ->
|
||||
to = paths.pop()
|
||||
for from in paths
|
||||
path = @join(from, to)
|
||||
return path if @exists(path)
|
||||
resolve: (args...) ->
|
||||
extensions = args.pop() if _.isArray(_.last(args))
|
||||
pathToResolve = args.pop()
|
||||
loadPaths = args
|
||||
|
||||
for loadPath in loadPaths
|
||||
candidatePath = @join(loadPath, pathToResolve)
|
||||
if extensions
|
||||
if resolvedPath = @resolveExtension(candidatePath, extensions)
|
||||
return resolvedPath
|
||||
else
|
||||
return candidatePath if @exists(candidatePath)
|
||||
undefined
|
||||
|
||||
resolveExtension: (path, extensions) ->
|
||||
for extension in extensions
|
||||
if extension == ""
|
||||
return path if @exists(path)
|
||||
else
|
||||
pathWithExtension = path + "." + extension
|
||||
return pathWithExtension if @exists(pathWithExtension)
|
||||
undefined
|
||||
|
||||
isCompressedExtension: (ext) ->
|
||||
|
||||
Reference in New Issue
Block a user