UNPKG

1.05 kBJavaScriptView Raw
1const Table = require( 'cli-table' );
2const chalk = require( 'chalk' );
3const nconf = require( 'nconf' );
4const moment = require( 'moment' );
5const util = require( '../lib/util' );
6
7/**
8 * The main command.
9 */
10function list() {
11 if ( !util.localProjectsExist() ) {
12 console.error( chalk`{red.bold No projects available.}` );
13 process.exit( 1 );
14 }
15
16 const localProjects = nconf.get( 'local_projects' );
17 const table = new Table({
18 head : [
19 chalk`{gray.bold Project}`,
20 chalk`{gray.bold Type}`,
21 chalk`{gray.bold Url}`,
22 chalk`{gray.bold Last Updated}`,
23 ],
24 });
25
26 Object.keys( localProjects ).forEach( ( key ) => {
27 const slug = key;
28 const type = nconf.get( `local_projects:${key}:type` );
29 const url = nconf.get( `local_projects:${key}:url` );
30 const timeISO = nconf.get( `local_projects:${key}:last_updated` );
31 const humanizedTime = moment( timeISO ).fromNow();
32
33 table.push({
34 [chalk`{green ${slug}}`] : [
35 type,
36 url,
37 humanizedTime,
38 ],
39 });
40 });
41
42 console.log( table.toString() );
43}
44
45module.exports = list;