From bb15dae15bc50854c960074e02d9d149184ebc6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arwid=20Thornstro=CC=88m?= Date: Fri, 21 Oct 2022 21:03:50 +0200 Subject: [PATCH] updated listing in testserver status --- .../deployment/testservers/status/status.ts | 43 ++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/src/commands/deployment/testservers/status/status.ts b/src/commands/deployment/testservers/status/status.ts index 1c9a7b5..d309402 100644 --- a/src/commands/deployment/testservers/status/status.ts +++ b/src/commands/deployment/testservers/status/status.ts @@ -1,4 +1,5 @@ import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu' +import chalk = require('chalk'); import { defaultMenuSettings } from '../../../../globals'; const tto = require('terminal-table-output').create(); @@ -67,11 +68,49 @@ module.exports = { } } + const stackUrl = (stackname: string) => { + return `https://test-${stackname.split('photowall-test-')[1]}.photowall-test.com/us`; + }; + + const ellipsis = (a: string, max: number) => { + return a.length > max ? a.substr(0, max) + '..' : a; + }; + + const timeSince = (date: number) => { + const now = Date.now(); + var seconds = Math.floor((now - date) / 1000); + + var interval = seconds / 31536000; + + if (interval > 1) { + return Math.floor(interval) + " years"; + } + interval = seconds / 2592000; + if (interval > 1) { + return `${chalk.red(Math.floor(interval) + " months")}`; + } + interval = seconds / 86400; + if (interval > 1) { + const days = Math.floor(interval); + return `${chalk[days >= 14 ? 'yellow' : 'green'](days + " days")}`; + } + interval = seconds / 3600; + if (interval > 1) { + return `${chalk.green(Math.floor(interval) + " hours")}`; + } + interval = seconds / 60; + if (interval > 1) { + return `${chalk.green(Math.floor(interval) + " minutes")}`; + } + return Math.floor(seconds) + " seconds"; + } + tto.line('-'); - tto.pushrow(['| status', 'stack', 'branch', 'updated']) + tto.pushrow(['| status', 'stack', 'branch', 'time since update', 'url']) .line('-'); for (const stack of curratedStacks) { - tto.pushrow([status(stack.status), stack.name, stack.branch, stack.updated]); + const t = new Date(stack.updated); + tto.pushrow([status(stack.status), stack.name, ellipsis(stack.branch, 24), timeSince(t.getTime()), stackUrl(stack.name)]); } tto.print(true);