Load keymaps from package.json

This commit is contained in:
Kevin Sawicki
2015-04-07 17:25:02 -07:00
parent 0d3d72c181
commit 50688973e6
2 changed files with 22 additions and 2 deletions

View File

@@ -3,6 +3,8 @@ CSON = require 'season'
fs = require 'fs-plus'
_ = require 'underscore-plus'
OtherPlatforms = ['darwin', 'freebsd', 'linux', 'sunos', 'win32'].filter (platform) -> platform isnt process.platform
module.exports = (grunt) ->
{spawn, rm} = require('./task-helpers')(grunt)
@@ -15,7 +17,13 @@ module.exports = (grunt) ->
getKeymaps = (appDir) ->
keymapsPath = path.join(appDir, 'keymaps')
keymaps = fs.listSync(keymapsPath, ['.cson', '.json']).map (keymapPath) -> CSON.readFileSync(keymapPath)
keymaps = {}
for keymapPath in fs.listSync(keymapsPath, ['.cson', '.json'])
name = path.basename(keymapPath, path.extname(keymapPath))
continue unless OtherPlatforms.indexOf(name) is -1
keymap = CSON.readFileSync(keymapPath)
keymaps[path.basename(keymapPath)] = keymap
rm keymapsPath
keymaps

View File

@@ -5,11 +5,23 @@ CSON = require 'season'
{jQuery} = require 'space-pen'
Grim = require 'grim'
try
bundledKeymaps = require('../package.json')?._atomKeymaps
catch error
bundledKeymaps = null
KeymapManager::onDidLoadBundledKeymaps = (callback) ->
@emitter.on 'did-load-bundled-keymaps', callback
KeymapManager::loadBundledKeymaps = ->
@loadKeymap(path.join(@resourcePath, 'keymaps'))
keymapsPath = path.join(@resourcePath, 'keymaps')
if bundledKeymaps?
for keymapName, keymap of bundledKeymaps
keymapPath = path.join(keymapsPath, keymapName)
@add(keymapPath, keymap)
else
@loadKeymap(keymapsPath)
@emit 'bundled-keymaps-loaded' if Grim.includeDeprecatedAPIs
@emitter.emit 'did-load-bundled-keymaps'