Skip to content

Commit 4025534

Browse files
committed
[cmd] update npm packaged on plugin upgrade command
1 parent 852d983 commit 4025534

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

bin/commands/scripts/plugin.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ if(myArgs[0] == "enable" && myArgs[1]){
3838
else if(myArgs[0] == "upgrade" && myArgs[1]){
3939
if(plugins.indexOf(myArgs[1]) > -1){
4040
require('../../../api/utils/log').setLevel('db:write', 'mute');
41-
manager.installPlugin(myArgs[1]);
41+
manager.upgradePlugin(myArgs[1]);
4242
}
4343
else{
4444
console.log("Plugin is not installed");

plugins/pluginManager.js

+27
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,33 @@ var pluginManager = function pluginManager(){
488488
});
489489
}
490490

491+
this.upgradePlugin = function(plugin, callback){
492+
console.log('Upgrading plugin %j...', plugin);
493+
callback = callback || function() {};
494+
try{
495+
var errors;
496+
var scriptPath = path.join(__dirname, plugin, 'install.js');
497+
delete require.cache[require.resolve(scriptPath)];
498+
require(scriptPath);
499+
}
500+
catch(ex){
501+
console.log(ex.stack);
502+
errors = true;
503+
return callback(errors);
504+
}
505+
var eplugin = global.enclose ? global.enclose.plugins[plugin] : null;
506+
if (eplugin && eplugin.prepackaged) return callback(errors);
507+
var cwd = eplugin ? eplugin.rfs : path.join(__dirname, plugin);
508+
var child = exec('npm update --unsafe-perm', {cwd: cwd}, function(error) {
509+
if (error){
510+
errors = true;
511+
console.log('error: %j', error);
512+
}
513+
console.log('Done upgrading plugin %j', plugin);
514+
callback(errors);
515+
});
516+
}
517+
491518
this.uninstallPlugin = function(plugin, callback){
492519
console.log('Uninstalling plugin %j...', plugin);
493520
callback = callback || function() {};

0 commit comments

Comments
 (0)