44 lines
1.0 KiB
JavaScript
Raw Normal View History

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-08-26 14:19:03 +02:00
/**
* A set of functions called "actions" for `Admin`
*/
module.exports = {
plugins: async ctx => {
try {
const plugins = Object.keys(strapi.plugins).reduce((acc, key) => {
acc[key] = strapi.plugins[key].package.strapi;
return acc;
}, {});
ctx.send({ plugins });
} catch(err) {
ctx.badRequest(null, [{ messages: [{ id: 'An error occured' }] }]);
}
},
uninstallPlugin: async ctx => {
try {
const { plugin } = ctx.params;
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}...`);
exec(`node ${strapiBin} uninstall ${plugin}`);
2017-11-02 17:05:37 +01:00
ctx.send({ ok: true });
2017-11-02 17:05:37 +01:00
strapi.reload();
} catch(err) {
2017-11-02 17:05:37 +01:00
strapi.reload.isWatching = true;
ctx.badRequest(null, [{ messages: [{ id: 'An error occured' }] }]);
}
2016-08-26 14:19:03 +02:00
}
};