mirror of
https://github.com/strapi/strapi.git
synced 2025-11-02 02:44:55 +00:00
Add Delete files option to strapi uninstall
This commit is contained in:
parent
f90f6638e8
commit
8c209020d0
@ -90,7 +90,7 @@ module.exports = {
|
||||
strapi.reload.isWatching = false;
|
||||
|
||||
strapi.log.info(`Uninstalling ${plugin}...`);
|
||||
await execa('npm', ['run', 'strapi', '--', 'uninstall', plugin]);
|
||||
await execa('npm', ['run', 'strapi', '--', 'uninstall', plugin, '-d']);
|
||||
|
||||
ctx.send({ ok: true });
|
||||
|
||||
|
||||
@ -167,6 +167,7 @@ program
|
||||
program
|
||||
.command('uninstall [plugins...]')
|
||||
.description('uninstall a Strapi plugin')
|
||||
.option('-d, --delete-files', 'Delete files', false)
|
||||
.action(getLocalScript('uninstall'));
|
||||
|
||||
/**
|
||||
|
||||
@ -1,25 +1,33 @@
|
||||
'use strict';
|
||||
|
||||
const { join } = require('path');
|
||||
const { existsSync } = require('fs-extra');
|
||||
const { existsSync, rmdirSync } = require('fs-extra');
|
||||
const ora = require('ora');
|
||||
const execa = require('execa');
|
||||
const inquirer = require('inquirer');
|
||||
const { cli } = require('strapi-utils');
|
||||
const findPackagePath = require('../load/package-path');
|
||||
|
||||
module.exports = async plugins => {
|
||||
module.exports = async (plugins, { deleteFiles }) => {
|
||||
if (!cli.isStrapiApp()) {
|
||||
return console.log(
|
||||
`⛔️ ${cyan('strapi install')} can only be used inside a Strapi project.`
|
||||
);
|
||||
}
|
||||
|
||||
const answers = await inquirer.prompt([
|
||||
{
|
||||
type: 'confirm',
|
||||
name: 'deleteFiles',
|
||||
default: true,
|
||||
when: !deleteFiles,
|
||||
},
|
||||
]);
|
||||
|
||||
const loader = ora();
|
||||
const dir = process.cwd();
|
||||
|
||||
const version = require(join(dir, 'package.json')).dependencies.strapi;
|
||||
|
||||
const pluginArgs = plugins.map(name => `strapi-plugin-${name}@${version}`);
|
||||
const pluginArgs = plugins.map(name => `strapi-plugin-${name}`);
|
||||
|
||||
try {
|
||||
// verify should rebuild before removing the pacakge
|
||||
@ -42,6 +50,17 @@ module.exports = async plugins => {
|
||||
|
||||
loader.succeed();
|
||||
|
||||
if (deleteFiles === true || answers.deleteFiles === true) {
|
||||
loader.start('Deleting old files');
|
||||
for (let name of plugins) {
|
||||
const pluginDir = join(dir, 'extensions', name);
|
||||
if (existsSync(pluginDir)) {
|
||||
rmdirSync();
|
||||
}
|
||||
}
|
||||
loader.succeed();
|
||||
}
|
||||
|
||||
if (shouldRebuild) {
|
||||
loader.start(`Rebuilding admin UI`);
|
||||
await execa('npm', ['run', 'build']);
|
||||
|
||||
@ -30,6 +30,7 @@
|
||||
"strapi": "./bin/strapi.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"inquirer": "^6.2.1",
|
||||
"async": "^2.1.2",
|
||||
"boom": "^5.2.0",
|
||||
"chalk": "^2.4.1",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user