mirror of
https://github.com/atom/atom.git
synced 2026-02-14 08:35:11 -05:00
Extend AtomPackage directly in packages index.coffee
This commit is contained in:
@@ -12,15 +12,13 @@ class AtomPackage extends Package
|
||||
|
||||
load: ->
|
||||
try
|
||||
if @requireModule
|
||||
@module = require(@path)
|
||||
@module.name = @name
|
||||
@loadMetadata()
|
||||
@loadKeymaps()
|
||||
@loadStylesheets()
|
||||
rootView.activatePackage(@name, @module) if @module
|
||||
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'])
|
||||
|
||||
@@ -16,7 +16,7 @@ _.extend atom,
|
||||
pack.load() for pack in @getPackages()
|
||||
|
||||
getPackages: ->
|
||||
@getPackageNames().map (name) -> Package.build(name)
|
||||
@getPackageNames().map((name) -> Package.build(name)).filter (pack) -> pack?
|
||||
|
||||
loadTextMatePackages: ->
|
||||
pack.load() for pack in @getTextMatePackages()
|
||||
@@ -25,7 +25,7 @@ _.extend atom,
|
||||
@getPackages().filter (pack) -> pack instanceof TextMatePackage
|
||||
|
||||
loadPackage: (name) ->
|
||||
Package.build(name).load()
|
||||
Package.build(name)?.load()
|
||||
|
||||
getPackageNames: ->
|
||||
disabledPackages = config.get("core.disabledPackages") ? []
|
||||
|
||||
@@ -2,25 +2,34 @@ fs = require 'fs'
|
||||
|
||||
module.exports =
|
||||
class Package
|
||||
@resolve: (name) ->
|
||||
path = require.resolve(name, verifyExistence: false)
|
||||
return path if path
|
||||
throw new Error("No package found named '#{name}'")
|
||||
|
||||
@build: (name) ->
|
||||
AtomPackage = require 'atom-package'
|
||||
TextMatePackage = require 'text-mate-package'
|
||||
AtomPackage = require 'atom-package'
|
||||
if TextMatePackage.testName(name)
|
||||
new TextMatePackage(name)
|
||||
else
|
||||
new AtomPackage(name)
|
||||
if fs.isDirectory(@resolve(name))
|
||||
new AtomPackage(name)
|
||||
else
|
||||
try
|
||||
PackageClass = require name
|
||||
new PackageClass(name) if typeof PackageClass is 'function'
|
||||
catch e
|
||||
console.warn "Failed to load package named '#{name}'", e.stack
|
||||
|
||||
name: null
|
||||
path: null
|
||||
requireModule: null
|
||||
isDirectory: false
|
||||
module: null
|
||||
|
||||
constructor: (@name) ->
|
||||
@path = require.resolve(@name, verifyExistence: false)
|
||||
throw new Error("No package found named '#{@name}'") unless @path
|
||||
@path = Package.resolve(@name)
|
||||
@isDirectory = fs.isDirectory(@path)
|
||||
@path = fs.directory(@path) unless @isDirectory
|
||||
|
||||
if fs.isDirectory(@path)
|
||||
@requireModule = false
|
||||
else
|
||||
@requireModule = true
|
||||
@path = fs.directory(@path)
|
||||
activate: (rootView) ->
|
||||
|
||||
@@ -32,6 +32,7 @@ class TextMatePackage extends Package
|
||||
syntax.addProperties(selector, properties)
|
||||
catch e
|
||||
console.warn "Failed to load package named '#{@name}'", e.stack
|
||||
this
|
||||
|
||||
getGrammars: ->
|
||||
return @grammars if @grammars
|
||||
|
||||
Reference in New Issue
Block a user