Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions src/commands/cm/stacks/export-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import {
flags,
FlagInput,
sanitizePath,
formatError,
managementSDKClient,
ContentstackClient,
log,
handleAndLogError,
} from '@contentstack/cli-utilities';
import { QueryExporter } from '../../../core/query-executor';
import { QueryExportConfig } from '../../../types';
Expand Down Expand Up @@ -83,8 +83,8 @@ export default class ExportQueryCommand extends Command {
}

this.exportDir = sanitizePath(exportQueryConfig.exportDir);
const context = createLogContext(exportQueryConfig);
log.debug('Export configuration setup completed', context);
exportQueryConfig.context = createLogContext(exportQueryConfig);
log.debug('Export configuration setup completed', exportQueryConfig.context);

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

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

// Initialize and run query export
log.debug('Starting query exporter', context);
log.debug('Starting query exporter', exportQueryConfig.context);
const queryExporter = new QueryExporter(managementAPIClient, exportQueryConfig);
await queryExporter.execute();
log.debug('Query exporter completed successfully', context);
log.debug('Query exporter completed successfully', exportQueryConfig.context);

log.success('Query-based export completed successfully!', context);
log.info(`Export files saved to: ${this.exportDir}`, context);
log.success('Query-based export completed successfully!', exportQueryConfig.context);
log.info(`Export files saved to: ${this.exportDir}`, exportQueryConfig.context);
} catch (error) {
const errorConfig = { exportDir: this.exportDir, stackApiKey: '' } as QueryExportConfig;
const errorContext = createLogContext(errorConfig);
log.error(`Export failed: ${formatError(error)}`, errorContext);
throw error;
handleAndLogError(error);
}
}
}
7 changes: 2 additions & 5 deletions src/core/module-exporter.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
import { formatError, log } from '@contentstack/cli-utilities';
import ExportCommand from '@contentstack/cli-cm-export';
import { QueryExportConfig, Modules, ExportOptions } from '../types';
import { createLogContext, LogContext } from '../utils/logger';


export class ModuleExporter {
private exportQueryConfig: QueryExportConfig;
private exportedModules: string[] = [];
private readonly logContext: LogContext;

constructor(exportQueryConfig: QueryExportConfig) {
this.exportQueryConfig = exportQueryConfig;
this.logContext = createLogContext(exportQueryConfig);
}

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

Expand All @@ -41,7 +38,7 @@ export class ModuleExporter {
// success message
log.success(`Successfully exported ${moduleName}`, moduleLogContext);
} catch (error) {
const moduleLogContext = createLogContext(this.exportQueryConfig, moduleName);
const moduleLogContext = { ...this.exportQueryConfig.context, module: moduleName };
log.error(`Failed to export ${moduleName}: ${formatError(error)}`, moduleLogContext);
throw error;
}
Expand Down
Loading