@contentstack/cli-utilities 2.0.0-beta.1 → 2.0.0-beta.10
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.
- package/lib/auth-handler.d.ts +5 -2
- package/lib/auth-handler.js +29 -29
- package/lib/chalk.d.ts +15 -0
- package/lib/chalk.js +66 -0
- package/lib/cli-ux.js +23 -10
- package/lib/config-handler.js +4 -4
- package/lib/constants/logging.js +2 -2
- package/lib/content-type-utils.d.ts +2 -2
- package/lib/content-type-utils.js +10 -8
- package/lib/contentstack-management-sdk.js +14 -4
- package/lib/contentstack-marketplace-sdk.d.ts +2 -2
- package/lib/contentstack-marketplace-sdk.js +1 -1
- package/lib/fs-utility/core.d.ts +0 -1
- package/lib/fs-utility/core.js +2 -6
- package/lib/fs-utility/helper.js +2 -3
- package/lib/helpers.d.ts +3 -1
- package/lib/helpers.js +14 -4
- package/lib/http-client/client.d.ts +2 -2
- package/lib/http-client/client.js +22 -2
- package/lib/http-client/http-response.d.ts +1 -1
- package/lib/http-client/http-response.js +1 -0
- package/lib/index.d.ts +3 -1
- package/lib/index.js +4 -1
- package/lib/inquirer-table-prompt.d.ts +49 -28
- package/lib/inquirer-table-prompt.js +144 -136
- package/lib/interfaces/index.d.ts +3 -1
- package/lib/logger/cli-error-handler.js +1 -1
- package/lib/logger/log.js +4 -4
- package/lib/logger/session-path.d.ts +5 -0
- package/lib/logger/session-path.js +18 -3
- package/lib/message-handler.d.ts +0 -3
- package/lib/message-handler.js +6 -10
- package/lib/progress-summary/cli-progress-manager.js +39 -35
- package/lib/progress-summary/summary-manager.js +30 -30
- package/lib/proxy-helper.d.ts +42 -1
- package/lib/proxy-helper.js +183 -32
- package/package.json +29 -28
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DefaultProgressStrategy = exports.CustomProgressStrategy = exports.ProgressStrategyRegistry = exports.PrimaryProcessStrategy = exports.SummaryManager = exports.CLIProgressManager = exports.getSessionLogPath = exports.getLogPath = exports.handleAndLogError = exports.cliErrorHandler = exports.log = exports.authenticationHandler = exports.Logger = exports.TablePrompt = exports.execute = exports.ux = exports.flush = exports.settings = exports.toConfiguredId = exports.toStandardizedId = exports.
|
|
3
|
+
exports.DefaultProgressStrategy = exports.CustomProgressStrategy = exports.ProgressStrategyRegistry = exports.PrimaryProcessStrategy = exports.SummaryManager = exports.CLIProgressManager = exports.getSessionLogPath = exports.getLogPath = exports.handleAndLogError = exports.cliErrorHandler = exports.log = exports.authenticationHandler = exports.Logger = exports.getChalk = exports.loadChalk = exports.TablePrompt = exports.execute = exports.ux = exports.flush = exports.settings = exports.toConfiguredId = exports.toStandardizedId = exports.Plugin = exports.Parser = exports.Interfaces = exports.HelpBase = exports.Help = exports.loadHelpClass = exports.Flags = exports.Errors = exports.Config = exports.CommandHelp = exports.Args = exports.marketplaceSDKInitiator = exports.MarketplaceSDKInitiator = exports.marketplaceSDKClient = exports.CLITable = exports.createLogContext = exports.Command = exports.flags = exports.args = exports.NodeCrypto = exports.managementSDKInitiator = exports.managementSDKClient = exports.configHandler = exports.authHandler = exports.messageHandler = exports.CLIError = exports.cliux = exports.LoggerService = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const logger_1 = tslib_1.__importDefault(require("./logger"));
|
|
6
6
|
exports.Logger = logger_1.default;
|
|
@@ -64,6 +64,9 @@ Object.defineProperty(exports, "ux", { enumerable: true, get: function () { retu
|
|
|
64
64
|
Object.defineProperty(exports, "execute", { enumerable: true, get: function () { return core_1.execute; } });
|
|
65
65
|
var inquirer_table_prompt_1 = require("./inquirer-table-prompt");
|
|
66
66
|
Object.defineProperty(exports, "TablePrompt", { enumerable: true, get: function () { return tslib_1.__importDefault(inquirer_table_prompt_1).default; } });
|
|
67
|
+
var chalk_1 = require("./chalk");
|
|
68
|
+
Object.defineProperty(exports, "loadChalk", { enumerable: true, get: function () { return chalk_1.loadChalk; } });
|
|
69
|
+
Object.defineProperty(exports, "getChalk", { enumerable: true, get: function () { return chalk_1.getChalk; } });
|
|
67
70
|
var authentication_handler_1 = require("./authentication-handler");
|
|
68
71
|
Object.defineProperty(exports, "authenticationHandler", { enumerable: true, get: function () { return tslib_1.__importDefault(authentication_handler_1).default; } });
|
|
69
72
|
var log_1 = require("./logger/log");
|
|
@@ -1,30 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Table prompt for inquirer v12.
|
|
3
|
+
* Standalone implementation (no inquirer/lib) compatible with
|
|
4
|
+
* inquirer 12 legacy adapter: constructor(question, rl, answers) + run() returns Promise.
|
|
5
|
+
*/
|
|
6
|
+
import * as readline from 'readline';
|
|
7
|
+
interface ChoiceLike {
|
|
8
|
+
name?: string;
|
|
9
|
+
value?: string;
|
|
10
|
+
}
|
|
11
|
+
interface TableQuestion {
|
|
12
|
+
message?: string;
|
|
13
|
+
name?: string;
|
|
14
|
+
columns?: ChoiceLike[];
|
|
15
|
+
rows?: ChoiceLike[];
|
|
16
|
+
selectAll?: boolean;
|
|
17
|
+
pageSize?: number;
|
|
18
|
+
}
|
|
19
|
+
type ReadLine = readline.Interface & {
|
|
20
|
+
input: NodeJS.ReadableStream;
|
|
21
|
+
output: NodeJS.WritableStream;
|
|
22
|
+
};
|
|
23
|
+
declare class TablePrompt {
|
|
24
|
+
private question;
|
|
25
|
+
private rl;
|
|
26
|
+
private selectAll;
|
|
27
|
+
private columns;
|
|
28
|
+
private rows;
|
|
29
|
+
private pointer;
|
|
30
|
+
private horizontalPointer;
|
|
31
|
+
private values;
|
|
32
|
+
private pageSize;
|
|
33
|
+
private spaceKeyPressed;
|
|
34
|
+
private status;
|
|
35
|
+
private done;
|
|
36
|
+
private lastHeight;
|
|
37
|
+
constructor(question: TableQuestion, rl: ReadLine, _answers: Record<string, unknown>);
|
|
38
|
+
run(): Promise<(string | undefined)[]>;
|
|
39
|
+
private getCurrentValue;
|
|
40
|
+
private onSubmit;
|
|
41
|
+
private onUpKey;
|
|
42
|
+
private onDownKey;
|
|
43
|
+
private onLeftKey;
|
|
44
|
+
private onRightKey;
|
|
45
|
+
private selectAllValues;
|
|
46
|
+
private onSpaceKey;
|
|
47
|
+
private paginate;
|
|
48
|
+
private getMessage;
|
|
49
|
+
private render;
|
|
29
50
|
}
|
|
30
51
|
export = TablePrompt;
|
|
@@ -1,120 +1,125 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
]
|
|
29
|
-
: [];
|
|
30
|
-
this.columns = new Choices(this.opt.columns, []);
|
|
2
|
+
/**
|
|
3
|
+
* Table prompt for inquirer v12.
|
|
4
|
+
* Standalone implementation (no inquirer/lib) compatible with
|
|
5
|
+
* inquirer 12 legacy adapter: constructor(question, rl, answers) + run() returns Promise.
|
|
6
|
+
*/
|
|
7
|
+
const tslib_1 = require("tslib");
|
|
8
|
+
const chalk_1 = require("./chalk");
|
|
9
|
+
const figures_1 = tslib_1.__importDefault(require("figures"));
|
|
10
|
+
const cli_cursor_1 = tslib_1.__importDefault(require("cli-cursor"));
|
|
11
|
+
const cli_table_1 = tslib_1.__importDefault(require("cli-table"));
|
|
12
|
+
function pluckName(c) {
|
|
13
|
+
var _a, _b;
|
|
14
|
+
return (_a = c.name) !== null && _a !== void 0 ? _a : String((_b = c.value) !== null && _b !== void 0 ? _b : '');
|
|
15
|
+
}
|
|
16
|
+
function getValue(c) {
|
|
17
|
+
var _a, _b;
|
|
18
|
+
return (_b = (_a = c.value) !== null && _a !== void 0 ? _a : c.name) !== null && _b !== void 0 ? _b : '';
|
|
19
|
+
}
|
|
20
|
+
class TablePrompt {
|
|
21
|
+
constructor(question, rl, _answers) {
|
|
22
|
+
this.question = question;
|
|
23
|
+
this.rl = rl;
|
|
24
|
+
this.selectAll = Boolean(question.selectAll);
|
|
25
|
+
this.columns = Array.isArray(question.columns) ? question.columns : [];
|
|
26
|
+
this.rows = this.selectAll
|
|
27
|
+
? [{ name: 'Select All', value: 'selectAll' }, ...(question.rows || [])]
|
|
28
|
+
: Array.isArray(question.rows) ? question.rows : [];
|
|
31
29
|
this.pointer = 0;
|
|
32
30
|
this.horizontalPointer = 0;
|
|
33
|
-
this.
|
|
34
|
-
this.
|
|
35
|
-
this.
|
|
31
|
+
this.values = this.columns.map(() => undefined);
|
|
32
|
+
this.pageSize = Number(question.pageSize) || 5;
|
|
33
|
+
this.spaceKeyPressed = false;
|
|
34
|
+
this.status = 'idle';
|
|
35
|
+
this.done = null;
|
|
36
|
+
this.lastHeight = 0;
|
|
36
37
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
38
|
+
run() {
|
|
39
|
+
return new Promise((resolve) => {
|
|
40
|
+
this.done = (value) => {
|
|
41
|
+
this.status = 'answered';
|
|
42
|
+
cli_cursor_1.default.show();
|
|
43
|
+
resolve(value);
|
|
44
|
+
};
|
|
45
|
+
const onKeypress = (_str, key) => {
|
|
46
|
+
if (this.status === 'answered')
|
|
47
|
+
return;
|
|
48
|
+
if (key.ctrl && key.name === 'c')
|
|
49
|
+
return;
|
|
50
|
+
switch (key.name) {
|
|
51
|
+
case 'up':
|
|
52
|
+
this.onUpKey();
|
|
53
|
+
break;
|
|
54
|
+
case 'down':
|
|
55
|
+
this.onDownKey();
|
|
56
|
+
break;
|
|
57
|
+
case 'left':
|
|
58
|
+
this.onLeftKey();
|
|
59
|
+
break;
|
|
60
|
+
case 'right':
|
|
61
|
+
this.onRightKey();
|
|
62
|
+
break;
|
|
63
|
+
case 'space':
|
|
64
|
+
this.onSpaceKey();
|
|
65
|
+
break;
|
|
66
|
+
case 'enter':
|
|
67
|
+
case 'return':
|
|
68
|
+
this.onSubmit();
|
|
69
|
+
break;
|
|
70
|
+
default:
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
this.render();
|
|
74
|
+
};
|
|
75
|
+
this.rl.input.on('keypress', onKeypress);
|
|
76
|
+
cli_cursor_1.default.hide();
|
|
77
|
+
this.render();
|
|
56
78
|
});
|
|
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
79
|
}
|
|
67
80
|
getCurrentValue() {
|
|
68
|
-
const
|
|
69
|
-
this.rows.
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
return
|
|
73
|
-
}
|
|
74
|
-
onDownKey() {
|
|
75
|
-
const length = this.rows.realLength;
|
|
76
|
-
this.pointer = this.pointer < length - 1 ? this.pointer + 1 : this.pointer;
|
|
77
|
-
this.render();
|
|
81
|
+
const out = [];
|
|
82
|
+
for (let i = 0; i < this.rows.length; i++) {
|
|
83
|
+
out.push(this.values[i]);
|
|
84
|
+
}
|
|
85
|
+
return out;
|
|
78
86
|
}
|
|
79
|
-
|
|
80
|
-
this.
|
|
81
|
-
|
|
82
|
-
this.
|
|
83
|
-
this.
|
|
84
|
-
|
|
85
|
-
if (this.selectAll) {
|
|
86
|
-
// remove select all row
|
|
87
|
-
const [, ...truncatedValue] = state.value;
|
|
88
|
-
this.done(truncatedValue);
|
|
87
|
+
onSubmit() {
|
|
88
|
+
if (!this.done)
|
|
89
|
+
return;
|
|
90
|
+
const raw = this.getCurrentValue();
|
|
91
|
+
if (this.selectAll && raw.length > 0) {
|
|
92
|
+
this.done(raw.slice(1));
|
|
89
93
|
}
|
|
90
94
|
else {
|
|
91
|
-
this.done(
|
|
95
|
+
this.done(raw);
|
|
92
96
|
}
|
|
93
97
|
}
|
|
94
|
-
|
|
95
|
-
this.
|
|
98
|
+
onUpKey() {
|
|
99
|
+
this.pointer = this.pointer > 0 ? this.pointer - 1 : this.pointer;
|
|
100
|
+
}
|
|
101
|
+
onDownKey() {
|
|
102
|
+
const len = this.rows.length;
|
|
103
|
+
this.pointer = this.pointer < len - 1 ? this.pointer + 1 : this.pointer;
|
|
96
104
|
}
|
|
97
105
|
onLeftKey() {
|
|
98
|
-
const
|
|
99
|
-
this.horizontalPointer = this.horizontalPointer > 0 ? this.horizontalPointer - 1 :
|
|
100
|
-
this.render();
|
|
106
|
+
const len = this.columns.length;
|
|
107
|
+
this.horizontalPointer = this.horizontalPointer > 0 ? this.horizontalPointer - 1 : len - 1;
|
|
101
108
|
}
|
|
102
109
|
onRightKey() {
|
|
103
|
-
const
|
|
104
|
-
this.horizontalPointer = this.horizontalPointer <
|
|
105
|
-
this.render();
|
|
110
|
+
const len = this.columns.length;
|
|
111
|
+
this.horizontalPointer = this.horizontalPointer < len - 1 ? this.horizontalPointer + 1 : 0;
|
|
106
112
|
}
|
|
107
113
|
selectAllValues(value) {
|
|
108
|
-
|
|
109
|
-
for (let i = 0; i < this.rows.length; i++) {
|
|
110
|
-
values.push(value);
|
|
111
|
-
}
|
|
112
|
-
this.values = values;
|
|
114
|
+
this.values = this.rows.map(() => value);
|
|
113
115
|
}
|
|
114
116
|
onSpaceKey() {
|
|
115
|
-
|
|
116
|
-
const
|
|
117
|
-
|
|
117
|
+
const col = this.columns[this.horizontalPointer];
|
|
118
|
+
const row = this.rows[this.pointer];
|
|
119
|
+
if (!col)
|
|
120
|
+
return;
|
|
121
|
+
const value = getValue(col);
|
|
122
|
+
const rowValue = row ? getValue(row) : '';
|
|
118
123
|
if (rowValue === 'selectAll') {
|
|
119
124
|
this.selectAllValues(value);
|
|
120
125
|
}
|
|
@@ -122,55 +127,58 @@ class TablePrompt extends Base {
|
|
|
122
127
|
this.values[this.pointer] = value;
|
|
123
128
|
}
|
|
124
129
|
this.spaceKeyPressed = true;
|
|
125
|
-
this.render();
|
|
126
|
-
}
|
|
127
|
-
onUpKey() {
|
|
128
|
-
this.pointer = this.pointer > 0 ? this.pointer - 1 : this.pointer;
|
|
129
|
-
this.render();
|
|
130
130
|
}
|
|
131
131
|
paginate() {
|
|
132
|
-
const
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
132
|
+
const mid = Math.floor(this.pageSize / 2);
|
|
133
|
+
const len = this.rows.length;
|
|
134
|
+
let first = Math.max(0, this.pointer - mid);
|
|
135
|
+
let last = Math.min(first + this.pageSize - 1, len - 1);
|
|
136
|
+
const offset = this.pageSize - 1 - (last - first);
|
|
137
|
+
first = Math.max(0, first - offset);
|
|
138
|
+
return [first, last];
|
|
137
139
|
}
|
|
138
|
-
|
|
139
|
-
let
|
|
140
|
-
let bottomContent = '';
|
|
140
|
+
getMessage() {
|
|
141
|
+
let msg = this.question.message || 'Select';
|
|
141
142
|
if (!this.spaceKeyPressed) {
|
|
142
|
-
|
|
143
|
-
'(Press ' +
|
|
144
|
-
|
|
143
|
+
msg +=
|
|
144
|
+
' (Press ' +
|
|
145
|
+
(0, chalk_1.getChalk)().cyan.bold('<space>') +
|
|
145
146
|
' to select, ' +
|
|
146
|
-
|
|
147
|
-
'
|
|
148
|
-
|
|
149
|
-
'
|
|
147
|
+
(0, chalk_1.getChalk)().cyan.bold('<Up/Down>') +
|
|
148
|
+
' rows, ' +
|
|
149
|
+
(0, chalk_1.getChalk)().cyan.bold('<Left/Right>') +
|
|
150
|
+
' columns, ' +
|
|
151
|
+
(0, chalk_1.getChalk)().cyan.bold('<Enter>') +
|
|
152
|
+
' to confirm)';
|
|
150
153
|
}
|
|
154
|
+
return msg;
|
|
155
|
+
}
|
|
156
|
+
render() {
|
|
151
157
|
const [firstIndex, lastIndex] = this.paginate();
|
|
152
|
-
const table = new
|
|
153
|
-
head: [
|
|
158
|
+
const table = new cli_table_1.default({
|
|
159
|
+
head: [(0, chalk_1.getChalk)().reset.dim(`${firstIndex + 1}-${lastIndex + 1} of ${this.rows.length}`)].concat(this.columns.map((c) => (0, chalk_1.getChalk)().reset.bold(pluckName(c)))),
|
|
154
160
|
});
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
161
|
+
for (let rowIndex = firstIndex; rowIndex <= lastIndex; rowIndex++) {
|
|
162
|
+
const row = this.rows[rowIndex];
|
|
163
|
+
if (!row)
|
|
164
|
+
continue;
|
|
158
165
|
const columnValues = [];
|
|
159
|
-
this.columns.
|
|
160
|
-
const isSelected = this.status !== 'answered' && this.pointer === rowIndex && this.horizontalPointer ===
|
|
161
|
-
const
|
|
162
|
-
columnValues.push(`${isSelected ? '[' : ' '} ${
|
|
163
|
-
}
|
|
164
|
-
const chalkModifier = this.status !== 'answered' && this.pointer === rowIndex ?
|
|
165
|
-
table.push({
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
if (
|
|
171
|
-
|
|
166
|
+
for (let colIndex = 0; colIndex < this.columns.length; colIndex++) {
|
|
167
|
+
const isSelected = this.status !== 'answered' && this.pointer === rowIndex && this.horizontalPointer === colIndex;
|
|
168
|
+
const cellValue = getValue(this.columns[colIndex]) === this.values[rowIndex] ? figures_1.default.radioOn : figures_1.default.radioOff;
|
|
169
|
+
columnValues.push(`${isSelected ? '[' : ' '} ${cellValue} ${isSelected ? ']' : ' '}`);
|
|
170
|
+
}
|
|
171
|
+
const chalkModifier = this.status !== 'answered' && this.pointer === rowIndex ? (0, chalk_1.getChalk)().reset.bold.cyan : (0, chalk_1.getChalk)().reset;
|
|
172
|
+
table.push({ [chalkModifier(pluckName(row))]: columnValues });
|
|
173
|
+
}
|
|
174
|
+
const message = this.getMessage() + '\n\n' + table.toString();
|
|
175
|
+
const lines = message.split('\n').length;
|
|
176
|
+
const out = this.rl.output;
|
|
177
|
+
if (this.lastHeight > 0) {
|
|
178
|
+
out.write('\u001b[' + this.lastHeight + 'A\u001b[0J');
|
|
172
179
|
}
|
|
173
|
-
|
|
180
|
+
out.write(message);
|
|
181
|
+
this.lastHeight = lines;
|
|
174
182
|
}
|
|
175
183
|
}
|
|
176
184
|
module.exports = TablePrompt;
|
|
@@ -17,7 +17,7 @@ export interface InquirePayload {
|
|
|
17
17
|
default?: any;
|
|
18
18
|
message: string;
|
|
19
19
|
choices?: Array<any>;
|
|
20
|
-
transformer?:
|
|
20
|
+
transformer?: (value: any) => any;
|
|
21
21
|
validate?(input: any, answers?: any): boolean | string | Promise<boolean | string>;
|
|
22
22
|
selectAll?: boolean;
|
|
23
23
|
pageSize?: number;
|
|
@@ -150,3 +150,5 @@ export interface ProgressResult {
|
|
|
150
150
|
success: number;
|
|
151
151
|
failures: number;
|
|
152
152
|
}
|
|
153
|
+
export type Answers = Record<string, unknown>;
|
|
154
|
+
export type InquirerQuestion = InquirePayload;
|
|
@@ -174,7 +174,7 @@ class CLIErrorHandler {
|
|
|
174
174
|
*/
|
|
175
175
|
extractErrorPayload(error) {
|
|
176
176
|
var _a, _b, _c, _d;
|
|
177
|
-
const { name,
|
|
177
|
+
const { name, code, status, response, request, config, statusText } = error;
|
|
178
178
|
const payload = {
|
|
179
179
|
name,
|
|
180
180
|
message: this.extractClearMessage(error),
|
package/lib/logger/log.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.cliErrorHandler = exports.v2Logger = exports.getSessionLogPath = void 0;
|
|
4
|
+
exports.handleAndLogError = handleAndLogError;
|
|
5
|
+
exports.getLogPath = getLogPath;
|
|
4
6
|
const tslib_1 = require("tslib");
|
|
5
7
|
const fs = tslib_1.__importStar(require("fs"));
|
|
6
8
|
const os = tslib_1.__importStar(require("os"));
|
|
@@ -68,7 +70,6 @@ function handleAndLogError(error, context, errorMessage) {
|
|
|
68
70
|
meta: classified.meta,
|
|
69
71
|
});
|
|
70
72
|
}
|
|
71
|
-
exports.handleAndLogError = handleAndLogError;
|
|
72
73
|
/**
|
|
73
74
|
* Get the log path for centralized logging
|
|
74
75
|
* Priority:
|
|
@@ -96,13 +97,12 @@ function getLogPath() {
|
|
|
96
97
|
fs.accessSync(cwdPath, fs.constants.W_OK);
|
|
97
98
|
return cwdPath;
|
|
98
99
|
}
|
|
99
|
-
catch (
|
|
100
|
+
catch (_a) {
|
|
100
101
|
// If current directory is not writable, fall back to home directory
|
|
101
102
|
}
|
|
102
103
|
// 4. Fallback to home directory
|
|
103
104
|
return path.join(os.homedir(), 'contentstack', 'logs');
|
|
104
105
|
}
|
|
105
|
-
exports.getLogPath = getLogPath;
|
|
106
106
|
// Re-export getSessionLogPath for external use
|
|
107
107
|
var session_path_1 = require("./session-path");
|
|
108
108
|
Object.defineProperty(exports, "getSessionLogPath", { enumerable: true, get: function () { return session_path_1.getSessionLogPath; } });
|
|
@@ -5,3 +5,8 @@
|
|
|
5
5
|
* @returns The session-specific log directory path
|
|
6
6
|
*/
|
|
7
7
|
export declare function getSessionLogPath(): string;
|
|
8
|
+
/**
|
|
9
|
+
* Clear the cached session path. Used by tests so each test gets a fresh path.
|
|
10
|
+
* Not needed in normal CLI usage (one process = one command = one cache).
|
|
11
|
+
*/
|
|
12
|
+
export declare function clearSessionLogPathCache(): void;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSessionLogPath =
|
|
3
|
+
exports.getSessionLogPath = getSessionLogPath;
|
|
4
|
+
exports.clearSessionLogPathCache = clearSessionLogPathCache;
|
|
4
5
|
const tslib_1 = require("tslib");
|
|
5
6
|
const fs = tslib_1.__importStar(require("fs"));
|
|
6
7
|
const os = tslib_1.__importStar(require("os"));
|
|
@@ -43,12 +44,16 @@ function createSessionMetadataFile(sessionPath, metadata) {
|
|
|
43
44
|
try {
|
|
44
45
|
fs.writeFileSync(metadataPath, JSON.stringify(metadata, null, 2), 'utf8');
|
|
45
46
|
}
|
|
46
|
-
catch (
|
|
47
|
+
catch (_a) {
|
|
47
48
|
// Silently fail if metadata file cannot be created
|
|
48
49
|
// Logging here would cause circular dependency
|
|
49
50
|
// The session folder and logs will still be created
|
|
50
51
|
}
|
|
51
52
|
}
|
|
53
|
+
// Cache session path for the process so multiple callers (e.g. Logger's 5 level
|
|
54
|
+
// loggers, export/import command at end, completeProgressWithMessage per module)
|
|
55
|
+
// get one folder instead of many.
|
|
56
|
+
let cachedSessionPath = null;
|
|
52
57
|
/**
|
|
53
58
|
* Get the session-based log path for date-organized logging
|
|
54
59
|
* Structure: {basePath}/{YYYY-MM-DD}/{command}-{YYYYMMDD-HHMMSS}-{sessionId}/
|
|
@@ -56,6 +61,9 @@ function createSessionMetadataFile(sessionPath, metadata) {
|
|
|
56
61
|
* @returns The session-specific log directory path
|
|
57
62
|
*/
|
|
58
63
|
function getSessionLogPath() {
|
|
64
|
+
if (cachedSessionPath) {
|
|
65
|
+
return cachedSessionPath;
|
|
66
|
+
}
|
|
59
67
|
// Get base log path
|
|
60
68
|
const basePath = (0, log_1.getLogPath)();
|
|
61
69
|
// Get current date in YYYY-MM-DD format
|
|
@@ -91,6 +99,13 @@ function getSessionLogPath() {
|
|
|
91
99
|
const metadata = generateSessionMetadata(__1.configHandler.get('currentCommandId') || commandId, sessionId, now);
|
|
92
100
|
createSessionMetadataFile(sessionPath, metadata);
|
|
93
101
|
}
|
|
102
|
+
cachedSessionPath = sessionPath;
|
|
94
103
|
return sessionPath;
|
|
95
104
|
}
|
|
96
|
-
|
|
105
|
+
/**
|
|
106
|
+
* Clear the cached session path. Used by tests so each test gets a fresh path.
|
|
107
|
+
* Not needed in normal CLI usage (one process = one command = one cache).
|
|
108
|
+
*/
|
|
109
|
+
function clearSessionLogPathCache() {
|
|
110
|
+
cachedSessionPath = null;
|
|
111
|
+
}
|
package/lib/message-handler.d.ts
CHANGED
package/lib/message-handler.js
CHANGED
|
@@ -3,32 +3,28 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
5
5
|
const cli_error_1 = tslib_1.__importDefault(require("./cli-error"));
|
|
6
|
+
const STORE_KEY = '__cs_messages__';
|
|
6
7
|
/**
|
|
7
8
|
* Message handler
|
|
8
9
|
*/
|
|
9
10
|
class Messages {
|
|
10
|
-
constructor() {
|
|
11
|
-
this.messages = {};
|
|
12
|
-
}
|
|
13
11
|
init(context) {
|
|
14
12
|
if (!context.messageFilePath) {
|
|
15
13
|
return;
|
|
16
14
|
}
|
|
17
15
|
try {
|
|
18
|
-
|
|
16
|
+
const loaded = JSON.parse(fs_1.default.readFileSync(context.messageFilePath, 'utf-8'));
|
|
17
|
+
globalThis[STORE_KEY] = Object.assign(Object.assign({}, globalThis[STORE_KEY]), loaded);
|
|
19
18
|
}
|
|
20
19
|
catch (error) {
|
|
21
|
-
|
|
22
|
-
if (error.code === 'ENOENT') {
|
|
23
|
-
this.messages = {};
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
20
|
+
if (error.code !== 'ENOENT') {
|
|
26
21
|
throw new cli_error_1.default(`Error: ${error.message}`);
|
|
27
22
|
}
|
|
28
23
|
}
|
|
29
24
|
}
|
|
30
25
|
parse(messageKey, ...substitutions) {
|
|
31
|
-
const
|
|
26
|
+
const store = globalThis[STORE_KEY] || {};
|
|
27
|
+
const msg = store[messageKey];
|
|
32
28
|
if (!msg) {
|
|
33
29
|
return messageKey;
|
|
34
30
|
}
|