UNPKG

1.39 kBJavaScriptView Raw
1const Table = require( 'cli-table' );
2const chalk = require( 'chalk' );
3const nconf = require( 'nconf' );
4const moment = require( 'moment' );
5const sh = require( 'shelljs' );
6const util = require( '../lib/util' );
7
8/**
9 * The main command.
10 * @param {Object} program
11 */
12function list( program ) {
13 const optionJson = program.args[0].json;
14 const optionAll = program.args[0].all;
15 const json = [];
16
17 if ( !util.localProjectsExist() && !optionJson ) {
18 console.error( chalk`{red.bold No projects available.}` );
19 process.exit( 1 );
20 }
21
22 const localProjects = nconf.get( 'local_projects' );
23 const table = new Table({
24 head : [
25 chalk`{gray.bold project}`,
26 chalk`{gray.bold type}`,
27 chalk`{gray.bold url}`,
28 chalk`{gray.bold last updated}`,
29 ],
30 });
31
32 Object.keys( localProjects ).forEach( ( key ) => {
33 const slug = key;
34 const type = nconf.get( `local_projects:${key}:type` );
35 const url = nconf.get( `local_projects:${key}:url` );
36 const timeISO = nconf.get( `local_projects:${key}:last_updated` );
37 const humanizedTime = moment( timeISO ).fromNow();
38
39 json.push({
40 slug,
41 type,
42 url,
43 'last-updated' : timeISO,
44 });
45
46 table.push({
47 [chalk`{green.bold ${slug}}`] : [
48 type,
49 url,
50 humanizedTime,
51 ],
52 });
53 });
54
55 if ( optionJson ) {
56 console.log( JSON.stringify( json ) );
57 } else {
58 console.log( table.toString() );
59 }
60}
61
62module.exports = list;