Skip to content

Commit 3afefb1

Browse files
authored
Merge pull request #2052 from contentstack/refactor/DX-3343
refactor: removed summary & header from first process
2 parents 5a0923f + a1c88c5 commit 3afefb1

File tree

5 files changed

+97
-74
lines changed

5 files changed

+97
-74
lines changed

.talismanrc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
fileignoreconfig:
22
- filename: package-lock.json
3-
checksum: c73d080bfbbf03bc2597891f956367bfd71f5f2f8d03525175426015265edc91
3+
checksum: 1c4c7e056ad7330134ac5726d3ef11cd4b40f567161b5a9c405294705e819099
44
- filename: pnpm-lock.yaml
5-
checksum: 0ca85066946c49994a4353c9f64b8f380d5d2050194e3e57ad7ccd7faa030d36
5+
checksum: 6034c8cc26390236c9e172454451e918febeaec373c5509886f1d15ee1017021
66
- filename: packages/contentstack-import-setup/test/unit/backup-handler.test.ts
77
checksum: 0582d62b88834554cf12951c8690a73ef3ddbb78b82d2804d994cf4148e1ef93
88
- filename: packages/contentstack-import-setup/test/config.json
@@ -35,4 +35,6 @@ fileignoreconfig:
3535
checksum: c09f6dc93702caff3adf689b501ec32586a16c865c1fe3a63b53ae645ca22349
3636
- filename: packages/contentstack-import-setup/test/unit/modules/assets.test.ts
3737
checksum: 449a5e3383631a6f78d1291aa3c28c91681879289398f0a933158fba5c5d5acf
38+
- filename: packages/contentstack-import/src/commands/cm/stacks/import.ts
39+
checksum: 0dbf0a6bc447206260b8acd41b85781d60ca50c948bb3ca62f444f97d64d1fb2
3840
version: "1.0"

packages/contentstack-export/src/export/module-exporter.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class ModuleExporter {
3535
return this.exportByBranches();
3636
}
3737
// If branches disabled then initialize the global summary
38-
CLIProgressManager.initializeGlobalSummary('EXPORT', this.exportConfig.branchName);
38+
CLIProgressManager.initializeGlobalSummary('EXPORT', this.exportConfig.branchName, 'EXPORTING CONTENT');
3939
return this.export();
4040
}
4141

