Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
18 changes: 12 additions & 6 deletions src/commands/cm/stacks/export-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import {
flags,
FlagInput,
sanitizePath,
formatError,
managementSDKClient,
ContentstackClient,
log,
handleAndLogError,
} 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,9 @@ export default class ExportQueryCommand extends Command {
}

this.exportDir = sanitizePath(exportQueryConfig.exportDir);
// Create base context without module name - module field is set dynamically during each module export
exportQueryConfig.context = createLogContext(exportQueryConfig);
log.debug('Export configuration setup completed', exportQueryConfig.context);

// Initialize management API client
const managementAPIClient: ContentstackClient = await managementSDKClient(exportQueryConfig);
Expand All @@ -94,16 +98,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', exportQueryConfig.context);

// Initialize and run query export
log.debug('Starting query exporter', exportQueryConfig.context);
const queryExporter = new QueryExporter(managementAPIClient, exportQueryConfig);
await queryExporter.execute();
log.debug('Query exporter completed successfully', exportQueryConfig.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!', exportQueryConfig.context);
log.info(`Export files saved to: ${this.exportDir}`, exportQueryConfig.context);
} catch (error) {
log({ exportDir: this.exportDir } as QueryExportConfig, `Export failed: ${formatError(error)}`, 'error');
throw error;
handleAndLogError(error);
}
}
}
13 changes: 8 additions & 5 deletions src/core/module-exporter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { formatError } from '@contentstack/cli-utilities';
import { log, handleAndLogError } from '@contentstack/cli-utilities';
import ExportCommand from '@contentstack/cli-cm-export';
import { QueryExportConfig, Modules, ExportOptions } from '../types';
import { log } from '../utils/logger';


export class ModuleExporter {
Expand All @@ -14,7 +13,9 @@ export class ModuleExporter {

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

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

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

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

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