From 5df1bc613213a5c34f2e0d4996819f2a440b571a Mon Sep 17 00:00:00 2001 From: nkzawa Date: Sat, 16 Apr 2016 17:32:42 +0900 Subject: [PATCH] now-list: format output --- bin/now-list | 26 +++++++++++++++++++++++++- package.json | 7 ++++--- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/bin/now-list b/bin/now-list index 25310d3..667e760 100755 --- a/bin/now-list +++ b/bin/now-list @@ -1,6 +1,9 @@ #!/usr/bin/env node import minimist from 'minimist'; +import chalk from 'chalk'; +import table from 'text-table'; +import ms from 'ms'; import Now from '../lib'; import login from '../lib/login'; import * as cfg from '../lib/cfg'; @@ -40,5 +43,26 @@ async function list (token) { process.exit(1); } - console.log(deployments); + now.close(); + + const apps = new Map(); + for (const dep of deployments) { + const deps = apps.get(dep.name) || []; + apps.set(dep.name, deps.concat(dep)); + } + + const current = Date.now(); + const text = [...apps].map(([name, deps]) => { + const t = table(deps.map(({ uid, url, created }) => { + const time = ms(current - created, { long: true }) + ' ago'; + return [ uid, time, `https://${url}` ]; + }), { align: ['l', 'r', 'l'] }); + return chalk.bold(name) + '\n\n' + indent(t, 2).split('\n').join('\n\n'); + }).join('\n\n'); + + if (text) console.log('\n' + text + '\n'); +} + +function indent (text, n) { + return text.split('\n').map((l) => ' '.repeat(n) + l).join('\n'); } diff --git a/package.json b/package.json index 2461c5b..8b408b3 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "now": "./build/bin/now" }, "dependencies": { + "ansi-escapes": "1.3.0", "arr-flatten": "1.0.1", "array-unique": "0.2.1", "babel-runtime": "6.6.1", @@ -20,15 +21,15 @@ "fs-promise": "0.4.1", "graceful-fs": "4.1.3", "minimatch": "3.0.0", + "minimist": "1.2.0", "ms": "0.7.1", "node-fetch": "1.3.3", "progress": "1.1.8", "resumer": "0.0.0", "retry": "0.9.0", + "socket.io-client": "1.4.5", "split-array": "1.0.1", - "minimist": "1.2.0", - "ansi-escapes": "1.3.0", - "socket.io-client": "1.4.5" + "text-table": "0.2.0" }, "devDependencies": { "alpha-sort": "1.0.2",