@@ -50,7 +50,8 @@ class ModuleExporter {
5050
// Reset progress manager for each branch (except the first one which was initialized in export command)
5151
if (index >= 0) {
5252
CLIProgressManager.clearGlobalSummary();
53-
CLIProgressManager.initializeGlobalSummary(`EXPORT-${branch.uid}`, branch.uid);
53+
CLIProgressManager.initializeGlobalSummary(`EXPORT-${branch.uid}`, branch.uid, `EXPORTING "${branch.uid}" BRANCH CONTENT`,);
54+
5455
}
5556

5657
log.info(`Exporting content from branch ${branch.uid}`, this.exportConfig.context);

packages/contentstack-utilities/src/progress-summary/cli-progress-manager.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ export default class CLIProgressManager {
6565
/**
6666
* Initialize global summary manager for the entire operation
6767
*/
68-
static initializeGlobalSummary(operationName: string, branchName: string): SummaryManager {
68+
static initializeGlobalSummary(operationName: string, branchName: string, headerTitle?: string): SummaryManager {
6969
CLIProgressManager.globalSummary = new SummaryManager({ operationName, context: { branchName } });
7070

7171
// Only show header if console logs are disabled (progress UI mode)
7272
if (!configHandler.get('log')?.showConsoleLogs) {
73-
CLIProgressManager.displayOperationHeader(operationName, branchName);
73+
CLIProgressManager.displayOperationHeader(branchName, headerTitle);
7474
}
7575

7676
return CLIProgressManager.globalSummary;
@@ -79,10 +79,13 @@ export default class CLIProgressManager {
7979
/**
8080
* Display operation header with branch information
8181
*/
82-
static displayOperationHeader(operationName: string, branchName: string): void {
83-
const branchInfo = branchName ? `EXPORTING "${branchName.toUpperCase()}" BRANCH CONTENT` : '';
82+
static displayOperationHeader(branchName: string, headerTitle?: string): void {
83+
if (!headerTitle) return;
84+
85+
const safeBranchName = branchName || 'main';
86+
const branchInfo = headerTitle || `${safeBranchName?.toUpperCase()} CONTENT`;
87+
8488
console.log('\n' + chalk.bold('='.repeat(80)));
85-
console.log(chalk.bold.cyan(` ${operationName.toUpperCase()}`));
8689
if (branchInfo) {
8790
console.log(chalk.bold.white(` ${branchInfo}`));
8891
}
@@ -171,7 +174,7 @@ export default class CLIProgressManager {
171174
}
172175

173176
/**
174-
* Convert module name from UPPERCASE to PascalCase
177+
* Convert module name from UPPERCASE to PascalCase
175178
*/
176179
private formatModuleName(name: string): string {
177180
return name.charAt(0).toUpperCase() + name.slice(1).toLowerCase();
@@ -478,15 +481,15 @@ export default class CLIProgressManager {
478481
` ${status} ${processName}: ${process.successCount}${process.failureCount}✗ (${process.current}/${process.total})`,
479482
);
480483

481-
// Show first few failures for this process
482-
if (process.failures.length > 0) {
483-
process.failures.slice(0, 3).forEach((failure) => {
484-
this.log(` ✗ ${failure.item}: ${failure.error}`);
485-
});
486-
if (process.failures.length > 3) {
487-
this.log(` ... and ${process.failures.length - 3} more failures`);
488-
}
489-
}
484+
// Show first few failures for this process - TEMPORARILY DISABLED - will be shown in separate section later
485+
// if (process.failures.length > 0) {
486+
// process.failures.slice(0, 3).forEach((failure) => {
487+
// this.log(` ✗ ${failure.item}: ${failure.error}`);
488+
// });
489+
// if (process.failures.length > 3) {
490+
// this.log(` ... and ${process.failures.length - 3} more failures`);
491+
// }
492+
// }
490493
}
491494

492495
this.log(`\nOverall: ${this.successCount}${this.failureCount}✗`);

packages/contentstack-utilities/src/progress-summary/summary-manager.ts

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,6 @@ export default class SummaryManager {
6464
const operationEndTime = Date.now();
6565
const totalDuration = operationEndTime - this.operationStartTime;
6666

67-
const branchInfo = this.branchName ? `EXPORTING "${this.branchName.toUpperCase()}" BRANCH RESULTS` : '';
68-
69-
console.log('\n' + chalk.bold('='.repeat(80)));
70-
console.log(chalk.bold.cyan(` ${this.operationName} SUMMARY`));
71-
if (branchInfo) {
72-
console.log(chalk.bold.white(` ${branchInfo}`));
73-
}
74-
console.log(chalk.bold('='.repeat(80)));
75-
7667
// Overall Statistics
7768
const totalModules = this.modules.size;
7869
const completedModules = Array.from(this.modules.values()).filter((m) => m.status === 'completed').length;
@@ -81,6 +72,7 @@ export default class SummaryManager {
8172
const totalSuccess = Array.from(this.modules.values()).reduce((sum, m) => sum + m.successCount, 0);
8273
const totalFailures = Array.from(this.modules.values()).reduce((sum, m) => sum + m.failureCount, 0);
8374

75+
console.log('\n' + chalk.bold('='.repeat(80)));
8476
console.log('\n' + chalk.bold('Overall Statistics:'));
8577
console.log(` Total ${this.operationName} Time: ${chalk.cyan(this.formatDuration(totalDuration))}`);
8678
console.log(` Modules Processed: ${chalk.cyan(completedModules)}/${chalk.cyan(totalModules)}`);
@@ -110,16 +102,17 @@ export default class SummaryManager {
110102
`${duration.padStart(8)}`,
111103
);
112104

113-
// Show failures if any
114-
if (module.failures.length > 0) {
115-
console.log(chalk.red(` Failures (${module.failures.length}):`));
116-
module.failures.slice(0, 5).forEach((failure) => {
117-
console.log(chalk.red(` - ${failure.item}: ${failure.error}`));
118-
});
119-
if (module.failures.length > 5) {
120-
console.log(chalk.red(` ... and ${module.failures.length - 5} more`));
121-
}
122-
}
105+
106+
// Show failures if any - TEMPORARILY DISABLED - will be shown in separate section later
107+
// if (module.failures.length > 0) {
108+
// console.log(chalk.red(` Failures (${module.failures.length}):`));
109+
// module.failures.slice(0, 5).forEach((failure) => {
110+
// console.log(chalk.red(` - ${failure.item}: ${failure.error}`));
111+
// });
112+
// if (module.failures.length > 5) {
113+
// console.log(chalk.red(` ... and ${module.failures.length - 5} more`));
114+
// }
115+
// }
123116
});
124117

125118
// Final Status
@@ -132,6 +125,8 @@ export default class SummaryManager {
132125
console.log(chalk.bold.red(`❌ ${this.operationName} failed`));
133126
}
134127

128+
//TODO:- Smart Failure Summary - only show if there are failures
129+
135130
console.log(chalk.bold('='.repeat(80)));
136131
}
137132

packages/contentstack-variants/src/utils/personalization-api-adapter.ts

Lines changed: 58 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -127,30 +127,34 @@ export class PersonalizationAdapter<T> extends AdapterHelper<T, HttpClient> impl
127127
}
128128

129129
async init(): Promise<void> {
130-
log.debug('Initializing personalization adapter...', this.exportConfig?.context);
131-
await authenticationHandler.getAuthDetails();
132-
const token = authenticationHandler.accessToken;
133-
log.debug(
134-
`Authentication type: ${authenticationHandler.isOauthEnabled ? 'OAuth' : 'Token'}`,
135-
this.exportConfig?.context,
136-
);
137-
138-
if (authenticationHandler.isOauthEnabled) {
139-
log.debug('Setting OAuth authorization header', this.exportConfig?.context);
140-
this.apiClient.headers({ authorization: token });
141-
if (this.adapterConfig.cmaConfig) {
142-
log.debug('Setting OAuth authorization header for CMA client', this.exportConfig?.context);
143-
this.cmaAPIClient?.headers({ authorization: token });
144-
}
145-
} else {
146-
log.debug('Setting authtoken header', this.exportConfig?.context);
147-
this.apiClient.headers({ authtoken: token });
148-
if (this.adapterConfig.cmaConfig) {
149-
log.debug('Setting authtoken header for CMA client', this.exportConfig?.context);
150-
this.cmaAPIClient?.headers({ authtoken: token });
130+
try {
131+
log.debug('Initializing personalization adapter...', this.exportConfig?.context);
132+
await authenticationHandler.getAuthDetails();
133+
const token = authenticationHandler.accessToken;
134+
log.debug(
135+
`Authentication type: ${authenticationHandler.isOauthEnabled ? 'OAuth' : 'Token'}`,
136+
this.exportConfig?.context,
137+
);
138+
139+
if (authenticationHandler.isOauthEnabled) {
140+
log.debug('Setting OAuth authorization header', this.exportConfig?.context);
141+
this.apiClient.headers({ authorization: token });
142+
if (this.adapterConfig.cmaConfig) {
143+
log.debug('Setting OAuth authorization header for CMA client', this.exportConfig?.context);
144+
this.cmaAPIClient?.headers({ authorization: token });
145+
}
146+
} else {
147+
log.debug('Setting authtoken header', this.exportConfig?.context);
148+
this.apiClient.headers({ authtoken: token });
149+
if (this.adapterConfig.cmaConfig) {
150+
log.debug('Setting authtoken header for CMA client', this.exportConfig?.context);
151+
this.cmaAPIClient?.headers({ authtoken: token });
152+
}
151153
}
154+
log.debug('Personalization adapter initialization completed', this.exportConfig?.context);
155+
} catch (error: any) {
156+
log.debug(`Personalization adapter initialization failed: ${error}`, this.exportConfig?.context);
152157
}
153-
log.debug('Personalization adapter initialization completed', this.exportConfig?.context);
154158
}
155159

156160
async projects(options: GetProjectsParams): Promise<ProjectStruct[]> {
@@ -170,7 +174,7 @@ export class PersonalizationAdapter<T> extends AdapterHelper<T, HttpClient> impl
170174

171175
return result;
172176
} catch (error: any) {
173-
this.updateProgress(false, 'projects fetch', error?.message || 'Failed to fetch projects', 'Projects');
177+
log.debug(`Failed to fetch projects: ${error}`, this.exportConfig?.context);
174178
throw error;
175179
}
176180
}
@@ -226,7 +230,7 @@ export class PersonalizationAdapter<T> extends AdapterHelper<T, HttpClient> impl
226230

227231
return result;
228232
} catch (error: any) {
229-
this.updateProgress(false, 'experiences fetch', error?.message || 'Failed to fetch experiences', 'Experiences');
233+
log.debug(`Failed to fetch experiences: ${error}`, this.exportConfig?.context);
230234
throw error;
231235
}
232236
}
@@ -318,10 +322,16 @@ export class PersonalizationAdapter<T> extends AdapterHelper<T, HttpClient> impl
318322

319323
async getEvents(): Promise<EventStruct[] | void> {
320324
log.debug('Fetching events from personalization API', this.exportConfig?.context);
321-
const data = await this.apiClient.get<EventStruct>('/events');
322-
const result = (await this.handleVariantAPIRes(data)) as EventStruct[];
323-
log.debug(`Fetched ${result?.length || 0} events`, this.exportConfig?.context);
324-
return result;
325+
try {
326+
const data = await this.apiClient.get<EventStruct>('/events');
327+
const result = (await this.handleVariantAPIRes(data)) as EventStruct[];
328+
log.debug(`Fetched ${result?.length || 0} events`, this.exportConfig?.context);
329+
return result;
330+
} catch (error: any) {
331+
log.debug(`Failed to fetch events: ${error}`, this.exportConfig?.context);
332+
// Return empty array instead of throwing to prevent spinner from hanging
333+
throw error;
334+
}
325335
}
326336

327337
async createEvents(event: CreateEventInput): Promise<void | EventStruct> {
@@ -333,18 +343,30 @@ export class PersonalizationAdapter<T> extends AdapterHelper<T, HttpClient> impl
333343

334344
async getAudiences(): Promise<AudienceStruct[] | void> {
335345
log.debug('Fetching audiences from personalization API', this.exportConfig?.context);
336-
const data = await this.apiClient.get<AudienceStruct>('/audiences');
337-
const result = (await this.handleVariantAPIRes(data)) as AudienceStruct[];
338-
log.debug(`Fetched ${result?.length || 0} audiences`, this.exportConfig?.context);
339-
return result;
346+
try {
347+
const data = await this.apiClient.get<AudienceStruct>('/audiences');
348+
const result = (await this.handleVariantAPIRes(data)) as AudienceStruct[];
349+
log.debug(`Fetched ${result?.length || 0} audiences`, this.exportConfig?.context);
350+
return result;
351+
} catch (error: any) {
352+
log.debug(`Failed to fetch audiences: ${error}`, this.exportConfig?.context);
353+
// Return empty array instead of throwing to prevent spinner from hanging
354+
throw error;
355+
}
340356
}
341357

342358
async getAttributes(): Promise<AttributeStruct[] | void> {
343359
log.debug('Fetching attributes from personalization API', this.exportConfig?.context);
344-
const data = await this.apiClient.get<AttributeStruct>('/attributes');
345-
const result = (await this.handleVariantAPIRes(data)) as AttributeStruct[];
346-
log.debug(`Fetched ${result?.length || 0} attributes`, this.exportConfig?.context);
347-
return result;
360+
try {
361+
const data = await this.apiClient.get<AttributeStruct>('/attributes');
362+
const result = (await this.handleVariantAPIRes(data)) as AttributeStruct[];
363+
log.debug(`Fetched ${result?.length || 0} attributes`, this.exportConfig?.context);
364+
return result;
365+
} catch (error: any) {
366+
log.debug(`Failed to fetch attributes: ${error}`, this.exportConfig?.context);
367+
// Return empty array instead of throwing to prevent spinner from hanging
368+
throw error;
369+
}
348370
}
349371

350372
/**

0 commit comments

Comments
 (0)