Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
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
4 changes: 4 additions & 0 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ fileignoreconfig:
checksum: 3d0b5cf07f5a87256f132f85a5556d193ce5a1fa6d92df2c7c50514071d592b7
- filename: package-lock.json
checksum: 37a33f085b6df7ee03b326885bc38957b84fdb17984a3b03de04fd6921b42fee
- filename: src/commands/cm/stacks/export-query.ts
checksum: 62e15b1a2705c49ec7abfafa65e04654fdf5025361dd3485b2b9a78be70af1f6
- filename: src/utils/logger.ts
checksum: 01a252f8f650b171f93a63ae241edd50352fde5e1e6ad5fca07c2390b38975f8
version: '1.0'
5 changes: 3 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@contentstack/cli-cm-export-query",
"description": "Contentstack CLI plugin to export content from stack",
"version": "1.0.0-beta.5",
"version": "1.0.0-beta.6",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
Expand All @@ -18,6 +18,7 @@
"mkdirp": "^1.0.4",
"progress-stream": "^2.0.0",
"promise-limit": "^2.7.0",
"tslib": "^2.8.1",
"winston": "^3.17.0"
},
"devDependencies": {
Expand Down Expand Up @@ -45,7 +46,7 @@
"typescript": "^4.9.5"
},
"scripts": {
"build": "npm run clean && npm run compile && cp -r src/config lib/",
"build": "npm run clean && npm install && npm run compile && cp -r src/config lib/",
"clean": "rm -rf ./lib ./node_modules tsconfig.build.tsbuildinfo",
"compile": "tsc -b tsconfig.json",
"postpack": "rm -f oclif.manifest.json",
Expand Down
16 changes: 12 additions & 4 deletions src/commands/cm/stacks/export-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import {
formatError,
managementSDKClient,
ContentstackClient,
log,
} from '@contentstack/cli-utilities';
import { QueryExporter } from '../../../core/query-executor';
import { QueryExportConfig } from '../../../types';
import { log, setupQueryExportConfig, setupBranches } from '../../../utils';
import { setupQueryExportConfig, setupBranches, createLogContext } from '../../../utils';

export default class ExportQueryCommand extends Command {
static description = 'Export content from a stack using query-based filtering';
Expand Down Expand Up @@ -82,6 +83,8 @@ export default class ExportQueryCommand extends Command {
}

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

// Initialize management API client
const managementAPIClient: ContentstackClient = await managementSDKClient(exportQueryConfig);
Expand All @@ -94,15 +97,20 @@ 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);

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

log(exportQueryConfig, 'Query-based export completed successfully!', 'success');
log(exportQueryConfig, `Export files saved to: ${this.exportDir}`, 'info');
log.success('Query-based export completed successfully!', context);
log.info(`Export files saved to: ${this.exportDir}`, context);
} catch (error) {
log({ exportDir: this.exportDir } as QueryExportConfig, `Export failed: ${formatError(error)}`, 'error');
const errorConfig = { exportDir: this.exportDir, stackApiKey: '' } as QueryExportConfig;
const errorContext = createLogContext(errorConfig);
log.error(`Export failed: ${formatError(error)}`, errorContext);
throw error;
}
}
Expand Down
14 changes: 9 additions & 5 deletions src/core/module-exporter.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import { formatError } from '@contentstack/cli-utilities';
import { formatError, log } from '@contentstack/cli-utilities';
import ExportCommand from '@contentstack/cli-cm-export';
import { QueryExportConfig, Modules, ExportOptions } from '../types';
import { log } from '../utils/logger';
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 {
log(this.exportQueryConfig, `Exporting module: ${moduleName}`, 'info');
log.info(`Exporting module: ${moduleName}`, this.logContext);
log.debug(`Building export command for module: ${moduleName}`, this.logContext);

// Build command arguments
const cmd = this.buildExportCommand(moduleName, options);
Expand All @@ -25,6 +28,7 @@ export class ModuleExporter {

// Create export command instance
await ExportCommand.run(cmd);
log.debug(`Export command completed for module: ${moduleName}`, this.logContext);

// Read the exported data
// const data = await this.readExportedData(moduleName, options);
Expand All @@ -34,9 +38,9 @@ export class ModuleExporter {
}

// success message
log(this.exportQueryConfig, `Successfully exported ${moduleName}`, 'success');
log.success(`Successfully exported ${moduleName}`, this.logContext);
} catch (error) {
log(this.exportQueryConfig, `Failed to export ${moduleName}: ${formatError(error)}`, 'error');
log.error(`Failed to export ${moduleName}: ${formatError(error)}`, this.logContext);
throw error;
}
}
Expand Down
Loading