@contentstack/cli-utilities 1.4.1 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -30,7 +30,7 @@ class AuthHandler {
30
30
  this.authEmailKeyName = 'email';
31
31
  this.oauthAccessTokenKeyName = 'oauthAccessToken';
32
32
  this.oauthDateTimeKeyName = 'oauthDateTime';
33
- this.oauthUserUidKeyName = 'oauthUserUid';
33
+ this.oauthUserUidKeyName = 'userUid';
34
34
  this.oauthOrgUidKeyName = 'oauthOrgUid';
35
35
  this.oauthRefreshTokenKeyName = 'oauthRefreshToken';
36
36
  this.authorisationTypeKeyName = 'authorisationType';
package/lib/cli-ux.js CHANGED
@@ -10,7 +10,7 @@ Object.defineProperty(exports, "Flags", { enumerable: true, get: function () { r
10
10
  Object.defineProperty(exports, "Command", { enumerable: true, get: function () { return core_1.Command; } });
11
11
  const ora_1 = tslib_1.__importDefault(require("ora"));
12
12
  const message_handler_1 = tslib_1.__importDefault(require("./message-handler"));
13
- inquirer_1.default.registerPrompt('table', require('inquirer-table-prompt'));
13
+ inquirer_1.default.registerPrompt('table', require('./inquirer-table-prompt'));
14
14
  /**
15
15
  * CLI Interface
16
16
  */
package/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.stdout = exports.stderr = exports.execute = exports.ux = exports.flush = exports.settings = exports.toConfiguredId = exports.toStandardizedId = exports.tsPath = exports.toCached = exports.run = exports.Plugin = exports.Parser = exports.Interfaces = exports.HelpBase = exports.Help = exports.loadHelpClass = exports.Flags = exports.Errors = exports.Config = exports.CommandHelp = exports.Args = exports.Command = exports.flags = exports.args = exports.NodeCrypto = exports.printFlagDeprecation = exports.managementSDKInitiator = exports.managementSDKClient = exports.configHandler = exports.authHandler = exports.messageHandler = exports.CLIError = exports.cliux = exports.logger = void 0;
3
+ exports.TablePrompt = exports.stdout = exports.stderr = exports.execute = exports.ux = exports.flush = exports.settings = exports.toConfiguredId = exports.toStandardizedId = exports.tsPath = exports.toCached = exports.run = exports.Plugin = exports.Parser = exports.Interfaces = exports.HelpBase = exports.Help = exports.loadHelpClass = exports.Flags = exports.Errors = exports.Config = exports.CommandHelp = exports.Args = exports.Command = exports.flags = exports.args = exports.NodeCrypto = exports.printFlagDeprecation = exports.managementSDKInitiator = exports.managementSDKClient = exports.configHandler = exports.authHandler = exports.messageHandler = exports.CLIError = exports.cliux = exports.logger = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  var logger_1 = require("./logger");
6
6
  Object.defineProperty(exports, "logger", { enumerable: true, get: function () { return tslib_1.__importDefault(logger_1).default; } });
@@ -51,3 +51,5 @@ Object.defineProperty(exports, "ux", { enumerable: true, get: function () { retu
51
51
  Object.defineProperty(exports, "execute", { enumerable: true, get: function () { return core_1.execute; } });
52
52
  Object.defineProperty(exports, "stderr", { enumerable: true, get: function () { return core_1.stderr; } });
53
53
  Object.defineProperty(exports, "stdout", { enumerable: true, get: function () { return core_1.stdout; } });
54
+ var inquirer_table_prompt_1 = require("./inquirer-table-prompt");
55
+ Object.defineProperty(exports, "TablePrompt", { enumerable: true, get: function () { return tslib_1.__importDefault(inquirer_table_prompt_1).default; } });
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+ const chalk = require('chalk');
3
+ const figures = require('figures');
4
+ const Table = require('cli-table');
5
+ const cliCursor = require('cli-cursor');
6
+ const Base = require('inquirer/lib/prompts/base');
7
+ const observe = require('inquirer/lib/utils/events');
8
+ const { map, takeUntil } = require('rxjs/operators');
9
+ const Choices = require('inquirer/lib/objects/choices');
10
+ class TablePrompt extends Base {
11
+ /**
12
+ * Initialise the prompt
13
+ *
14
+ * @param {Object} questions
15
+ * @param {Object} rl
16
+ * @param {Object} answers
17
+ */
18
+ constructor(questions, rl, answers) {
19
+ super(questions, rl, answers);
20
+ this.selectAll = this.opt.selectAll || false;
21
+ const formattedRows = this.selectAll
22
+ ? [
23
+ {
24
+ name: 'Select All',
25
+ value: 'selectAll',
26
+ },
27
+ ...(this.opt.rows || []),
28
+ ]
29
+ : [];
30
+ this.columns = new Choices(this.opt.columns, []);
31
+ this.pointer = 0;
32
+ this.horizontalPointer = 0;
33
+ this.rows = new Choices(formattedRows, []);
34
+ this.values = this.columns.filter(() => true).map(() => undefined);
35
+ this.pageSize = this.opt.pageSize || 5;
36
+ }
37
+ /**
38
+ * Start the inquirer session
39
+ *
40
+ * @param {Function} callback
41
+ * @return {TablePrompt}
42
+ */
43
+ _run(callback) {
44
+ this.done = callback;
45
+ const events = observe(this.rl);
46
+ const validation = this.handleSubmitEvents(events.line.pipe(map(this.getCurrentValue.bind(this))));
47
+ validation.success.forEach(this.onEnd.bind(this));
48
+ validation.error.forEach(this.onError.bind(this));
49
+ events.keypress.forEach(({ key }) => {
50
+ switch (key.name) {
51
+ case 'left':
52
+ return this.onLeftKey();
53
+ case 'right':
54
+ return this.onRightKey();
55
+ }
56
+ });
57
+ events.normalizedUpKey.pipe(takeUntil(validation.success)).forEach(this.onUpKey.bind(this));
58
+ events.normalizedDownKey.pipe(takeUntil(validation.success)).forEach(this.onDownKey.bind(this));
59
+ events.spaceKey.pipe(takeUntil(validation.success)).forEach(this.onSpaceKey.bind(this));
60
+ if (this.rl.line) {
61
+ this.onKeypress();
62
+ }
63
+ cliCursor.hide();
64
+ this.render();
65
+ return this;
66
+ }
67
+ getCurrentValue() {
68
+ const currentValue = [];
69
+ this.rows.forEach((row, rowIndex) => {
70
+ currentValue.push(this.values[rowIndex]);
71
+ });
72
+ return currentValue;
73
+ }
74
+ onDownKey() {
75
+ const length = this.rows.realLength;
76
+ this.pointer = this.pointer < length - 1 ? this.pointer + 1 : this.pointer;
77
+ this.render();
78
+ }
79
+ onEnd(state) {
80
+ this.status = 'answered';
81
+ this.spaceKeyPressed = true;
82
+ this.render();
83
+ this.screen.done();
84
+ cliCursor.show();
85
+ if (this.selectAll) {
86
+ // remove select all row
87
+ const [, ...truncatedValue] = state.value;
88
+ this.done(truncatedValue);
89
+ }
90
+ else {
91
+ this.done(state.value);
92
+ }
93
+ }
94
+ onError(state) {
95
+ this.render(state.isValid);
96
+ }
97
+ onLeftKey() {
98
+ const length = this.columns.realLength;
99
+ this.horizontalPointer = this.horizontalPointer > 0 ? this.horizontalPointer - 1 : length - 1;
100
+ this.render();
101
+ }
102
+ onRightKey() {
103
+ const length = this.columns.realLength;
104
+ this.horizontalPointer = this.horizontalPointer < length - 1 ? this.horizontalPointer + 1 : 0;
105
+ this.render();
106
+ }
107
+ selectAllValues(value) {
108
+ let values = [];
109
+ for (let i = 0; i < this.rows.length; i++) {
110
+ values.push(value);
111
+ }
112
+ this.values = values;
113
+ }
114
+ onSpaceKey() {
115
+ var _a;
116
+ const value = this.columns.get(this.horizontalPointer).value;
117
+ const rowValue = ((_a = this.rows.get(this.pointer)) === null || _a === void 0 ? void 0 : _a.value) || '';
118
+ if (rowValue === 'selectAll') {
119
+ this.selectAllValues(value);
120
+ }
121
+ else {
122
+ this.values[this.pointer] = value;
123
+ }
124
+ this.spaceKeyPressed = true;
125
+ this.render();
126
+ }
127
+ onUpKey() {
128
+ this.pointer = this.pointer > 0 ? this.pointer - 1 : this.pointer;
129
+ this.render();
130
+ }
131
+ paginate() {
132
+ const middleOfPage = Math.floor(this.pageSize / 2);
133
+ const firstIndex = Math.max(0, this.pointer - middleOfPage);
134
+ const lastIndex = Math.min(firstIndex + this.pageSize - 1, this.rows.realLength - 1);
135
+ const lastPageOffset = this.pageSize - 1 - lastIndex + firstIndex;
136
+ return [Math.max(0, firstIndex - lastPageOffset), lastIndex];
137
+ }
138
+ render(error) {
139
+ let message = this.getQuestion();
140
+ let bottomContent = '';
141
+ if (!this.spaceKeyPressed) {
142
+ message +=
143
+ '(Press ' +
144
+ chalk.cyan.bold('<space>') +
145
+ ' to select, ' +
146
+ chalk.cyan.bold('<Up and Down>') +
147
+ ' to move rows, ' +
148
+ chalk.cyan.bold('<Left and Right>') +
149
+ ' to move columns)';
150
+ }
151
+ const [firstIndex, lastIndex] = this.paginate();
152
+ const table = new Table({
153
+ head: [chalk.reset.dim(`${firstIndex + 1}-${lastIndex} of ${this.rows.realLength - 1}`)].concat(this.columns.pluck('name').map((name) => chalk.reset.bold(name))),
154
+ });
155
+ this.rows.forEach((row, rowIndex) => {
156
+ if (rowIndex < firstIndex || rowIndex > lastIndex)
157
+ return;
158
+ const columnValues = [];
159
+ this.columns.forEach((column, columnIndex) => {
160
+ const isSelected = this.status !== 'answered' && this.pointer === rowIndex && this.horizontalPointer === columnIndex;
161
+ const value = column.value === this.values[rowIndex] ? figures.radioOn : figures.radioOff;
162
+ columnValues.push(`${isSelected ? '[' : ' '} ${value} ${isSelected ? ']' : ' '}`);
163
+ });
164
+ const chalkModifier = this.status !== 'answered' && this.pointer === rowIndex ? chalk.reset.bold.cyan : chalk.reset;
165
+ table.push({
166
+ [chalkModifier(row.name)]: columnValues,
167
+ });
168
+ });
169
+ message += '\n\n' + table.toString();
170
+ if (error) {
171
+ bottomContent = chalk.red('>> ') + error;
172
+ }
173
+ this.screen.render(message, bottomContent);
174
+ }
175
+ }
176
+ module.exports = TablePrompt;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentstack/cli-utilities",
3
- "version": "1.4.1",
3
+ "version": "1.4.2",
4
4
  "description": "Utilities for contentstack projects",
5
5
  "main": "lib/index.js",
6
6
  "types": "./types/index.d.ts",
@@ -40,7 +40,6 @@
40
40
  "inquirer": "8.2.4",
41
41
  "inquirer-search-checkbox": "^1.0.0",
42
42
  "inquirer-search-list": "^1.2.6",
43
- "inquirer-table-prompt": "git@github.com:kego1992/inquirer-table-prompt.git",
44
43
  "lodash": "^4.17.15",
45
44
  "open": "^8.4.2",
46
45
  "ora": "^5.4.0",