From 9b5e6b12371317356d9cb4600a4a574df305f63f Mon Sep 17 00:00:00 2001 From: Piotr Grzesik Date: Fri, 1 Oct 2021 11:50:18 +0200 Subject: [PATCH] refactor(CLI): Modern logs for `upgrade` command --- lib/plugins/standalone.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/plugins/standalone.js b/lib/plugins/standalone.js index 6b64c58de..91e5a5819 100644 --- a/lib/plugins/standalone.js +++ b/lib/plugins/standalone.js @@ -42,10 +42,18 @@ module.exports = class Standalone { } async upgrade() { + mainProgress.notice('Resolving latest standalone version', { isMainEvent: true }); const tagName = await standaloneUtils.resolveLatestTag(); const latestVersion = tagName.slice(1); if (latestVersion === currentVersion) { - this.serverless.cli.log('Already at latest version'); + legacy.log('Already at latest version'); + log.notice.skip( + `Already at latest version ${style.aside( + `(${Math.floor( + (Date.now() - this.serverless.pluginManager.commandRunStartTime) / 1000 + )}s)` + )}` + ); return; } const currentMajor = Number(currentVersion.split('.')[0]); @@ -64,7 +72,8 @@ module.exports = class Standalone { 'CANNOT_UPGRADE_MAJOR' ); } - this.serverless.cli.log('Downloading new version...'); + legacy.log('Downloading new version...'); + mainProgress.notice('Downloading latest standalone version', { isMainEvent: true }); const executableUrl = standaloneUtils.resolveUrl(tagName); const standaloneResponse = await fetch(executableUrl); if (!standaloneResponse.ok) { @@ -78,17 +87,21 @@ module.exports = class Standalone { await pipeline(standaloneResponse.body, fs.createWriteStream(BINARY_TMP_PATH)); await fsp.rename(BINARY_TMP_PATH, BINARY_PATH); await fsp.chmod(BINARY_PATH, 0o755); - this.serverless.cli.log(`Successfully upgraded to ${tagName}`); + legacy.log(`Successfully upgraded to ${tagName}`); + log.notice.success( + `Successfully upgraded to ${tagName} ${style.aside( + `(${Math.floor((Date.now() - this.serverless.pluginManager.commandRunStartTime) / 1000)}s)` + )}` + ); } async uninstall() { - const commandRunStartTime = Date.now(); mainProgress.notice('Uninstalling standalone binary', { isMainEvent: true }); await fse.remove(path.dirname(BINARY_PATH)); legacy.log('Uninstalled'); log.notice.success( `Standalone binary uninstalled ${style.aside( - `(${Math.floor((Date.now() - commandRunStartTime) / 1000)}s)` + `(${Math.floor((Date.now() - this.serverless.pluginManager.commandRunStartTime) / 1000)}s)` )}` ); }