@contentstack/cli-utilities 1.15.0 → 1.16.0
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/LICENSE +1 -1
- package/lib/auth-handler.js +8 -8
- package/lib/authentication-handler.js +0 -6
- package/lib/config-handler.js +1 -1
- package/lib/constants/logging.d.ts +0 -1
- package/lib/constants/logging.js +3 -4
- package/lib/contentstack-management-sdk.js +2 -0
- package/lib/flag-deprecation-check.js +5 -5
- package/lib/helpers.d.ts +25 -1
- package/lib/helpers.js +46 -9
- package/lib/http-client/client.d.ts +7 -0
- package/lib/http-client/client.js +6 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +3 -8
- package/lib/interfaces/index.d.ts +1 -50
- package/lib/logger/cli-error-handler.js +2 -1
- package/lib/logger/log.d.ts +1 -0
- package/lib/logger/log.js +5 -2
- package/lib/logger/logger.js +23 -40
- package/lib/logger/session-path.d.ts +7 -0
- package/lib/logger/session-path.js +96 -0
- package/lib/logger.js +1 -1
- package/lib/message-handler.js +1 -1
- package/package.json +5 -5
- package/lib/progress-summary/cli-progress-manager.d.ts +0 -121
- package/lib/progress-summary/cli-progress-manager.js +0 -530
- package/lib/progress-summary/index.d.ts +0 -4
- package/lib/progress-summary/index.js +0 -13
- package/lib/progress-summary/progress-strategy.d.ts +0 -25
- package/lib/progress-summary/progress-strategy.js +0 -54
- package/lib/progress-summary/summary-manager.d.ts +0 -24
- package/lib/progress-summary/summary-manager.js +0 -181
package/lib/message-handler.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-utilities",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.16.0",
|
|
4
4
|
"description": "Utilities for contentstack projects",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"author": "contentstack",
|
|
33
33
|
"license": "MIT",
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@contentstack/management": "~1.
|
|
36
|
-
"@contentstack/marketplace-sdk": "^1.
|
|
35
|
+
"@contentstack/management": "~1.25.1",
|
|
36
|
+
"@contentstack/marketplace-sdk": "^1.4.0",
|
|
37
37
|
"@oclif/core": "^4.3.0",
|
|
38
38
|
"axios": "^1.9.0",
|
|
39
39
|
"chalk": "^4.1.2",
|
|
@@ -43,10 +43,10 @@
|
|
|
43
43
|
"conf": "^10.2.0",
|
|
44
44
|
"dotenv": "^16.5.0",
|
|
45
45
|
"figures": "^3.2.0",
|
|
46
|
-
"inquirer": "8.2.
|
|
46
|
+
"inquirer": "8.2.7",
|
|
47
47
|
"inquirer-search-checkbox": "^1.0.0",
|
|
48
48
|
"inquirer-search-list": "^1.2.6",
|
|
49
|
-
"js-yaml": "^4.1.
|
|
49
|
+
"js-yaml": "^4.1.1",
|
|
50
50
|
"klona": "^2.0.6",
|
|
51
51
|
"lodash": "^4.17.21",
|
|
52
52
|
"mkdirp": "^1.0.4",
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import SummaryManager from './summary-manager';
|
|
2
|
-
import { ProgressManagerOptions } from '../interfaces';
|
|
3
|
-
interface ProgressCallback {
|
|
4
|
-
onModuleStart?: (moduleName: string) => void;
|
|
5
|
-
onModuleComplete?: (moduleName: string, success: boolean, error?: string) => void;
|
|
6
|
-
onProgress?: (moduleName: string, success: boolean, itemName: string, error?: string) => void;
|
|
7
|
-
}
|
|
8
|
-
export default class CLIProgressManager {
|
|
9
|
-
private static globalSummary;
|
|
10
|
-
private showConsoleLogs;
|
|
11
|
-
private total;
|
|
12
|
-
private moduleName;
|
|
13
|
-
private enableNestedProgress;
|
|
14
|
-
private successCount;
|
|
15
|
-
private failureCount;
|
|
16
|
-
private failures;
|
|
17
|
-
private spinner;
|
|
18
|
-
private progressBar;
|
|
19
|
-
private processes;
|
|
20
|
-
private multiBar;
|
|
21
|
-
private currentProcess;
|
|
22
|
-
private callbacks;
|
|
23
|
-
private branchName;
|
|
24
|
-
constructor({ showConsoleLogs, total, moduleName, enableNestedProgress, }?: ProgressManagerOptions);
|
|
25
|
-
/**
|
|
26
|
-
* Initialize global summary manager for the entire operation
|
|
27
|
-
*/
|
|
28
|
-
static initializeGlobalSummary(operationName: string, branchName: string, headerTitle?: string): SummaryManager;
|
|
29
|
-
/**
|
|
30
|
-
* Display operation header with branch information
|
|
31
|
-
*/
|
|
32
|
-
static displayOperationHeader(branchName: string, headerTitle?: string): void;
|
|
33
|
-
/**
|
|
34
|
-
* Print the final summary for all modules using strategies
|
|
35
|
-
*/
|
|
36
|
-
static printGlobalSummary(): void;
|
|
37
|
-
/**
|
|
38
|
-
* Apply strategy-based corrections to module data
|
|
39
|
-
*/
|
|
40
|
-
private static applyStrategyCorrections;
|
|
41
|
-
/**
|
|
42
|
-
* Clear global summary (for cleanup)
|
|
43
|
-
*/
|
|
44
|
-
static clearGlobalSummary(): void;
|
|
45
|
-
/**
|
|
46
|
-
* Create a simple progress manager (no nested processes)
|
|
47
|
-
*/
|
|
48
|
-
static createSimple(moduleName: string, total?: number, showConsoleLogs?: boolean): CLIProgressManager;
|
|
49
|
-
/**
|
|
50
|
-
* Create a nested progress manager (with sub-processes)
|
|
51
|
-
*/
|
|
52
|
-
static createNested(moduleName: string, showConsoleLogs?: boolean): CLIProgressManager;
|
|
53
|
-
/**
|
|
54
|
-
* Show a loading spinner before initializing progress
|
|
55
|
-
*/
|
|
56
|
-
static withLoadingSpinner<T>(message: string, asyncOperation: () => Promise<T>): Promise<T>;
|
|
57
|
-
private setupGlobalSummaryIntegration;
|
|
58
|
-
/**
|
|
59
|
-
* Register process data with summary manager for strategy calculations
|
|
60
|
-
*/
|
|
61
|
-
private registerProcessDataWithSummary;
|
|
62
|
-
/**
|
|
63
|
-
* Set callbacks for external integration
|
|
64
|
-
*/
|
|
65
|
-
setCallbacks(callbacks: ProgressCallback): void;
|
|
66
|
-
/**
|
|
67
|
-
* Convert module name from UPPERCASE to PascalCase
|
|
68
|
-
*/
|
|
69
|
-
private formatModuleName;
|
|
70
|
-
/**
|
|
71
|
-
* Format process name with smart truncation (modules should use short names)
|
|
72
|
-
*/
|
|
73
|
-
private formatProcessName;
|
|
74
|
-
/**
|
|
75
|
-
* Format percentage for consistent alignment (always 3 characters)
|
|
76
|
-
*/
|
|
77
|
-
private formatPercentage;
|
|
78
|
-
private initializeProgress;
|
|
79
|
-
/**
|
|
80
|
-
* Add a new process to track (for nested progress)
|
|
81
|
-
*/
|
|
82
|
-
addProcess(processName: string, total: number): this;
|
|
83
|
-
/**
|
|
84
|
-
* Update the total for a specific process (for dynamic totals after API calls)
|
|
85
|
-
*/
|
|
86
|
-
updateProcessTotal(processName: string, newTotal: number): this;
|
|
87
|
-
/**
|
|
88
|
-
* Start a specific process
|
|
89
|
-
*/
|
|
90
|
-
startProcess(processName: string): this;
|
|
91
|
-
/**
|
|
92
|
-
* Complete a specific process
|
|
93
|
-
*/
|
|
94
|
-
completeProcess(processName: string, success?: boolean): this;
|
|
95
|
-
/**
|
|
96
|
-
* Update status message
|
|
97
|
-
*/
|
|
98
|
-
updateStatus(message: string, processName?: string): this;
|
|
99
|
-
/**
|
|
100
|
-
* Update progress
|
|
101
|
-
*/
|
|
102
|
-
tick(success?: boolean, itemName?: string, errorMessage?: string | null, processName?: string): this;
|
|
103
|
-
/**
|
|
104
|
-
* Complete the entire module
|
|
105
|
-
*/
|
|
106
|
-
complete(success?: boolean, error?: string): this;
|
|
107
|
-
/**
|
|
108
|
-
* Log message (respects showConsoleLogs mode)
|
|
109
|
-
*/
|
|
110
|
-
log(msg: string): void;
|
|
111
|
-
/**
|
|
112
|
-
* Stop all progress indicators
|
|
113
|
-
*/
|
|
114
|
-
stop(): void;
|
|
115
|
-
private printSummary;
|
|
116
|
-
/**
|
|
117
|
-
* Get the current failure count
|
|
118
|
-
*/
|
|
119
|
-
getFailureCount(): number;
|
|
120
|
-
}
|
|
121
|
-
export {};
|
|
@@ -1,530 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
5
|
-
const ora_1 = tslib_1.__importDefault(require("ora"));
|
|
6
|
-
const cli_progress_1 = tslib_1.__importDefault(require("cli-progress"));
|
|
7
|
-
const summary_manager_1 = tslib_1.__importDefault(require("./summary-manager"));
|
|
8
|
-
const __1 = require("..");
|
|
9
|
-
const progress_strategy_1 = require("./progress-strategy");
|
|
10
|
-
class CLIProgressManager {
|
|
11
|
-
constructor({ showConsoleLogs = false, total = 0, moduleName = 'Module', enableNestedProgress = false, } = {}) {
|
|
12
|
-
this.showConsoleLogs = showConsoleLogs;
|
|
13
|
-
this.total = total;
|
|
14
|
-
this.moduleName = moduleName;
|
|
15
|
-
this.enableNestedProgress = enableNestedProgress;
|
|
16
|
-
this.successCount = 0;
|
|
17
|
-
this.failureCount = 0;
|
|
18
|
-
this.failures = [];
|
|
19
|
-
this.spinner = null;
|
|
20
|
-
this.progressBar = null;
|
|
21
|
-
this.processes = new Map();
|
|
22
|
-
this.multiBar = null;
|
|
23
|
-
this.currentProcess = null;
|
|
24
|
-
this.callbacks = {};
|
|
25
|
-
this.branchName = '';
|
|
26
|
-
this.initializeProgress();
|
|
27
|
-
this.setupGlobalSummaryIntegration();
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Initialize global summary manager for the entire operation
|
|
31
|
-
*/
|
|
32
|
-
static initializeGlobalSummary(operationName, branchName, headerTitle) {
|
|
33
|
-
var _a;
|
|
34
|
-
CLIProgressManager.globalSummary = new summary_manager_1.default({ operationName, context: { branchName } });
|
|
35
|
-
// Only show header if console logs are disabled (progress UI mode)
|
|
36
|
-
if (!((_a = __1.configHandler.get('log')) === null || _a === void 0 ? void 0 : _a.showConsoleLogs)) {
|
|
37
|
-
CLIProgressManager.displayOperationHeader(branchName, headerTitle);
|
|
38
|
-
}
|
|
39
|
-
return CLIProgressManager.globalSummary;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Display operation header with branch information
|
|
43
|
-
*/
|
|
44
|
-
static displayOperationHeader(branchName, headerTitle) {
|
|
45
|
-
if (!headerTitle)
|
|
46
|
-
return;
|
|
47
|
-
const safeBranchName = branchName || 'main';
|
|
48
|
-
const branchInfo = headerTitle || `${safeBranchName === null || safeBranchName === void 0 ? void 0 : safeBranchName.toUpperCase()} CONTENT`;
|
|
49
|
-
console.log('\n' + chalk_1.default.bold('='.repeat(80)));
|
|
50
|
-
if (branchInfo) {
|
|
51
|
-
console.log(chalk_1.default.bold.white(` ${branchInfo}`));
|
|
52
|
-
}
|
|
53
|
-
console.log(chalk_1.default.bold('='.repeat(80)) + '\n');
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Print the final summary for all modules using strategies
|
|
57
|
-
*/
|
|
58
|
-
static printGlobalSummary() {
|
|
59
|
-
if (!CLIProgressManager.globalSummary) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
// Apply strategy-based corrections before printing
|
|
63
|
-
CLIProgressManager.applyStrategyCorrections();
|
|
64
|
-
// Print the final summary
|
|
65
|
-
CLIProgressManager.globalSummary.printFinalSummary();
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Apply strategy-based corrections to module data
|
|
69
|
-
*/
|
|
70
|
-
static applyStrategyCorrections() {
|
|
71
|
-
if (!CLIProgressManager.globalSummary)
|
|
72
|
-
return;
|
|
73
|
-
const modules = Array.from(CLIProgressManager.globalSummary.getModules().values());
|
|
74
|
-
modules.forEach((module) => {
|
|
75
|
-
// Check if this module has a registered strategy
|
|
76
|
-
if (progress_strategy_1.ProgressStrategyRegistry.has(module.name)) {
|
|
77
|
-
const strategy = progress_strategy_1.ProgressStrategyRegistry.get(module.name);
|
|
78
|
-
// Create a processes map from module data if available
|
|
79
|
-
const processesMap = new Map();
|
|
80
|
-
// If module has process data, populate the map
|
|
81
|
-
if (module.processes && Array.isArray(module.processes)) {
|
|
82
|
-
module.processes.forEach((processData) => {
|
|
83
|
-
if (processData.processName) {
|
|
84
|
-
processesMap.set(processData.processName, processData);
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
// Calculate corrected progress using strategy
|
|
89
|
-
const correctedResult = strategy.calculate(processesMap);
|
|
90
|
-
if (correctedResult) {
|
|
91
|
-
// Update module with corrected counts
|
|
92
|
-
module.totalItems = correctedResult.total;
|
|
93
|
-
module.successCount = correctedResult.success;
|
|
94
|
-
module.failureCount = correctedResult.failures;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Clear global summary (for cleanup)
|
|
101
|
-
*/
|
|
102
|
-
static clearGlobalSummary() {
|
|
103
|
-
CLIProgressManager.globalSummary = null;
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Create a simple progress manager (no nested processes)
|
|
107
|
-
*/
|
|
108
|
-
static createSimple(moduleName, total, showConsoleLogs = false) {
|
|
109
|
-
return new CLIProgressManager({
|
|
110
|
-
moduleName: moduleName.toUpperCase(),
|
|
111
|
-
total: total || 0,
|
|
112
|
-
showConsoleLogs,
|
|
113
|
-
enableNestedProgress: false,
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Create a nested progress manager (with sub-processes)
|
|
118
|
-
*/
|
|
119
|
-
static createNested(moduleName, showConsoleLogs = false) {
|
|
120
|
-
return new CLIProgressManager({
|
|
121
|
-
moduleName: moduleName.toUpperCase(),
|
|
122
|
-
total: 0,
|
|
123
|
-
showConsoleLogs,
|
|
124
|
-
enableNestedProgress: true,
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Show a loading spinner before initializing progress
|
|
129
|
-
*/
|
|
130
|
-
static async withLoadingSpinner(message, asyncOperation) {
|
|
131
|
-
const spinner = (0, ora_1.default)(message).start();
|
|
132
|
-
try {
|
|
133
|
-
const result = await asyncOperation();
|
|
134
|
-
spinner.stop();
|
|
135
|
-
return result;
|
|
136
|
-
}
|
|
137
|
-
catch (error) {
|
|
138
|
-
spinner.stop();
|
|
139
|
-
throw error;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
setupGlobalSummaryIntegration() {
|
|
143
|
-
var _a, _b;
|
|
144
|
-
// Auto-register with global summary if it exists
|
|
145
|
-
if (CLIProgressManager.globalSummary) {
|
|
146
|
-
this.setCallbacks({
|
|
147
|
-
onModuleStart: (name) => {
|
|
148
|
-
var _a, _b;
|
|
149
|
-
(_a = CLIProgressManager.globalSummary) === null || _a === void 0 ? void 0 : _a.registerModule(name, this.total);
|
|
150
|
-
(_b = CLIProgressManager.globalSummary) === null || _b === void 0 ? void 0 : _b.startModule(name);
|
|
151
|
-
},
|
|
152
|
-
onModuleComplete: (name, success, error) => {
|
|
153
|
-
var _a;
|
|
154
|
-
// Register process data with summary manager before completing
|
|
155
|
-
this.registerProcessDataWithSummary(name);
|
|
156
|
-
(_a = CLIProgressManager.globalSummary) === null || _a === void 0 ? void 0 : _a.completeModule(name, success, error);
|
|
157
|
-
},
|
|
158
|
-
onProgress: (name, success, itemName, error) => {
|
|
159
|
-
var _a;
|
|
160
|
-
(_a = CLIProgressManager.globalSummary) === null || _a === void 0 ? void 0 : _a.updateModuleProgress(name, success, itemName, error);
|
|
161
|
-
},
|
|
162
|
-
});
|
|
163
|
-
// Trigger module start
|
|
164
|
-
(_b = (_a = this.callbacks).onModuleStart) === null || _b === void 0 ? void 0 : _b.call(_a, this.moduleName);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* Register process data with summary manager for strategy calculations
|
|
169
|
-
*/
|
|
170
|
-
registerProcessDataWithSummary(moduleName) {
|
|
171
|
-
if (!CLIProgressManager.globalSummary)
|
|
172
|
-
return;
|
|
173
|
-
// Register each process with the summary manager
|
|
174
|
-
this.processes.forEach((processData, processName) => {
|
|
175
|
-
var _a;
|
|
176
|
-
(_a = CLIProgressManager.globalSummary) === null || _a === void 0 ? void 0 : _a.registerProcessData(moduleName, processName, {
|
|
177
|
-
processName,
|
|
178
|
-
total: processData.total,
|
|
179
|
-
current: processData.current,
|
|
180
|
-
successCount: processData.successCount,
|
|
181
|
-
failureCount: processData.failureCount,
|
|
182
|
-
status: processData.status,
|
|
183
|
-
failures: processData.failures,
|
|
184
|
-
});
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* Set callbacks for external integration
|
|
189
|
-
*/
|
|
190
|
-
setCallbacks(callbacks) {
|
|
191
|
-
this.callbacks = Object.assign(Object.assign({}, this.callbacks), callbacks);
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Convert module name from UPPERCASE to PascalCase
|
|
195
|
-
*/
|
|
196
|
-
formatModuleName(name) {
|
|
197
|
-
return name.charAt(0).toUpperCase() + name.slice(1).toLowerCase();
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
|
-
* Format process name with smart truncation (modules should use short names)
|
|
201
|
-
*/
|
|
202
|
-
formatProcessName(processName) {
|
|
203
|
-
const cleaned = processName.trim();
|
|
204
|
-
if (cleaned.length <= 20) {
|
|
205
|
-
return cleaned;
|
|
206
|
-
}
|
|
207
|
-
return cleaned.length <= 20 ? cleaned : cleaned.substring(0, 20) + '...';
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* Format percentage for consistent alignment (always 3 characters)
|
|
211
|
-
*/
|
|
212
|
-
formatPercentage(percentage) {
|
|
213
|
-
if (percentage === 100) {
|
|
214
|
-
return '100';
|
|
215
|
-
}
|
|
216
|
-
else if (percentage >= 10) {
|
|
217
|
-
return ` ${percentage}`;
|
|
218
|
-
}
|
|
219
|
-
else {
|
|
220
|
-
return ` ${percentage}`;
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
initializeProgress() {
|
|
224
|
-
if (this.showConsoleLogs) {
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
if (this.enableNestedProgress) {
|
|
228
|
-
// Initialize multi-bar for nested progress tracking
|
|
229
|
-
this.multiBar = new cli_progress_1.default.MultiBar({
|
|
230
|
-
clearOnComplete: false,
|
|
231
|
-
hideCursor: true,
|
|
232
|
-
format: ' {label} |' + chalk_1.default.cyan('{bar}') + '| {percentage}% | {value}/{total} | {status}',
|
|
233
|
-
barCompleteChar: '\u2588',
|
|
234
|
-
barIncompleteChar: '\u2591',
|
|
235
|
-
}, cli_progress_1.default.Presets.shades_classic);
|
|
236
|
-
if (!this.showConsoleLogs) {
|
|
237
|
-
console.log(chalk_1.default.bold.cyan(`\n${this.moduleName}:`));
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
else if (this.total > 0) {
|
|
241
|
-
if (!this.showConsoleLogs) {
|
|
242
|
-
console.log(chalk_1.default.bold.cyan(`\n${this.moduleName}:`));
|
|
243
|
-
}
|
|
244
|
-
this.progressBar = new cli_progress_1.default.SingleBar({
|
|
245
|
-
format: ' {label} |' + chalk_1.default.cyan('{bar}') + '| {percentage}% | {value}/{total} | {status}',
|
|
246
|
-
barCompleteChar: '\u2588',
|
|
247
|
-
barIncompleteChar: '\u2591',
|
|
248
|
-
hideCursor: true,
|
|
249
|
-
});
|
|
250
|
-
const formattedName = this.formatModuleName(this.moduleName);
|
|
251
|
-
const displayName = formattedName.length > 20 ? formattedName.substring(0, 17) + '...' : formattedName;
|
|
252
|
-
this.progressBar.start(this.total, 0, {
|
|
253
|
-
label: chalk_1.default.gray(` └─ ${displayName}`.padEnd(25)),
|
|
254
|
-
status: chalk_1.default.gray('Starting...'),
|
|
255
|
-
percentage: ' 0',
|
|
256
|
-
});
|
|
257
|
-
}
|
|
258
|
-
else {
|
|
259
|
-
this.spinner = (0, ora_1.default)(`${chalk_1.default.bold(this.moduleName)}: Processing...`).start();
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
/**
|
|
263
|
-
* Add a new process to track (for nested progress)
|
|
264
|
-
*/
|
|
265
|
-
addProcess(processName, total) {
|
|
266
|
-
if (!this.enableNestedProgress || !this.multiBar)
|
|
267
|
-
return this;
|
|
268
|
-
const process = {
|
|
269
|
-
name: processName,
|
|
270
|
-
total,
|
|
271
|
-
current: 0,
|
|
272
|
-
status: 'pending',
|
|
273
|
-
successCount: 0,
|
|
274
|
-
failureCount: 0,
|
|
275
|
-
failures: [],
|
|
276
|
-
};
|
|
277
|
-
if (!this.showConsoleLogs) {
|
|
278
|
-
const displayName = this.formatProcessName(processName);
|
|
279
|
-
const indentedLabel = ` ├─ ${displayName}`.padEnd(25);
|
|
280
|
-
process.progressBar = this.multiBar.create(total, 0, {
|
|
281
|
-
label: chalk_1.default.gray(indentedLabel),
|
|
282
|
-
status: chalk_1.default.gray('Pending'),
|
|
283
|
-
percentage: ' 0',
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
this.processes.set(processName, process);
|
|
287
|
-
return this;
|
|
288
|
-
}
|
|
289
|
-
/**
|
|
290
|
-
* Update the total for a specific process (for dynamic totals after API calls)
|
|
291
|
-
*/
|
|
292
|
-
updateProcessTotal(processName, newTotal) {
|
|
293
|
-
if (!this.enableNestedProgress)
|
|
294
|
-
return this;
|
|
295
|
-
const process = this.processes.get(processName);
|
|
296
|
-
if (process) {
|
|
297
|
-
process.total = newTotal;
|
|
298
|
-
if (process.progressBar && !this.showConsoleLogs) {
|
|
299
|
-
// Update the progress bar with the new total
|
|
300
|
-
process.progressBar.setTotal(newTotal);
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
return this;
|
|
304
|
-
}
|
|
305
|
-
/**
|
|
306
|
-
* Start a specific process
|
|
307
|
-
*/
|
|
308
|
-
startProcess(processName) {
|
|
309
|
-
if (!this.enableNestedProgress)
|
|
310
|
-
return this;
|
|
311
|
-
const process = this.processes.get(processName);
|
|
312
|
-
if (process) {
|
|
313
|
-
process.status = 'active';
|
|
314
|
-
if (!this.showConsoleLogs && process.progressBar) {
|
|
315
|
-
const displayName = this.formatProcessName(processName);
|
|
316
|
-
const indentedLabel = ` ├─ ${displayName}`.padEnd(25);
|
|
317
|
-
process.progressBar.update(0, {
|
|
318
|
-
label: chalk_1.default.yellow(indentedLabel),
|
|
319
|
-
status: chalk_1.default.yellow('Processing'),
|
|
320
|
-
percentage: ' 0',
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
|
-
this.currentProcess = processName;
|
|
324
|
-
}
|
|
325
|
-
return this;
|
|
326
|
-
}
|
|
327
|
-
/**
|
|
328
|
-
* Complete a specific process
|
|
329
|
-
*/
|
|
330
|
-
completeProcess(processName, success = true) {
|
|
331
|
-
if (!this.enableNestedProgress)
|
|
332
|
-
return this;
|
|
333
|
-
const process = this.processes.get(processName);
|
|
334
|
-
if (process) {
|
|
335
|
-
process.status = success ? 'completed' : 'failed';
|
|
336
|
-
if (!this.showConsoleLogs && process.progressBar) {
|
|
337
|
-
const percentage = Math.round((process.current / process.total) * 100);
|
|
338
|
-
const formattedPercentage = this.formatPercentage(percentage);
|
|
339
|
-
const statusText = success
|
|
340
|
-
? chalk_1.default.green(`✓ Complete (${process.successCount}/${process.current})`)
|
|
341
|
-
: chalk_1.default.red(`✗ Failed (${process.successCount}/${process.current})`);
|
|
342
|
-
const displayName = this.formatProcessName(processName);
|
|
343
|
-
const indentedLabel = ` ├─ ${displayName}`.padEnd(25);
|
|
344
|
-
process.progressBar.update(process.total, {
|
|
345
|
-
label: success ? chalk_1.default.green(indentedLabel) : chalk_1.default.red(indentedLabel),
|
|
346
|
-
status: statusText,
|
|
347
|
-
percentage: formattedPercentage,
|
|
348
|
-
});
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
return this;
|
|
352
|
-
}
|
|
353
|
-
/**
|
|
354
|
-
* Update status message
|
|
355
|
-
*/
|
|
356
|
-
updateStatus(message, processName) {
|
|
357
|
-
if (!this.showConsoleLogs) {
|
|
358
|
-
if (this.enableNestedProgress && processName) {
|
|
359
|
-
const process = this.processes.get(processName);
|
|
360
|
-
if (process && process.progressBar) {
|
|
361
|
-
const percentage = Math.round((process.current / process.total) * 100);
|
|
362
|
-
const formattedPercentage = this.formatPercentage(percentage);
|
|
363
|
-
const displayName = this.formatProcessName(processName);
|
|
364
|
-
const indentedLabel = ` ├─ ${displayName}`.padEnd(25);
|
|
365
|
-
process.progressBar.update(process.current, {
|
|
366
|
-
label: chalk_1.default.yellow(indentedLabel),
|
|
367
|
-
status: chalk_1.default.yellow(message),
|
|
368
|
-
percentage: formattedPercentage,
|
|
369
|
-
});
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
else if (this.progressBar) {
|
|
373
|
-
const percentage = Math.round(this.progressBar.getProgress() * 100);
|
|
374
|
-
const formattedPercentage = this.formatPercentage(percentage);
|
|
375
|
-
const formattedName = this.formatModuleName(this.moduleName);
|
|
376
|
-
const displayName = formattedName.length > 20 ? formattedName.substring(0, 17) + '...' : formattedName;
|
|
377
|
-
this.progressBar.update(this.progressBar.getProgress() * this.total, {
|
|
378
|
-
label: chalk_1.default.yellow(` └─ ${displayName}`.padEnd(25)),
|
|
379
|
-
status: chalk_1.default.yellow(message),
|
|
380
|
-
percentage: formattedPercentage,
|
|
381
|
-
});
|
|
382
|
-
}
|
|
383
|
-
else if (this.spinner) {
|
|
384
|
-
this.spinner.text = `${chalk_1.default.bold(this.moduleName)}: ${message}`;
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
return this;
|
|
388
|
-
}
|
|
389
|
-
/**
|
|
390
|
-
* Update progress
|
|
391
|
-
*/
|
|
392
|
-
tick(success = true, itemName = '', errorMessage = null, processName) {
|
|
393
|
-
var _a, _b;
|
|
394
|
-
const targetProcess = processName || this.currentProcess;
|
|
395
|
-
if (success) {
|
|
396
|
-
this.successCount++;
|
|
397
|
-
}
|
|
398
|
-
else {
|
|
399
|
-
this.failureCount++;
|
|
400
|
-
this.failures.push({
|
|
401
|
-
item: itemName,
|
|
402
|
-
error: errorMessage,
|
|
403
|
-
process: targetProcess || undefined,
|
|
404
|
-
});
|
|
405
|
-
}
|
|
406
|
-
// Trigger callback
|
|
407
|
-
(_b = (_a = this.callbacks).onProgress) === null || _b === void 0 ? void 0 : _b.call(_a, this.moduleName, success, itemName, errorMessage || undefined);
|
|
408
|
-
// Update nested progress if enabled and console logs are disabled
|
|
409
|
-
if (this.enableNestedProgress && targetProcess) {
|
|
410
|
-
const process = this.processes.get(targetProcess);
|
|
411
|
-
if (process) {
|
|
412
|
-
process.current++;
|
|
413
|
-
if (success) {
|
|
414
|
-
process.successCount++;
|
|
415
|
-
}
|
|
416
|
-
else {
|
|
417
|
-
process.failureCount++;
|
|
418
|
-
process.failures.push({ item: itemName, error: errorMessage });
|
|
419
|
-
}
|
|
420
|
-
// Only update progress bar if console logs are disabled
|
|
421
|
-
if (!this.showConsoleLogs && process.progressBar) {
|
|
422
|
-
const percentage = Math.round((process.current / process.total) * 100);
|
|
423
|
-
const formattedPercentage = this.formatPercentage(percentage);
|
|
424
|
-
const statusText = `${process.successCount}✓ ${process.failureCount}✗`;
|
|
425
|
-
const displayName = this.formatProcessName(targetProcess);
|
|
426
|
-
const indentedLabel = ` ├─ ${displayName}`.padEnd(25);
|
|
427
|
-
process.progressBar.increment(1, {
|
|
428
|
-
label: chalk_1.default.cyan(indentedLabel),
|
|
429
|
-
status: chalk_1.default.cyan(statusText),
|
|
430
|
-
percentage: formattedPercentage,
|
|
431
|
-
});
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
else {
|
|
436
|
-
// Update single progress bar or spinner only if console logs are disabled
|
|
437
|
-
if (!this.showConsoleLogs) {
|
|
438
|
-
if (this.progressBar) {
|
|
439
|
-
const percentage = Math.round(((this.successCount + this.failureCount) / this.total) * 100);
|
|
440
|
-
const formattedPercentage = this.formatPercentage(percentage);
|
|
441
|
-
const totalProcessed = this.successCount + this.failureCount;
|
|
442
|
-
// Show completion status when finished, otherwise show running count
|
|
443
|
-
const statusText = totalProcessed >= this.total
|
|
444
|
-
? this.failureCount === 0
|
|
445
|
-
? chalk_1.default.green(`✓ Complete (${this.successCount}/${totalProcessed})`)
|
|
446
|
-
: chalk_1.default.yellow(`✓ Complete (${this.successCount}/${totalProcessed})`)
|
|
447
|
-
: chalk_1.default.cyan(`${this.successCount}✓ ${this.failureCount}✗`);
|
|
448
|
-
const labelColor = totalProcessed >= this.total ? (this.failureCount === 0 ? chalk_1.default.green : chalk_1.default.yellow) : chalk_1.default.cyan;
|
|
449
|
-
const formattedName = this.formatModuleName(this.moduleName);
|
|
450
|
-
const displayName = formattedName.length > 20 ? formattedName.substring(0, 17) + '...' : formattedName;
|
|
451
|
-
this.progressBar.increment(1, {
|
|
452
|
-
label: labelColor(` └─ ${displayName}`.padEnd(25)),
|
|
453
|
-
status: statusText,
|
|
454
|
-
percentage: formattedPercentage,
|
|
455
|
-
});
|
|
456
|
-
}
|
|
457
|
-
else if (this.spinner) {
|
|
458
|
-
const total = this.successCount + this.failureCount;
|
|
459
|
-
this.spinner.text = `${chalk_1.default.bold(this.moduleName)}: ${total} items (${this.successCount}✓ ${this.failureCount}✗)`;
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
return this;
|
|
464
|
-
}
|
|
465
|
-
/**
|
|
466
|
-
* Complete the entire module
|
|
467
|
-
*/
|
|
468
|
-
complete(success = true, error) {
|
|
469
|
-
var _a, _b;
|
|
470
|
-
this.stop();
|
|
471
|
-
(_b = (_a = this.callbacks).onModuleComplete) === null || _b === void 0 ? void 0 : _b.call(_a, this.moduleName, success, error);
|
|
472
|
-
return this;
|
|
473
|
-
}
|
|
474
|
-
/**
|
|
475
|
-
* Log message (respects showConsoleLogs mode)
|
|
476
|
-
*/
|
|
477
|
-
log(msg) {
|
|
478
|
-
if (this.showConsoleLogs) {
|
|
479
|
-
console.log(msg);
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
/**
|
|
483
|
-
* Stop all progress indicators
|
|
484
|
-
*/
|
|
485
|
-
stop() {
|
|
486
|
-
// Only stop progress bars if they were initialized (console logs disabled)
|
|
487
|
-
if (!this.showConsoleLogs) {
|
|
488
|
-
if (this.multiBar) {
|
|
489
|
-
this.multiBar.stop();
|
|
490
|
-
}
|
|
491
|
-
if (this.progressBar) {
|
|
492
|
-
this.progressBar.stop();
|
|
493
|
-
}
|
|
494
|
-
if (this.spinner) {
|
|
495
|
-
this.spinner.stop();
|
|
496
|
-
}
|
|
497
|
-
this.printSummary();
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
printSummary() {
|
|
501
|
-
if (!this.enableNestedProgress) {
|
|
502
|
-
// Simple summary for single progress
|
|
503
|
-
this.log('\n' + chalk_1.default.bold(`${this.moduleName} Summary:`));
|
|
504
|
-
this.log(`✓ Success: ${chalk_1.default.green(this.successCount)}`);
|
|
505
|
-
this.log(`✗ Failures: ${chalk_1.default.red(this.failureCount)}`);
|
|
506
|
-
return;
|
|
507
|
-
}
|
|
508
|
-
// Detailed summary for nested progress
|
|
509
|
-
this.log('\n' + chalk_1.default.bold(`${this.moduleName} Detailed Summary:`));
|
|
510
|
-
for (const [processName, process] of this.processes) {
|
|
511
|
-
const status = process.status === 'completed'
|
|
512
|
-
? '✓'
|
|
513
|
-
: process.status === 'failed'
|
|
514
|
-
? '✗'
|
|
515
|
-
: process.status === 'active'
|
|
516
|
-
? '●'
|
|
517
|
-
: '○';
|
|
518
|
-
this.log(` ${status} ${processName}: ${process.successCount}✓ ${process.failureCount}✗ (${process.current}/${process.total})`);
|
|
519
|
-
}
|
|
520
|
-
this.log(`\nOverall: ${this.successCount}✓ ${this.failureCount}✗`);
|
|
521
|
-
}
|
|
522
|
-
/**
|
|
523
|
-
* Get the current failure count
|
|
524
|
-
*/
|
|
525
|
-
getFailureCount() {
|
|
526
|
-
return this.failureCount;
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
exports.default = CLIProgressManager;
|
|
530
|
-
CLIProgressManager.globalSummary = null;
|