mirror of
https://github.com/atom/atom.git
synced 2026-02-14 00:25:08 -05:00
This eliminates warnings when we activate packages in specs without setting up the `rootView`.
46 lines
1.2 KiB
CoffeeScript
46 lines
1.2 KiB
CoffeeScript
Package = require 'package'
|
|
fs = require 'fs'
|
|
|
|
module.exports =
|
|
class AtomPackage extends Package
|
|
metadata: null
|
|
keymapsDirPath: null
|
|
autoloadStylesheets: true
|
|
|
|
constructor: (@name) ->
|
|
super
|
|
@keymapsDirPath = fs.join(@path, 'keymaps')
|
|
|
|
load: ->
|
|
try
|
|
@loadMetadata()
|
|
@loadKeymaps()
|
|
@loadStylesheets() if @autoloadStylesheets
|
|
rootView?.activatePackage(@name, this) unless @isDirectory
|
|
catch e
|
|
console.warn "Failed to load package named '#{@name}'", e.stack
|
|
this
|
|
|
|
loadMetadata: ->
|
|
if metadataPath = fs.resolveExtension(fs.join(@path, "package"), ['cson', 'json'])
|
|
@metadata = fs.readObject(metadataPath)
|
|
|
|
loadKeymaps: ->
|
|
for keymapPath in @getKeymapPaths()
|
|
keymap.load(keymapPath)
|
|
|
|
getKeymapPaths: ->
|
|
if keymaps = @metadata?.keymaps
|
|
keymaps.map (relativePath) =>
|
|
fs.resolve(@keymapsDirPath, relativePath, ['cson', 'json', ''])
|
|
else
|
|
fs.list(@keymapsDirPath)
|
|
|
|
loadStylesheets: ->
|
|
for stylesheetPath in @getStylesheetPaths()
|
|
requireStylesheet(stylesheetPath)
|
|
|
|
getStylesheetPaths: ->
|
|
stylesheetDirPath = fs.join(@path, 'stylesheets')
|
|
fs.list(stylesheetDirPath)
|