1 |
|
2 | var Table = require('cli-table2');
|
3 | var moment = require('moment');
|
4 |
|
5 | var CoreObject = require('core-object');
|
6 | var Promise = require('ember-cli/lib/ext/promise');
|
7 |
|
8 | module.exports = CoreObject.extend({
|
9 | init: function(plugin, revisions) {
|
10 | this._plugin = plugin;
|
11 | this.revisions = revisions;
|
12 | },
|
13 |
|
14 | display: function(revisions) {
|
15 | var table = this._createTable();
|
16 | this._tableRows(table);
|
17 |
|
18 | this._plugin.logRaw(table.toString());
|
19 | return Promise.resolve();
|
20 | },
|
21 |
|
22 | _isWide: function() {
|
23 | return process.stdout.columns >= 98;
|
24 | },
|
25 |
|
26 | _tableHeader: function() {
|
27 | var head = ['RevisionKey', 'Commit', 'User', 'Branch'];
|
28 |
|
29 | if (this._isWide()) {
|
30 | head.push('Deploy time');
|
31 | }
|
32 | return head;
|
33 | },
|
34 |
|
35 | _createTable: function() {
|
36 | var 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: function(table) {
|
62 | this.revisions.forEach(function(revision) {
|
63 | var data = revision.revisionData;
|
64 |
|
65 | var 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 | var 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 | });
|