2016-08-26 14:19:03 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const path = require('path');
|
2017-11-02 17:05:37 +01:00
|
|
|
const exec = require('child_process').execSync;
|
2016-11-24 16:19:01 +01:00
|
|
|
|
2016-08-26 14:19:03 +02:00
|
|
|
/**
|
|
|
|
* A set of functions called "actions" for `Admin`
|
|
|
|
*/
|
|
|
|
|
|
|
|
module.exports = {
|
2017-11-09 11:25:01 +01:00
|
|
|
plugins: async ctx => {
|
|
|
|
try {
|
2017-11-09 13:30:54 +01:00
|
|
|
const plugins = Object.keys(strapi.plugins).reduce((acc, key) => {
|
|
|
|
acc[key] = strapi.plugins[key].package.strapi;
|
|
|
|
|
|
|
|
return acc;
|
|
|
|
}, {});
|
|
|
|
|
|
|
|
ctx.send({ plugins });
|
2017-11-09 11:25:01 +01:00
|
|
|
} catch(err) {
|
|
|
|
ctx.badRequest(null, [{ messages: [{ id: 'An error occured' }] }]);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-11-02 16:49:10 +01:00
|
|
|
uninstallPlugin: async ctx => {
|
|
|
|
try {
|
|
|
|
const { plugin } = ctx.params;
|
2017-11-03 14:13:47 +01:00
|
|
|
const strapiBin = path.join(process.cwd(), 'node_modules', 'strapi', 'bin', 'strapi');
|
2017-11-02 17:05:37 +01:00
|
|
|
|
|
|
|
strapi.reload.isWatching = false;
|
|
|
|
|
|
|
|
strapi.log.info(`Uninstalling ${plugin}...`);
|
2017-11-03 14:13:47 +01:00
|
|
|
exec(`node ${strapiBin} uninstall ${plugin}`);
|
2017-11-02 17:05:37 +01:00
|
|
|
|
2017-11-02 16:49:10 +01:00
|
|
|
ctx.send({ ok: true });
|
2017-11-02 17:05:37 +01:00
|
|
|
|
|
|
|
strapi.reload();
|
2017-11-02 16:49:10 +01:00
|
|
|
} catch(err) {
|
2017-11-02 17:05:37 +01:00
|
|
|
strapi.reload.isWatching = true;
|
2017-11-02 16:49:10 +01:00
|
|
|
ctx.badRequest(null, [{ messages: [{ id: 'An error occured' }] }]);
|
|
|
|
}
|
2016-08-26 14:19:03 +02:00
|
|
|
}
|
|
|
|
};
|