UNPKG

1.69 kBJavaScriptView Raw
1const Table = require('cli-table3');
2const moment = require('moment');
3const CoreObject = require('core-object');
4const RSVP = require('rsvp');
5
6module.exports = CoreObject.extend({
7 init(plugin, revisions) {
8 this._super(plugin, revisions);
9
10 this._plugin = plugin;
11 this.revisions = revisions;
12 },
13
14 display(/* revisions */) {
15 let table = this._createTable();
16 this._tableRows(table);
17
18 this._plugin.logRaw(table.toString());
19 return RSVP.resolve();
20 },
21
22 _isWide() {
23 return process.stdout.columns >= 98;
24 },
25
26 _tableHeader() {
27 let head = ['RevisionKey', 'Commit', 'User', 'Branch'];
28
29 if (this._isWide()) {
30 head.push('Deploy time');
31 }
32 return head;
33 },
34
35 _createTable() {
36 let head = this._tableHeader();
37
38 return new Table({
39 head: head,
40 wordWrap: true,
41 chars: {
42 'top': '',
43 'top-mid': '',
44 'top-left': '',
45 'top-right': '',
46 'bottom': '',
47 'mid': '',
48 'middle': '',
49 'mid-mid': '',
50 'bottom-mid': '',
51 'bottom-left': '',
52 'bottom-right': '',
53 'left': '',
54 'left-mid': '',
55 'right': '',
56 'right-mid': ''
57 }
58 });
59 },
60
61 _tableRows(table) {
62 this.revisions.forEach(function(revision) {
63 let data = revision.revisionData;
64
65 let row = [
66 ((revision.active) ? '> ' : ' ') + data.revisionKey,
67 data.scm.sha.substr(0,8),
68 data.scm.email,
69 data.scm.branch,
70 ];
71
72 if (this._isWide()) {
73 let value = moment(data.timestamp).format("YYYY/MM/DD HH:mm:ss");
74 row.push(value);
75 }
76
77 table.push(row);
78
79 }.bind(this));
80 },
81
82});