fix(plugin): better errors if plugins are malformed

Fixed read assets
This commit is contained in:
Evan Morikawa 2016-02-25 11:54:46 -08:00
parent 57d7057161
commit cc15d35848
5 changed files with 29 additions and 11 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

View file

@ -37,7 +37,8 @@ export default class OpenTrackingMessageStatus extends React.Component {
return (
<RetinaImg
className={this.state.opened ? "opened" : "unopened"}
url="nylas://open-tracking/assets/icon-composer-eye@2x.png"
style={{position: 'relative', top: -1}}
url="nylas://open-tracking/assets/InMessage-Read@2x.png"
mode={RetinaImg.Mode.ContentIsMask} />
);
}

View file

@ -173,15 +173,13 @@ PackagesStore = Reflux.createStore
properties: ['openDirectory']
, (filenames) =>
return if not filenames or filenames.length is 0
NylasEnv.packages.installPackageFromPath filenames[0], (err, packageTargetDir) =>
NylasEnv.packages.installPackageFromPath filenames[0], (err) =>
return if err
packageName = path.basename(filenames[0])
msg = "#{packageName} has been installed and enabled. No need to \
restart! If you don't see the package loaded, check the \
console for errors."
@_displayMessage("Package installed", msg)
if packageTargetDir
shell.showItemInFolder(packageTargetDir)
@_displayMessage("Plugin installed 🎉", msg)
_onCreatePackage: ->
if not NylasEnv.inDevMode()
@ -210,19 +208,19 @@ PackagesStore = Reflux.createStore
packageName = path.basename(packageDir)
if not packageDir.startsWith(packagesDir)
return @_displayMessage('Invalid package location', 'Sorry, you must
create packages in the packages folder.')
return @_displayMessage('Invalid plugin location', 'Sorry, you must
create plugins in the packages folder.')
if NylasEnv.packages.resolvePackagePath(packageName)
return @_displayMessage('Invalid package name', 'Sorry, you must
give your package a unqiue name.')
return @_displayMessage('Invalid plugin name', 'Sorry, you must
give your plugin a unqiue name.')
if packageName.indexOf(' ') isnt -1
return @_displayMessage('Invalid package name', 'Sorry, package names
return @_displayMessage('Invalid plugin name', 'Sorry, plugin names
cannot contain spaces.')
fs.mkdir packageDir, (err) =>
return @_displayMessage('Could not create package', err.toString()) if err
return @_displayMessage('Could not create plugin', err.toString()) if err
{resourcePath} = NylasEnv.getLoadSettings()
packageTemplatePath = path.join(resourcePath, 'static', 'package-template')

View file

@ -6,6 +6,7 @@ EmitterMixin = require('emissary').Emitter
fs = require 'fs-plus'
Q = require 'q'
Grim = require 'grim'
CSON = require 'season'
ServiceHub = require 'service-hub'
Package = require './package'
@ -338,6 +339,8 @@ class PackageManager
dialog = require('remote').require('dialog')
shell = require('shell')
return unless @verifyValidPackage(packageSourceDir, callback)
packagesDir = path.join(NylasEnv.getConfigDirPath(), 'packages')
packageName = path.basename(packageSourceDir)
packageTargetDir = path.join(packagesDir, packageName)
@ -376,6 +379,22 @@ class PackageManager
@activatePackage(packageName)
callback(null, packageTargetDir)
verifyValidPackage: (packageSourceDir, callback) ->
if CSON.resolve(path.join(packageSourceDir, 'package'))
return true
else
errMsg = "The folder you selected doesn't look like a valid N1 plugin. All N1 plugins must have a package.json file in the top level of the folder. Check the contents of #{packageSourceDir} and try again"
dialog = require('remote').require('dialog')
dialog.showMessageBox({
type: 'warning'
buttons: ['OK']
title: 'Not a valid plugin folder'
message: errMsg
})
callback(errMsg)
return false
###
Section: Private
###