mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
This saves space, but leads to surprises when package code tries to read these files for purposes of introspection. For example, it was causing us not to report exceptions from the exception-reporting package. The .1% of the app bundle size it saves doesn’t seem worth the potential for problems. Signed-off-by: Max Brunsfeld <maxbrunsfeld@github.com>
94 lines
3.5 KiB
CoffeeScript
94 lines
3.5 KiB
CoffeeScript
path = require 'path'
|
|
CSON = require 'season'
|
|
fs = require 'fs-plus'
|
|
_ = require 'underscore-plus'
|
|
normalizePackageData = require 'normalize-package-data'
|
|
semver = require 'semver'
|
|
|
|
OtherPlatforms = ['darwin', 'freebsd', 'linux', 'sunos', 'win32'].filter (platform) -> platform isnt process.platform
|
|
|
|
module.exports = (grunt) ->
|
|
{spawn} = require('./task-helpers')(grunt)
|
|
|
|
getMenu = (appDir) ->
|
|
menusPath = path.join(appDir, 'menus')
|
|
menuPath = path.join(menusPath, "#{process.platform}.json")
|
|
menu = CSON.readFileSync(menuPath) if fs.isFileSync(menuPath)
|
|
menu
|
|
|
|
getKeymaps = (appDir) ->
|
|
keymapsPath = path.join(appDir, 'keymaps')
|
|
keymaps = {}
|
|
for keymapPath in fs.listSync(keymapsPath, ['.json'])
|
|
name = path.basename(keymapPath, path.extname(keymapPath))
|
|
continue unless OtherPlatforms.indexOf(name) is -1
|
|
|
|
keymap = CSON.readFileSync(keymapPath)
|
|
keymaps[path.basename(keymapPath)] = keymap
|
|
keymaps
|
|
|
|
grunt.registerTask 'compile-packages-slug', 'Add bundled package metadata information to the main package.json file', ->
|
|
appDir = fs.realpathSync(grunt.config.get('atom.appDir'))
|
|
|
|
modulesDirectory = path.join(appDir, 'node_modules')
|
|
packages = {}
|
|
invalidPackages = false
|
|
|
|
for moduleDirectory in fs.listSync(modulesDirectory)
|
|
continue if path.basename(moduleDirectory) is '.bin'
|
|
|
|
metadataPath = path.join(moduleDirectory, 'package.json')
|
|
continue unless fs.existsSync(metadataPath)
|
|
|
|
metadata = grunt.file.readJSON(metadataPath)
|
|
continue unless metadata?.engines?.atom?
|
|
|
|
reportPackageError = (msg) ->
|
|
invalidPackages = true
|
|
grunt.log.error("#{metadata.name}: #{msg}")
|
|
normalizePackageData metadata, reportPackageError, true
|
|
if metadata.repository?.type is 'git'
|
|
metadata.repository.url = metadata.repository.url?.replace(/^git\+/, '')
|
|
|
|
moduleCache = metadata._atomModuleCache ? {}
|
|
|
|
_.remove(moduleCache.extensions?['.json'] ? [], 'package.json')
|
|
|
|
for property in ['_from', '_id', 'dist', 'readme', 'readmeFilename']
|
|
delete metadata[property]
|
|
|
|
pack = {metadata, keymaps: {}, menus: {}}
|
|
|
|
if metadata.main
|
|
mainPath = require.resolve(path.resolve(moduleDirectory, metadata.main))
|
|
pack.main = path.relative(appDir, mainPath)
|
|
|
|
keymapsPath = path.join(moduleDirectory, 'keymaps')
|
|
for keymapPath in fs.listSync(keymapsPath, ['.cson', '.json'])
|
|
relativePath = path.relative(appDir, keymapPath)
|
|
pack.keymaps[relativePath] = CSON.readFileSync(keymapPath)
|
|
|
|
menusPath = path.join(moduleDirectory, 'menus')
|
|
for menuPath in fs.listSync(menusPath, ['.cson', '.json'])
|
|
relativePath = path.relative(appDir, menuPath)
|
|
pack.menus[relativePath] = CSON.readFileSync(menuPath)
|
|
|
|
packages[metadata.name] = pack
|
|
|
|
for extension, paths of moduleCache.extensions
|
|
delete moduleCache.extensions[extension] if paths.length is 0
|
|
|
|
metadata = grunt.file.readJSON(path.join(appDir, 'package.json'))
|
|
metadata._atomPackages = packages
|
|
metadata._atomMenu = getMenu(appDir)
|
|
metadata._atomKeymaps = getKeymaps(appDir)
|
|
metadata._deprecatedPackages = require('../deprecated-packages')
|
|
|
|
for name, {version} of metadata._deprecatedPackages
|
|
if version and not semver.validRange(version)
|
|
invalidPackages = true
|
|
grunt.log.error("Invalid range: #{version} (#{name})")
|
|
|
|
grunt.file.write(path.join(appDir, 'package.json'), JSON.stringify(metadata))
|
|
not invalidPackages
|