diff --git a/utils/commands.ts b/utils/commands.ts index 84a172c..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; @@ -231,6 +236,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}`, false); +} /** @@ -256,7 +272,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}`); + } } /**