From 62803800544d7293bcb30302820b223423ad21b3 Mon Sep 17 00:00:00 2001 From: Opeyemi Ibrahim Date: Tue, 2 Jul 2024 15:13:18 +0100 Subject: [PATCH 1/2] :bug: Fixed uninstall error during cleanup for plugin that is not installed --- utils/commands.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/utils/commands.ts b/utils/commands.ts index 84a172c..72bd9bd 100644 --- a/utils/commands.ts +++ b/utils/commands.ts @@ -231,6 +231,17 @@ export async function activatePlugin(name: string): Promise { } } +/** + * Check if plugin is installed + * @function + * @name activatePlugin + * @async + * @param {string} name - The name of the plugin to be checked if installed. + * @returns {Promise} - A Promise that resolves when the check is completed. + */ +export async function isPluginInstalled(name: string): Promise { + return await wp(`plugin is-installed ${name}`) +} /** @@ -256,7 +267,9 @@ export async function installRemotePlugin(url: string): Promise { * @returns {Promise} - A Promise that resolves when the uninstallation is completed. */ export async function uninstallPlugin(plugin: string): Promise { - await wp(`plugin uninstall --deactivate ${plugin}`); + if(await isPluginInstalled(plugin)) { + await wp(`plugin uninstall --deactivate ${plugin}`); + } } /** From 4162dabe1403647ad1aaa0ded30d21d533781819 Mon Sep 17 00:00:00 2001 From: Opeyemi Ibrahim Date: Mon, 8 Jul 2024 13:29:15 +0100 Subject: [PATCH 2/2] :feat: Add option to show error or disable error --- utils/commands.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/utils/commands.ts b/utils/commands.ts index 72bd9bd..175c9b5 100644 --- a/utils/commands.ts +++ b/utils/commands.ts @@ -40,9 +40,10 @@ function wrapPrefix(command: string): string { * @name wp * @async * @param {string} args - Arguments to be passed to the WP-CLI command. + * @param {boolean} show_errors - Show error * @returns {Promise} - A Promise that resolves when the command is executed. */ -async function wp(args: string): Promise { +async function wp(args: string, show_errors: boolean = true): Promise { const root = configurations.type === ServerType.docker ? ' --allow-root': ''; const cwd = getWPDir(configurations); @@ -53,9 +54,13 @@ async function wp(args: string): Promise { username: configurations.ssh.username, privateKeyPath: configurations.ssh.key }) + const result = await client.execCommand(`wp ${args}${root} --path=${cwd}`); + if(result.code === 1) { - console.error('Error :', result.stderr); + if(show_errors){ + console.error('Error :', result.stderr); + } return false } return true; @@ -240,7 +245,7 @@ export async function activatePlugin(name: string): Promise { * @returns {Promise} - A Promise that resolves when the check is completed. */ export async function isPluginInstalled(name: string): Promise { - return await wp(`plugin is-installed ${name}`) + return await wp(`plugin is-installed ${name}`, false); }