Skip to content

Commit bd85841

Browse files
Fixed PR comments
1 parent 0e5c2ad commit bd85841

File tree

7 files changed

+79
-96
lines changed

7 files changed

+79
-96
lines changed

src/commands/cm/stacks/export-query.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import {
33
flags,
44
FlagInput,
55
sanitizePath,
6-
formatError,
76
managementSDKClient,
87
ContentstackClient,
98
log,
9+
handleAndLogError,
1010
} from '@contentstack/cli-utilities';
1111
import { QueryExporter } from '../../../core/query-executor';
1212
import { QueryExportConfig } from '../../../types';
@@ -83,8 +83,8 @@ export default class ExportQueryCommand extends Command {
8383
}
8484

8585
this.exportDir = sanitizePath(exportQueryConfig.exportDir);
86-
const context = createLogContext(exportQueryConfig);
87-
log.debug('Export configuration setup completed', context);
86+
exportQueryConfig.context = createLogContext(exportQueryConfig);
87+
log.debug('Export configuration setup completed', exportQueryConfig.context);
8888

8989
// Initialize management API client
9090
const managementAPIClient: ContentstackClient = await managementSDKClient(exportQueryConfig);
@@ -97,21 +97,18 @@ export default class ExportQueryCommand extends Command {
9797

9898
// Setup branches (validate branch or set default to 'main')
9999
await setupBranches(exportQueryConfig, stackAPIClient);
100-
log.debug('Branch configuration setup completed', context);
100+
log.debug('Branch configuration setup completed', exportQueryConfig.context);
101101

102102
// Initialize and run query export
103-
log.debug('Starting query exporter', context);
103+
log.debug('Starting query exporter', exportQueryConfig.context);
104104
const queryExporter = new QueryExporter(managementAPIClient, exportQueryConfig);
105105
await queryExporter.execute();
106-
log.debug('Query exporter completed successfully', context);
106+
log.debug('Query exporter completed successfully', exportQueryConfig.context);
107107

108-
log.success('Query-based export completed successfully!', context);
109-
log.info(`Export files saved to: ${this.exportDir}`, context);
108+
log.success('Query-based export completed successfully!', exportQueryConfig.context);
109+
log.info(`Export files saved to: ${this.exportDir}`, exportQueryConfig.context);
110110
} catch (error) {
111-
const errorConfig = { exportDir: this.exportDir, stackApiKey: '' } as QueryExportConfig;
112-
const errorContext = createLogContext(errorConfig);
113-
log.error(`Export failed: ${formatError(error)}`, errorContext);
114-
throw error;
111+
handleAndLogError(error);
115112
}
116113
}
117114
}

src/core/module-exporter.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
import { formatError, log } from '@contentstack/cli-utilities';
22
import ExportCommand from '@contentstack/cli-cm-export';
33
import { QueryExportConfig, Modules, ExportOptions } from '../types';
4-
import { createLogContext, LogContext } from '../utils/logger';
54

65

76
export class ModuleExporter {
87
private exportQueryConfig: QueryExportConfig;
98
private exportedModules: string[] = [];
10-
private readonly logContext: LogContext;
119

1210
constructor(exportQueryConfig: QueryExportConfig) {
1311
this.exportQueryConfig = exportQueryConfig;
14-
this.logContext = createLogContext(exportQueryConfig);
1512
}
1613

1714
async exportModule(moduleName: Modules, options: ExportOptions = {}): Promise<void> {
1815
try {
19-
const moduleLogContext = createLogContext(this.exportQueryConfig, moduleName);
16+
const moduleLogContext = { ...this.exportQueryConfig.context, module: moduleName };
2017
log.info(`Exporting module: ${moduleName}`, moduleLogContext);
2118
log.debug(`Building export command for module: ${moduleName}`, moduleLogContext);
2219

@@ -41,7 +38,7 @@ export class ModuleExporter {
4138
// success message
4239
log.success(`Successfully exported ${moduleName}`, moduleLogContext);
4340
} catch (error) {
44-
const moduleLogContext = createLogContext(this.exportQueryConfig, moduleName);
41+
const moduleLogContext = { ...this.exportQueryConfig.context, module: moduleName };
4542
log.error(`Failed to export ${moduleName}: ${formatError(error)}`, moduleLogContext);
4643
throw error;
4744
}

0 commit comments

Comments
 (0)