@contentstack/cli-utilities 1.17.0 → 1.17.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.
- package/lib/auth-handler.d.ts +0 -2
- package/lib/auth-handler.js +3 -6
- package/lib/constants/logging.d.ts +1 -0
- package/lib/constants/logging.js +4 -3
- package/lib/fs-utility/core.js +1 -2
- package/lib/helpers.d.ts +1 -0
- package/lib/helpers.js +11 -3
- package/lib/index.d.ts +1 -0
- package/lib/index.js +8 -1
- package/lib/interfaces/index.d.ts +50 -1
- package/lib/logger/cli-error-handler.js +1 -2
- package/lib/logger/log.js +1 -1
- package/lib/logger/logger.js +37 -17
- package/lib/progress-summary/cli-progress-manager.d.ts +125 -0
- package/lib/progress-summary/cli-progress-manager.js +544 -0
- package/lib/progress-summary/index.d.ts +4 -0
- package/lib/progress-summary/index.js +13 -0
- package/lib/progress-summary/progress-strategy.d.ts +25 -0
- package/lib/progress-summary/progress-strategy.js +54 -0
- package/lib/progress-summary/summary-manager.d.ts +28 -0
- package/lib/progress-summary/summary-manager.js +188 -0
- package/package.json +2 -2
package/lib/auth-handler.d.ts
CHANGED
|
@@ -21,7 +21,6 @@ declare class AuthHandler {
|
|
|
21
21
|
private authorisationTypeOAUTHValue;
|
|
22
22
|
private authorisationTypeAUTHValue;
|
|
23
23
|
private allAuthConfigItems;
|
|
24
|
-
private logger;
|
|
25
24
|
private oauthHandler;
|
|
26
25
|
private managementAPIClient;
|
|
27
26
|
private isRefreshingToken;
|
|
@@ -29,7 +28,6 @@ declare class AuthHandler {
|
|
|
29
28
|
set host(contentStackHost: any);
|
|
30
29
|
constructor();
|
|
31
30
|
private getCmaHost;
|
|
32
|
-
initLog(): void;
|
|
33
31
|
setOAuthBaseURL(): Promise<void>;
|
|
34
32
|
initSDK(): Promise<void>;
|
|
35
33
|
oauth(): Promise<void>;
|
package/lib/auth-handler.js
CHANGED
|
@@ -7,7 +7,7 @@ const dotenv_1 = tslib_1.__importDefault(require("dotenv"));
|
|
|
7
7
|
const open_1 = tslib_1.__importDefault(require("open"));
|
|
8
8
|
const http_1 = tslib_1.__importDefault(require("http"));
|
|
9
9
|
const url_1 = tslib_1.__importDefault(require("url"));
|
|
10
|
-
const
|
|
10
|
+
const log_1 = require("./logger/log");
|
|
11
11
|
const contentstack_management_sdk_1 = tslib_1.__importDefault(require("./contentstack-management-sdk"));
|
|
12
12
|
const helpers_1 = require("./helpers");
|
|
13
13
|
dotenv_1.default.config();
|
|
@@ -77,9 +77,6 @@ class AuthHandler {
|
|
|
77
77
|
}
|
|
78
78
|
return cma;
|
|
79
79
|
}
|
|
80
|
-
initLog() {
|
|
81
|
-
this.logger = new logger_1.LoggerService(process.cwd(), 'cli-log');
|
|
82
|
-
}
|
|
83
80
|
async setOAuthBaseURL() {
|
|
84
81
|
if (config_handler_1.default.get('region')['uiHost']) {
|
|
85
82
|
this.OAuthBaseURL = config_handler_1.default.get('region')['uiHost'] || '';
|
|
@@ -108,13 +105,12 @@ class AuthHandler {
|
|
|
108
105
|
*/
|
|
109
106
|
async oauth() {
|
|
110
107
|
try {
|
|
111
|
-
this.initLog();
|
|
112
108
|
await this.initSDK();
|
|
113
109
|
await this.createHTTPServer();
|
|
114
110
|
await this.openOAuthURL();
|
|
115
111
|
}
|
|
116
112
|
catch (error) {
|
|
117
|
-
|
|
113
|
+
(0, log_1.handleAndLogError)(error, { module: 'auth-handler' }, 'OAuth login failed!');
|
|
118
114
|
throw error;
|
|
119
115
|
}
|
|
120
116
|
}
|
|
@@ -375,6 +371,7 @@ class AuthHandler {
|
|
|
375
371
|
else {
|
|
376
372
|
cli_ux_1.default.print('No OAuth configuration set.');
|
|
377
373
|
this.unsetConfigData();
|
|
374
|
+
return Promise.resolve();
|
|
378
375
|
}
|
|
379
376
|
}
|
|
380
377
|
restoreOAuthConfig() {
|
package/lib/constants/logging.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.levelColors = exports.logLevels = void 0;
|
|
3
|
+
exports.PROGRESS_SUPPORTED_MODULES = exports.levelColors = exports.logLevels = void 0;
|
|
4
4
|
exports.logLevels = {
|
|
5
5
|
error: 0,
|
|
6
6
|
warn: 1,
|
|
7
7
|
info: 2,
|
|
8
8
|
success: 2,
|
|
9
9
|
debug: 3,
|
|
10
|
-
verbose: 4
|
|
10
|
+
verbose: 4,
|
|
11
11
|
};
|
|
12
12
|
// 2. Create color mappings (for console only)
|
|
13
13
|
exports.levelColors = {
|
|
@@ -15,5 +15,6 @@ exports.levelColors = {
|
|
|
15
15
|
warn: 'yellow',
|
|
16
16
|
success: 'green',
|
|
17
17
|
info: 'white',
|
|
18
|
-
debug: 'blue'
|
|
18
|
+
debug: 'blue',
|
|
19
19
|
};
|
|
20
|
+
exports.PROGRESS_SUPPORTED_MODULES = ['export', 'import', 'audit', 'import-setup'];
|
package/lib/fs-utility/core.js
CHANGED
|
@@ -11,7 +11,6 @@ const node_fs_1 = require("node:fs");
|
|
|
11
11
|
const helper_1 = require("./helper");
|
|
12
12
|
class FsUtility {
|
|
13
13
|
constructor(options = {}) {
|
|
14
|
-
var _a;
|
|
15
14
|
this.isArray = false;
|
|
16
15
|
this.prefixKey = '';
|
|
17
16
|
this.currentFileName = '';
|
|
@@ -35,7 +34,7 @@ class FsUtility {
|
|
|
35
34
|
this.metaPickKeys = metaPickKeys || [];
|
|
36
35
|
this.moduleName = moduleName || 'chunk';
|
|
37
36
|
this.chunkFileSize = chunkFileSize || 10;
|
|
38
|
-
this.keepMetadata = keepMetadata
|
|
37
|
+
this.keepMetadata = keepMetadata !== null && keepMetadata !== void 0 ? keepMetadata : true;
|
|
39
38
|
this.indexFileName = indexFileName || 'index.json';
|
|
40
39
|
this.pageInfo.hasNextPage = (0, keys_1.default)(this.indexFileContent).length > 0;
|
|
41
40
|
this.defaultInitContent = defaultInitContent || this.isArray ? '[' : this.fileExt === 'json' ? '{' : '';
|
package/lib/helpers.d.ts
CHANGED
|
@@ -27,6 +27,7 @@ export declare const formatError: (error: any) => string;
|
|
|
27
27
|
* from.
|
|
28
28
|
*/
|
|
29
29
|
export declare const redactObject: (obj: any) => any;
|
|
30
|
+
export declare function clearProgressModuleSetting(): void;
|
|
30
31
|
/**
|
|
31
32
|
* Get authentication method from config
|
|
32
33
|
* @returns Authentication method string ('OAuth', 'Basic Auth', or empty string)
|
package/lib/helpers.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createLogContext = exports.getAuthenticationMethod = exports.redactObject = exports.formatError = exports.validateRegex = exports.validateFileName = exports.validateUids = exports.sanitizePath = exports.escapeRegExp = exports.validatePath = exports.createDeveloperHubUrl = exports.isManagementTokenValid = exports.getBranchFromAlias = exports.doesBranchExist = exports.isAuthenticated = void 0;
|
|
3
|
+
exports.createLogContext = exports.getAuthenticationMethod = exports.clearProgressModuleSetting = exports.redactObject = exports.formatError = exports.validateRegex = exports.validateFileName = exports.validateUids = exports.sanitizePath = exports.escapeRegExp = exports.validatePath = exports.createDeveloperHubUrl = exports.isManagementTokenValid = exports.getBranchFromAlias = exports.doesBranchExist = exports.isAuthenticated = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const recheck_1 = require("recheck");
|
|
6
6
|
const traverse_1 = tslib_1.__importDefault(require("traverse"));
|
|
@@ -191,8 +191,8 @@ const formatError = function (error) {
|
|
|
191
191
|
// If message is in JSON format, parse it to extract the actual message string
|
|
192
192
|
try {
|
|
193
193
|
const parsedMessage = JSON.parse(message);
|
|
194
|
-
if (typeof parsedMessage === 'object') {
|
|
195
|
-
message = (parsedMessage === null || parsedMessage === void 0 ? void 0 : parsedMessage.message) || message;
|
|
194
|
+
if (typeof parsedMessage === 'object' && parsedMessage !== null) {
|
|
195
|
+
message = (parsedMessage === null || parsedMessage === void 0 ? void 0 : parsedMessage.message) || (parsedMessage === null || parsedMessage === void 0 ? void 0 : parsedMessage.errorMessage) || (parsedMessage === null || parsedMessage === void 0 ? void 0 : parsedMessage.error) || message;
|
|
196
196
|
}
|
|
197
197
|
}
|
|
198
198
|
catch (e) {
|
|
@@ -244,6 +244,14 @@ const sensitiveKeys = [
|
|
|
244
244
|
/management[-._]?token/i,
|
|
245
245
|
/delivery[-._]?token/i,
|
|
246
246
|
];
|
|
247
|
+
function clearProgressModuleSetting() {
|
|
248
|
+
const logConfig = _1.configHandler.get('log') || {};
|
|
249
|
+
if (logConfig === null || logConfig === void 0 ? void 0 : logConfig.progressSupportedModule) {
|
|
250
|
+
delete logConfig.progressSupportedModule;
|
|
251
|
+
_1.configHandler.set('log', logConfig);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
exports.clearProgressModuleSetting = clearProgressModuleSetting;
|
|
247
255
|
/**
|
|
248
256
|
* Get authentication method from config
|
|
249
257
|
* @returns Authentication method string ('OAuth', 'Basic Auth', or empty string)
|
package/lib/index.d.ts
CHANGED
|
@@ -26,3 +26,4 @@ export { default as TablePrompt } from './inquirer-table-prompt';
|
|
|
26
26
|
export { Logger };
|
|
27
27
|
export { default as authenticationHandler } from './authentication-handler';
|
|
28
28
|
export { v2Logger as log, cliErrorHandler, handleAndLogError, getLogPath } from './logger/log';
|
|
29
|
+
export { CLIProgressManager, SummaryManager, PrimaryProcessStrategy, ProgressStrategyRegistry, CustomProgressStrategy, DefaultProgressStrategy } from './progress-summary';
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
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.run = 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.printFlagDeprecation = exports.managementSDKInitiator = exports.managementSDKClient = exports.configHandler = exports.authHandler = exports.messageHandler = exports.CLIError = exports.cliux = exports.LoggerService = void 0;
|
|
3
|
+
exports.DefaultProgressStrategy = exports.CustomProgressStrategy = exports.ProgressStrategyRegistry = exports.PrimaryProcessStrategy = exports.SummaryManager = exports.CLIProgressManager = 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.run = 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.printFlagDeprecation = 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;
|
|
@@ -71,3 +71,10 @@ Object.defineProperty(exports, "log", { enumerable: true, get: function () { ret
|
|
|
71
71
|
Object.defineProperty(exports, "cliErrorHandler", { enumerable: true, get: function () { return log_1.cliErrorHandler; } });
|
|
72
72
|
Object.defineProperty(exports, "handleAndLogError", { enumerable: true, get: function () { return log_1.handleAndLogError; } });
|
|
73
73
|
Object.defineProperty(exports, "getLogPath", { enumerable: true, get: function () { return log_1.getLogPath; } });
|
|
74
|
+
var progress_summary_1 = require("./progress-summary");
|
|
75
|
+
Object.defineProperty(exports, "CLIProgressManager", { enumerable: true, get: function () { return progress_summary_1.CLIProgressManager; } });
|
|
76
|
+
Object.defineProperty(exports, "SummaryManager", { enumerable: true, get: function () { return progress_summary_1.SummaryManager; } });
|
|
77
|
+
Object.defineProperty(exports, "PrimaryProcessStrategy", { enumerable: true, get: function () { return progress_summary_1.PrimaryProcessStrategy; } });
|
|
78
|
+
Object.defineProperty(exports, "ProgressStrategyRegistry", { enumerable: true, get: function () { return progress_summary_1.ProgressStrategyRegistry; } });
|
|
79
|
+
Object.defineProperty(exports, "CustomProgressStrategy", { enumerable: true, get: function () { return progress_summary_1.CustomProgressStrategy; } });
|
|
80
|
+
Object.defineProperty(exports, "DefaultProgressStrategy", { enumerable: true, get: function () { return progress_summary_1.DefaultProgressStrategy; } });
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { logLevels } from
|
|
1
|
+
import { logLevels } from '../constants/logging';
|
|
2
|
+
import ProgressBar from 'cli-progress';
|
|
2
3
|
export interface IPromptOptions {
|
|
3
4
|
prompt?: string;
|
|
4
5
|
type?: 'normal' | 'mask' | 'hide' | 'single';
|
|
@@ -101,3 +102,51 @@ export interface ErrorContextBase {
|
|
|
101
102
|
export type ErrorContext = ErrorContextBase & {
|
|
102
103
|
[key: string]: unknown;
|
|
103
104
|
};
|
|
105
|
+
export interface Failure {
|
|
106
|
+
item: string;
|
|
107
|
+
error: string | null;
|
|
108
|
+
process?: string;
|
|
109
|
+
}
|
|
110
|
+
export interface ProcessProgress {
|
|
111
|
+
name: string;
|
|
112
|
+
total: number;
|
|
113
|
+
current: number;
|
|
114
|
+
status: 'pending' | 'active' | 'completed' | 'failed';
|
|
115
|
+
successCount: number;
|
|
116
|
+
failureCount: number;
|
|
117
|
+
failures: Failure[];
|
|
118
|
+
progressBar?: ProgressBar.SingleBar;
|
|
119
|
+
}
|
|
120
|
+
export interface ProgressManagerOptions {
|
|
121
|
+
showConsoleLogs?: boolean;
|
|
122
|
+
total?: number;
|
|
123
|
+
moduleName?: string;
|
|
124
|
+
enableNestedProgress?: boolean;
|
|
125
|
+
}
|
|
126
|
+
export interface ModuleResult {
|
|
127
|
+
name: string;
|
|
128
|
+
status: 'pending' | 'running' | 'completed' | 'failed';
|
|
129
|
+
startTime?: number;
|
|
130
|
+
endTime?: number;
|
|
131
|
+
totalItems: number;
|
|
132
|
+
successCount: number;
|
|
133
|
+
failureCount: number;
|
|
134
|
+
failures: Array<{
|
|
135
|
+
item: string;
|
|
136
|
+
error: string;
|
|
137
|
+
}>;
|
|
138
|
+
processes?: Array<{
|
|
139
|
+
processName: string;
|
|
140
|
+
[key: string]: any;
|
|
141
|
+
}>;
|
|
142
|
+
}
|
|
143
|
+
export interface SummaryOptions {
|
|
144
|
+
operationName: string;
|
|
145
|
+
context?: any;
|
|
146
|
+
branchName?: string;
|
|
147
|
+
}
|
|
148
|
+
export interface ProgressResult {
|
|
149
|
+
total: number;
|
|
150
|
+
success: number;
|
|
151
|
+
failures: number;
|
|
152
|
+
}
|
|
@@ -114,8 +114,7 @@ class CLIErrorHandler {
|
|
|
114
114
|
if (typeof error === 'object') {
|
|
115
115
|
try {
|
|
116
116
|
const errorObj = error;
|
|
117
|
-
const
|
|
118
|
-
const normalizedError = new Error(message);
|
|
117
|
+
const normalizedError = new Error('Error occurred');
|
|
119
118
|
// Only copy essential properties
|
|
120
119
|
const essentialProps = [
|
|
121
120
|
'code',
|
package/lib/logger/log.js
CHANGED
|
@@ -13,7 +13,7 @@ function createLoggerInstance() {
|
|
|
13
13
|
var _a;
|
|
14
14
|
const logConfig = __1.configHandler.get('log');
|
|
15
15
|
const logLevel = (logConfig === null || logConfig === void 0 ? void 0 : logConfig.level) || 'info';
|
|
16
|
-
const showConsoleLogs = (_a = logConfig === null || logConfig === void 0 ? void 0 : logConfig
|
|
16
|
+
const showConsoleLogs = (_a = logConfig === null || logConfig === void 0 ? void 0 : logConfig.showConsoleLogs) !== null && _a !== void 0 ? _a : false;
|
|
17
17
|
const config = {
|
|
18
18
|
basePath: getLogPath(),
|
|
19
19
|
logLevel: logLevel,
|
package/lib/logger/logger.js
CHANGED
|
@@ -6,6 +6,7 @@ const full_1 = require("klona/full");
|
|
|
6
6
|
const path_1 = require("path");
|
|
7
7
|
const winston = tslib_1.__importStar(require("winston"));
|
|
8
8
|
const logging_1 = require("../constants/logging");
|
|
9
|
+
const __1 = require("..");
|
|
9
10
|
const session_path_1 = require("./session-path");
|
|
10
11
|
class Logger {
|
|
11
12
|
constructor(config) {
|
|
@@ -46,26 +47,45 @@ class Logger {
|
|
|
46
47
|
};
|
|
47
48
|
}
|
|
48
49
|
createLogger(level, filePath) {
|
|
50
|
+
var _a;
|
|
51
|
+
const transports = [
|
|
52
|
+
new winston.transports.File(Object.assign(Object.assign({}, this.loggerOptions), { filename: `${filePath}/${level}.log`, format: winston.format.combine(winston.format.timestamp(), winston.format.printf((info) => {
|
|
53
|
+
// Apply minimal redaction for files (debugging info preserved)
|
|
54
|
+
const redactedInfo = this.redact(info, false);
|
|
55
|
+
return JSON.stringify(redactedInfo);
|
|
56
|
+
})) })),
|
|
57
|
+
];
|
|
58
|
+
// Determine console logging based on configuration
|
|
59
|
+
let showConsoleLogs = true;
|
|
60
|
+
if (__1.configHandler && typeof __1.configHandler.get === 'function') {
|
|
61
|
+
const logConfig = __1.configHandler.get('log') || {};
|
|
62
|
+
const currentModule = logConfig.progressSupportedModule;
|
|
63
|
+
const hasProgressSupport = currentModule && logging_1.PROGRESS_SUPPORTED_MODULES.includes(currentModule);
|
|
64
|
+
if (hasProgressSupport) {
|
|
65
|
+
// Plugin has progress bars - respect user's explicit setting, or default to false (show progress bars)
|
|
66
|
+
showConsoleLogs = (_a = logConfig.showConsoleLogs) !== null && _a !== void 0 ? _a : false;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
// Plugin doesn't have progress support - always show console logs
|
|
70
|
+
showConsoleLogs = true;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (showConsoleLogs) {
|
|
74
|
+
transports.push(new winston.transports.Console({
|
|
75
|
+
format: winston.format.combine(winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), winston.format.printf((info) => {
|
|
76
|
+
// Apply full redaction for console (user-facing)
|
|
77
|
+
const redactedInfo = this.redact(info, true);
|
|
78
|
+
const colorizer = winston.format.colorize();
|
|
79
|
+
const levelText = redactedInfo.level.toUpperCase();
|
|
80
|
+
const { timestamp, message } = redactedInfo;
|
|
81
|
+
return colorizer.colorize(redactedInfo.level, `[${timestamp}] ${levelText}: ${message}`);
|
|
82
|
+
})),
|
|
83
|
+
}));
|
|
84
|
+
}
|
|
49
85
|
return winston.createLogger({
|
|
50
86
|
levels: logging_1.logLevels,
|
|
51
87
|
level,
|
|
52
|
-
transports
|
|
53
|
-
new winston.transports.File(Object.assign(Object.assign({}, this.loggerOptions), { filename: `${filePath}/${level}.log`, format: winston.format.combine(winston.format.timestamp(), winston.format.printf((info) => {
|
|
54
|
-
// Apply minimal redaction for files (debugging info preserved)
|
|
55
|
-
const redactedInfo = this.redact(info, false);
|
|
56
|
-
return JSON.stringify(redactedInfo);
|
|
57
|
-
})) })),
|
|
58
|
-
new winston.transports.Console({
|
|
59
|
-
format: winston.format.combine(winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), winston.format.printf((info) => {
|
|
60
|
-
// Apply full redaction for console (user-facing)
|
|
61
|
-
const redactedInfo = this.redact(info, true);
|
|
62
|
-
const colorizer = winston.format.colorize();
|
|
63
|
-
const levelText = redactedInfo.level.toUpperCase();
|
|
64
|
-
const { timestamp, message } = redactedInfo;
|
|
65
|
-
return colorizer.colorize(redactedInfo.level, `[${timestamp}] ${levelText}: ${message}`);
|
|
66
|
-
})),
|
|
67
|
-
}),
|
|
68
|
-
],
|
|
88
|
+
transports,
|
|
69
89
|
});
|
|
70
90
|
}
|
|
71
91
|
isSensitiveKey(keyStr, consoleMode = false) {
|
|
@@ -0,0 +1,125 @@
|
|
|
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
|
+
* Check if there are any failures in the global summary
|
|
39
|
+
*/
|
|
40
|
+
static hasFailures(): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Apply strategy-based corrections to module data
|
|
43
|
+
*/
|
|
44
|
+
private static applyStrategyCorrections;
|
|
45
|
+
/**
|
|
46
|
+
* Clear global summary (for cleanup)
|
|
47
|
+
*/
|
|
48
|
+
static clearGlobalSummary(): void;
|
|
49
|
+
/**
|
|
50
|
+
* Create a simple progress manager (no nested processes)
|
|
51
|
+
*/
|
|
52
|
+
static createSimple(moduleName: string, total?: number, showConsoleLogs?: boolean): CLIProgressManager;
|
|
53
|
+
/**
|
|
54
|
+
* Create a nested progress manager (with sub-processes)
|
|
55
|
+
*/
|
|
56
|
+
static createNested(moduleName: string, showConsoleLogs?: boolean): CLIProgressManager;
|
|
57
|
+
/**
|
|
58
|
+
* Show a loading spinner before initializing progress
|
|
59
|
+
*/
|
|
60
|
+
static withLoadingSpinner<T>(message: string, asyncOperation: () => Promise<T>): Promise<T>;
|
|
61
|
+
private setupGlobalSummaryIntegration;
|
|
62
|
+
/**
|
|
63
|
+
* Register process data with summary manager for strategy calculations
|
|
64
|
+
*/
|
|
65
|
+
private registerProcessDataWithSummary;
|
|
66
|
+
/**
|
|
67
|
+
* Set callbacks for external integration
|
|
68
|
+
*/
|
|
69
|
+
setCallbacks(callbacks: ProgressCallback): void;
|
|
70
|
+
/**
|
|
71
|
+
* Convert module name from UPPERCASE to PascalCase
|
|
72
|
+
*/
|
|
73
|
+
private formatModuleName;
|
|
74
|
+
/**
|
|
75
|
+
* Format process name with smart truncation (modules should use short names)
|
|
76
|
+
*/
|
|
77
|
+
private formatProcessName;
|
|
78
|
+
/**
|
|
79
|
+
* Format percentage for consistent alignment (always 3 characters)
|
|
80
|
+
*/
|
|
81
|
+
private formatPercentage;
|
|
82
|
+
private initializeProgress;
|
|
83
|
+
/**
|
|
84
|
+
* Add a new process to track (for nested progress)
|
|
85
|
+
*/
|
|
86
|
+
addProcess(processName: string, total: number): this;
|
|
87
|
+
/**
|
|
88
|
+
* Update the total for a specific process (for dynamic totals after API calls)
|
|
89
|
+
*/
|
|
90
|
+
updateProcessTotal(processName: string, newTotal: number): this;
|
|
91
|
+
/**
|
|
92
|
+
* Start a specific process
|
|
93
|
+
*/
|
|
94
|
+
startProcess(processName: string): this;
|
|
95
|
+
/**
|
|
96
|
+
* Complete a specific process
|
|
97
|
+
*/
|
|
98
|
+
completeProcess(processName: string, success?: boolean): this;
|
|
99
|
+
/**
|
|
100
|
+
* Update status message
|
|
101
|
+
*/
|
|
102
|
+
updateStatus(message: string, processName?: string): this;
|
|
103
|
+
/**
|
|
104
|
+
* Update progress
|
|
105
|
+
*/
|
|
106
|
+
tick(success?: boolean, itemName?: string, errorMessage?: string | null, processName?: string): this;
|
|
107
|
+
/**
|
|
108
|
+
* Complete the entire module
|
|
109
|
+
*/
|
|
110
|
+
complete(success?: boolean, error?: string): this;
|
|
111
|
+
/**
|
|
112
|
+
* Log message (respects showConsoleLogs mode)
|
|
113
|
+
*/
|
|
114
|
+
log(msg: string): void;
|
|
115
|
+
/**
|
|
116
|
+
* Stop all progress indicators
|
|
117
|
+
*/
|
|
118
|
+
stop(): void;
|
|
119
|
+
private printSummary;
|
|
120
|
+
/**
|
|
121
|
+
* Get the current failure count
|
|
122
|
+
*/
|
|
123
|
+
getFailureCount(): number;
|
|
124
|
+
}
|
|
125
|
+
export {};
|