Skip to content

Commit

Permalink
refactor(CLI): Modern logs for upgrade command
Browse files Browse the repository at this point in the history
  • Loading branch information
pgrzesik committed Oct 4, 2021
1 parent 2787ea0 commit 9b5e6b1
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions lib/plugins/standalone.js
Expand Up @@ -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]);
Expand All @@ -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) {
Expand All @@ -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)`
)}`
);
}
Expand Down

0 comments on commit 9b5e6b1

Please sign in to comment.