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