mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
48 lines
997 B
CoffeeScript
48 lines
997 B
CoffeeScript
CSON = require 'season'
|
|
{basename, join} = require 'path'
|
|
|
|
### Internal ###
|
|
module.exports =
|
|
class Package
|
|
@build: (path) ->
|
|
TextMatePackage = require './text-mate-package'
|
|
AtomPackage = require './atom-package'
|
|
|
|
if TextMatePackage.testName(path)
|
|
new TextMatePackage(path)
|
|
else
|
|
new AtomPackage(path)
|
|
|
|
@load: (path, options) ->
|
|
pack = @build(path)
|
|
pack.load(options)
|
|
pack
|
|
|
|
@loadMetadata: (path, ignoreErrors=false) ->
|
|
if metadataPath = CSON.resolve(join(path, 'package'))
|
|
try
|
|
metadata = CSON.readFileSync(metadataPath)
|
|
catch e
|
|
throw e unless ignoreErrors
|
|
metadata ?= {}
|
|
metadata.name = basename(path)
|
|
metadata
|
|
|
|
name: null
|
|
path: null
|
|
|
|
constructor: (@path) ->
|
|
@name = basename(@path)
|
|
|
|
isActive: ->
|
|
atom.isPackageActive(@name)
|
|
|
|
isTheme: ->
|
|
!!@metadata?.theme
|
|
|
|
# Private:
|
|
measure: (key, fn) ->
|
|
startTime = new Date().getTime()
|
|
fn()
|
|
@[key] = new Date().getTime() - startTime
|