mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-20 15:37:46 +03:00
Cache package metadata in main package.json file
This commit is contained in:
parent
c931071c91
commit
50e27854cc
@ -153,7 +153,7 @@ module.exports = (grunt) ->
|
||||
fs.writeFileSync path.join(appDir, 'node_modules', 'symbols-view', 'vendor', 'ctags-win32.exe.ignore'), ''
|
||||
fs.writeFileSync path.join(shellAppDir, 'atom.exe.gui'), ''
|
||||
|
||||
dependencies = ['compile', 'generate-license:save', 'generate-module-cache']
|
||||
dependencies = ['compile', 'generate-license:save', 'generate-module-cache', 'compile-packages-slug']
|
||||
dependencies.push('copy-info-plist') if process.platform is 'darwin'
|
||||
dependencies.push('set-exe-icon') if process.platform is 'win32'
|
||||
grunt.task.run(dependencies...)
|
||||
|
35
build/tasks/compile-packages-slug-task.coffee
Normal file
35
build/tasks/compile-packages-slug-task.coffee
Normal file
@ -0,0 +1,35 @@
|
||||
path = require 'path'
|
||||
CSON = require 'season'
|
||||
fs = require 'fs-plus'
|
||||
|
||||
module.exports = (grunt) ->
|
||||
{spawn} = require('./task-helpers')(grunt)
|
||||
|
||||
grunt.registerTask 'compile-packages-slug', 'Add package metadata information to to the main package.json file', ->
|
||||
appDir = grunt.config.get('atom.appDir')
|
||||
|
||||
modulesDirectory = path.join(appDir, 'node_modules')
|
||||
packages = {}
|
||||
|
||||
for moduleDirectory in fs.listSync(modulesDirectory)
|
||||
continue if path.basename(moduleDirectory) is '.bin'
|
||||
|
||||
metadata = grunt.file.readJSON(path.join(moduleDirectory, 'package.json'))
|
||||
continue unless metadata?.engines?.atom?
|
||||
|
||||
pack = {metadata, keymaps: {}, menus: {}}
|
||||
|
||||
for keymapPath in fs.listSync(path.join(moduleDirectory, 'keymaps'), ['.cson', '.json'])
|
||||
keymapPath = path.relative(appDir, keymapPath)
|
||||
pack.keymaps[keymapPath] = CSON.readFileSync(keymapPath)
|
||||
|
||||
for menuPath in fs.listSync(path.join(moduleDirectory, 'menus'), ['.cson', '.json'])
|
||||
menuPath = path.relative(appDir, menuPath)
|
||||
pack.menus[menuPath] = CSON.readFileSync(menuPath)
|
||||
|
||||
packages[metadata.name] = pack
|
||||
|
||||
metadata = grunt.file.readJSON(path.join(appDir, 'package.json'))
|
||||
metadata._atomPackages = packages
|
||||
|
||||
grunt.file.write(path.join(appDir, 'package.json'), JSON.stringify(metadata, null, 2))
|
@ -13,6 +13,11 @@ $ = null # Defer require in case this is in the window-less browser process
|
||||
ModuleCache = require './module-cache'
|
||||
ScopedProperties = require './scoped-properties'
|
||||
|
||||
try
|
||||
packagesCache = require('../package.json')
|
||||
catch
|
||||
packagesCache = {}
|
||||
|
||||
# Loads and activates a package's main module and resources such as
|
||||
# stylesheets, keymaps, grammar, editor properties, and menus.
|
||||
module.exports =
|
||||
@ -22,13 +27,16 @@ class Package
|
||||
@stylesheetsDir: 'stylesheets'
|
||||
|
||||
@loadMetadata: (packagePath, ignoreErrors=false) ->
|
||||
packageName = path.basename(packagePath)
|
||||
metadata = packagesCache[packageName]?.metadata
|
||||
unless metadata?
|
||||
if metadataPath = CSON.resolve(path.join(packagePath, 'package'))
|
||||
try
|
||||
metadata = CSON.readFileSync(metadataPath)
|
||||
catch error
|
||||
throw error unless ignoreErrors
|
||||
metadata ?= {}
|
||||
metadata.name = path.basename(packagePath)
|
||||
metadata.name = packageName
|
||||
metadata
|
||||
|
||||
keymaps: null
|
||||
@ -177,9 +185,15 @@ class Package
|
||||
@scopedPropertiesActivated = true
|
||||
|
||||
loadKeymaps: ->
|
||||
if packagesCache[@name]?
|
||||
@keymaps = ([keymapPath, keymapObject] for keymapPath, keymapObject of packagesCache[@name].keymaps)
|
||||
else
|
||||
@keymaps = @getKeymapPaths().map (keymapPath) -> [keymapPath, CSON.readFileSync(keymapPath)]
|
||||
|
||||
loadMenus: ->
|
||||
if packagesCache[@name]?
|
||||
@menus = ([menuPath, menuObject] for menuPath, menuObject of packagesCache[@name].menus)
|
||||
else
|
||||
@menus = @getMenuPaths().map (menuPath) -> [menuPath, CSON.readFileSync(menuPath)]
|
||||
|
||||
getKeymapPaths: ->
|
||||
|
Loading…
Reference in New Issue
Block a user