Browse Source

now-list: format output

master
nkzawa 9 years ago
parent
commit
5df1bc6132
  1. 26
      bin/now-list
  2. 7
      package.json

26
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');
}

7
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",

Loading…
Cancel
Save