@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.
@@ -1,4 +0,0 @@
1
- import SummaryManager from './summary-manager';
2
- import CLIProgressManager from './cli-progress-manager';
3
- import { PrimaryProcessStrategy, CustomProgressStrategy, ProgressStrategyRegistry, DefaultProgressStrategy } from './progress-strategy';
4
- export { SummaryManager, CLIProgressManager, PrimaryProcessStrategy, CustomProgressStrategy, ProgressStrategyRegistry, DefaultProgressStrategy, };
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DefaultProgressStrategy = exports.ProgressStrategyRegistry = exports.CustomProgressStrategy = exports.PrimaryProcessStrategy = exports.CLIProgressManager = exports.SummaryManager = void 0;
4
- const tslib_1 = require("tslib");
5
- const summary_manager_1 = tslib_1.__importDefault(require("./summary-manager"));
6
- exports.SummaryManager = summary_manager_1.default;
7
- const cli_progress_manager_1 = tslib_1.__importDefault(require("./cli-progress-manager"));
8
- exports.CLIProgressManager = cli_progress_manager_1.default;
9
- const progress_strategy_1 = require("./progress-strategy");
10
- Object.defineProperty(exports, "PrimaryProcessStrategy", { enumerable: true, get: function () { return progress_strategy_1.PrimaryProcessStrategy; } });
11
- Object.defineProperty(exports, "CustomProgressStrategy", { enumerable: true, get: function () { return progress_strategy_1.CustomProgressStrategy; } });
12
- Object.defineProperty(exports, "ProgressStrategyRegistry", { enumerable: true, get: function () { return progress_strategy_1.ProgressStrategyRegistry; } });
13
- Object.defineProperty(exports, "DefaultProgressStrategy", { enumerable: true, get: function () { return progress_strategy_1.DefaultProgressStrategy; } });
@@ -1,25 +0,0 @@
1
- import { ProcessProgress, ProgressResult } from '../interfaces';
2
- export interface ProgressCalculationStrategy {
3
- calculate(processes: Map<string, ProcessProgress>): ProgressResult | null;
4
- }
5
- export declare class DefaultProgressStrategy implements ProgressCalculationStrategy {
6
- calculate(): ProgressResult | null;
7
- }
8
- export declare class PrimaryProcessStrategy implements ProgressCalculationStrategy {
9
- private primaryProcessName;
10
- constructor(primaryProcessName: string);
11
- calculate(processes: Map<string, ProcessProgress>): ProgressResult | null;
12
- }
13
- export declare class CustomProgressStrategy implements ProgressCalculationStrategy {
14
- private calculator;
15
- constructor(calculator: (processes: Map<string, ProcessProgress>) => ProgressResult | null);
16
- calculate(processes: Map<string, ProcessProgress>): ProgressResult | null;
17
- }
18
- export declare class ProgressStrategyRegistry {
19
- private static strategies;
20
- static register(moduleName: string, strategy: ProgressCalculationStrategy): void;
21
- static get(moduleName: string): ProgressCalculationStrategy;
22
- static clear(): void;
23
- static has(moduleName: string): boolean;
24
- static getAllRegistered(): string[];
25
- }
@@ -1,54 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ProgressStrategyRegistry = exports.CustomProgressStrategy = exports.PrimaryProcessStrategy = exports.DefaultProgressStrategy = void 0;
4
- class DefaultProgressStrategy {
5
- calculate() {
6
- return null; // Use default aggregated counting
7
- }
8
- }
9
- exports.DefaultProgressStrategy = DefaultProgressStrategy;
10
- class PrimaryProcessStrategy {
11
- constructor(primaryProcessName) {
12
- this.primaryProcessName = primaryProcessName;
13
- }
14
- calculate(processes) {
15
- const primaryProcess = processes.get(this.primaryProcessName);
16
- if (!primaryProcess)
17
- return null;
18
- return {
19
- total: primaryProcess.total,
20
- success: primaryProcess.successCount,
21
- failures: primaryProcess.failureCount
22
- };
23
- }
24
- }
25
- exports.PrimaryProcessStrategy = PrimaryProcessStrategy;
26
- class CustomProgressStrategy {
27
- constructor(calculator) {
28
- this.calculator = calculator;
29
- }
30
- calculate(processes) {
31
- return this.calculator(processes);
32
- }
33
- }
34
- exports.CustomProgressStrategy = CustomProgressStrategy;
35
- // Registry
36
- class ProgressStrategyRegistry {
37
- static register(moduleName, strategy) {
38
- this.strategies.set(moduleName.toUpperCase(), strategy);
39
- }
40
- static get(moduleName) {
41
- return this.strategies.get(moduleName.toUpperCase()) || new DefaultProgressStrategy();
42
- }
43
- static clear() {
44
- this.strategies.clear();
45
- }
46
- static has(moduleName) {
47
- return this.strategies.has(moduleName.toUpperCase());
48
- }
49
- static getAllRegistered() {
50
- return Array.from(this.strategies.keys());
51
- }
52
- }
53
- exports.ProgressStrategyRegistry = ProgressStrategyRegistry;
54
- ProgressStrategyRegistry.strategies = new Map();
@@ -1,24 +0,0 @@
1
- import { ModuleResult, SummaryOptions } from '../interfaces/index';
2
- export default class SummaryManager {
3
- private modules;
4
- private operationName;
5
- private context;
6
- private operationStartTime;
7
- private branchName;
8
- constructor({ operationName, context }: SummaryOptions);
9
- getModules(): Map<string, ModuleResult>;
10
- registerModule(moduleName: string, totalItems?: number): void;
11
- startModule(moduleName: string): void;
12
- completeModule(moduleName: string, success?: boolean, error?: string): void;
13
- /**
14
- * Register process data for strategy calculations
15
- */
16
- registerProcessData(moduleName: string, processName: string, processData: any): void;
17
- updateModuleProgress(moduleName: string, success: boolean, itemName: string, error?: string): void;
18
- printFinalSummary(): void;
19
- private printFailureSummaryWithLogReference;
20
- private getStatusIcon;
21
- private formatDuration;
22
- private calculateSuccessRate;
23
- private formatSuccessRate;
24
- }
@@ -1,181 +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
- class SummaryManager {
6
- constructor({ operationName, context }) {
7
- this.modules = new Map();
8
- this.operationName = operationName;
9
- this.context = context;
10
- this.operationStartTime = Date.now();
11
- this.branchName = context.branchName || '';
12
- }
13
- getModules() {
14
- return this.modules;
15
- }
16
- registerModule(moduleName, totalItems = 0) {
17
- this.modules.set(moduleName, {
18
- name: moduleName,
19
- status: 'pending',
20
- totalItems,
21
- successCount: 0,
22
- failureCount: 0,
23
- failures: [],
24
- processes: [],
25
- });
26
- }
27
- startModule(moduleName) {
28
- const module = this.modules.get(moduleName);
29
- if (module) {
30
- module.status = 'running';
31
- module.startTime = Date.now();
32
- }
33
- }
34
- completeModule(moduleName, success = true, error) {
35
- const module = this.modules.get(moduleName);
36
- if (module) {
37
- module.status = success ? 'completed' : 'failed';
38
- module.endTime = Date.now();
39
- if (!success && error) {
40
- module.failures.push({ item: 'module', error });
41
- }
42
- }
43
- }
44
- /**
45
- * Register process data for strategy calculations
46
- */
47
- registerProcessData(moduleName, processName, processData) {
48
- const module = this.modules.get(moduleName);
49
- if (module) {
50
- if (!module.processes) {
51
- module.processes = [];
52
- }
53
- const existingIndex = module.processes.findIndex((p) => p.processName === processName);
54
- if (existingIndex >= 0) {
55
- module.processes[existingIndex] = Object.assign({ processName }, processData);
56
- }
57
- else {
58
- module.processes.push(Object.assign({ processName }, processData));
59
- }
60
- }
61
- }
62
- updateModuleProgress(moduleName, success, itemName, error) {
63
- const module = this.modules.get(moduleName);
64
- if (module) {
65
- if (success) {
66
- module.successCount++;
67
- }
68
- else {
69
- module.failureCount++;
70
- if (error) {
71
- module.failures.push({ item: itemName, error });
72
- }
73
- }
74
- }
75
- }
76
- printFinalSummary() {
77
- const operationEndTime = Date.now();
78
- const totalDuration = operationEndTime - this.operationStartTime;
79
- // Overall Statistics
80
- const totalModules = this.modules.size;
81
- const completedModules = Array.from(this.modules.values()).filter((m) => m.status === 'completed').length;
82
- const failedModules = Array.from(this.modules.values()).filter((m) => m.status === 'failed').length;
83
- const totalItems = Array.from(this.modules.values()).reduce((sum, m) => sum + m.successCount + m.failureCount, 0);
84
- const totalSuccess = Array.from(this.modules.values()).reduce((sum, m) => sum + m.successCount, 0);
85
- const totalFailures = Array.from(this.modules.values()).reduce((sum, m) => sum + m.failureCount, 0);
86
- console.log('\n' + chalk_1.default.bold('='.repeat(80)));
87
- console.log('\n' + chalk_1.default.bold('Overall Statistics:'));
88
- console.log(` Total ${this.operationName} Time: ${chalk_1.default.cyan(this.formatDuration(totalDuration))}`);
89
- console.log(` Modules Processed: ${chalk_1.default.cyan(completedModules)}/${chalk_1.default.cyan(totalModules)}`);
90
- console.log(` Items Processed: ${chalk_1.default.green(totalSuccess)} success, ${chalk_1.default.red(totalFailures)} failed of ${chalk_1.default.cyan(totalItems)} total`);
91
- console.log(` Success Rate: ${chalk_1.default.cyan(this.calculateSuccessRate(totalSuccess, totalItems))}%`);
92
- // Module Details
93
- console.log('\n' + chalk_1.default.bold('Module Details:'));
94
- console.log(chalk_1.default.gray('-'.repeat(80)));
95
- Array.from(this.modules.values()).forEach((module) => {
96
- const status = this.getStatusIcon(module.status);
97
- const totalCount = module.successCount + module.failureCount;
98
- const duration = module.endTime && module.startTime ? this.formatDuration(module.endTime - module.startTime) : 'N/A';
99
- const successRate = this.calculateSuccessRate(module.successCount, totalCount);
100
- console.log(`${status} ${module.name.padEnd(20)} | ` +
101
- `${String(module.successCount).padStart(4)}/${String(totalCount).padStart(4)} items | ` +
102
- `${this.formatSuccessRate(successRate).padStart(6)} | ` +
103
- `${duration.padStart(8)}`);
104
- });
105
- // Final Status
106
- console.log('\n' + chalk_1.default.bold('Final Status:'));
107
- if (failedModules === 0) {
108
- console.log(chalk_1.default.bold.green(`šŸŽ‰ ${this.operationName} completed successfully!`));
109
- }
110
- else if (completedModules > 0) {
111
- console.log(chalk_1.default.bold.yellow(`āš ļø ${this.operationName} completed with ${failedModules} failed modules`));
112
- }
113
- else {
114
- console.log(chalk_1.default.bold.red(`āŒ ${this.operationName} failed`));
115
- }
116
- console.log(chalk_1.default.bold('='.repeat(80)));
117
- console.log(chalk_1.default.bold('='.repeat(80)));
118
- // Simple failure summary with log reference
119
- this.printFailureSummaryWithLogReference();
120
- }
121
- printFailureSummaryWithLogReference() {
122
- const modulesWithFailures = Array.from(this.modules.values()).filter((m) => m.failures.length > 0);
123
- if (modulesWithFailures.length === 0)
124
- return;
125
- const totalFailures = modulesWithFailures.reduce((sum, m) => sum + m.failures.length, 0);
126
- console.log('\n' + chalk_1.default.bold.red('Failure Summary:'));
127
- console.log(chalk_1.default.red('-'.repeat(50)));
128
- modulesWithFailures.forEach((module) => {
129
- console.log(`${chalk_1.default.bold.red('āœ—')} ${chalk_1.default.bold(module.name)}: ${chalk_1.default.red(module.failures.length)} failures`);
130
- // Show just first 2-3 failures briefly
131
- const preview = module.failures.slice(0, 2);
132
- preview.forEach((failure) => {
133
- console.log(` • ${chalk_1.default.gray(failure.item)}`);
134
- });
135
- if (module.failures.length > 2) {
136
- console.log(` ${chalk_1.default.gray(`... and ${module.failures.length - 2} more`)}`);
137
- }
138
- });
139
- console.log(chalk_1.default.blue('\nšŸ“‹ For detailed error information, check the log files:'));
140
- //console.log(chalk.blue(` ${getLogPath()}`));
141
- console.log(chalk_1.default.gray(' Recent errors are logged with full context and stack traces.'));
142
- }
143
- getStatusIcon(status) {
144
- switch (status) {
145
- case 'completed':
146
- return chalk_1.default.green('āœ“');
147
- case 'failed':
148
- return chalk_1.default.red('āœ—');
149
- case 'running':
150
- return chalk_1.default.yellow('ā—');
151
- case 'pending':
152
- return chalk_1.default.gray('ā—‹');
153
- default:
154
- return chalk_1.default.gray('?');
155
- }
156
- }
157
- formatDuration(ms) {
158
- if (ms < 1000)
159
- return `${ms}ms`;
160
- if (ms < 60000)
161
- return `${(ms / 1000).toFixed(1)}s`;
162
- return `${(ms / 60000).toFixed(1)}m`;
163
- }
164
- calculateSuccessRate(success, total) {
165
- if (total === 0)
166
- return '0';
167
- return ((success / total) * 100).toFixed(1);
168
- }
169
- formatSuccessRate(rate) {
170
- if (rate === '100.0') {
171
- return '100%';
172
- }
173
- else if (parseFloat(rate) >= 10) {
174
- return `${rate}%`;
175
- }
176
- else {
177
- return ` ${rate}%`;
178
- }
179
- }
180
- }
181
- exports.default = SummaryManager;