Skip to content

Commit dfeedc1

Browse files
Merge pull request #42 from contentstack/development
staging PR
2 parents e8751f3 + 87fece9 commit dfeedc1

File tree

14 files changed

+158
-113
lines changed

14 files changed

+158
-113
lines changed

.talismanrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@ fileignoreconfig:
33
checksum: 3d0b5cf07f5a87256f132f85a5556d193ce5a1fa6d92df2c7c50514071d592b7
44
- filename: package-lock.json
55
checksum: 37a33f085b6df7ee03b326885bc38957b84fdb17984a3b03de04fd6921b42fee
6+
- filename: src/commands/cm/stacks/export-query.ts
7+
checksum: 62e15b1a2705c49ec7abfafa65e04654fdf5025361dd3485b2b9a78be70af1f6
8+
- filename: src/utils/logger.ts
9+
checksum: 01a252f8f650b171f93a63ae241edd50352fde5e1e6ad5fca07c2390b38975f8
610
version: '1.0'

package-lock.json

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@contentstack/cli-cm-export-query",
33
"description": "Contentstack CLI plugin to export content from stack",
4-
"version": "1.0.0-beta.5",
4+
"version": "1.0.0-beta.6",
55
"author": "Contentstack",
66
"bugs": "https://github.com/contentstack/cli/issues",
77
"dependencies": {
@@ -18,6 +18,7 @@
1818
"mkdirp": "^1.0.4",
1919
"progress-stream": "^2.0.0",
2020
"promise-limit": "^2.7.0",
21+
"tslib": "^2.8.1",
2122
"winston": "^3.17.0"
2223
},
2324
"devDependencies": {
@@ -45,7 +46,7 @@
4546
"typescript": "^4.9.5"
4647
},
4748
"scripts": {
48-
"build": "npm run clean && npm run compile && cp -r src/config lib/",
49+
"build": "npm run clean && npm install && npm run compile && cp -r src/config lib/",
4950
"clean": "rm -rf ./lib ./node_modules tsconfig.build.tsbuildinfo",
5051
"compile": "tsc -b tsconfig.json",
5152
"postpack": "rm -f oclif.manifest.json",

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ import {
33
flags,
44
FlagInput,
55
sanitizePath,
6-
formatError,
76
managementSDKClient,
87
ContentstackClient,
8+
log,
9+
handleAndLogError,
910
} from '@contentstack/cli-utilities';
1011
import { QueryExporter } from '../../../core/query-executor';
1112
import { QueryExportConfig } from '../../../types';
12-
import { log, setupQueryExportConfig, setupBranches } from '../../../utils';
13+
import { setupQueryExportConfig, setupBranches, createLogContext } from '../../../utils';
1314

1415
export default class ExportQueryCommand extends Command {
1516
static description = 'Export content from a stack using query-based filtering';
@@ -82,6 +83,9 @@ export default class ExportQueryCommand extends Command {
8283
}
8384

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

8690
// Initialize management API client
8791
const managementAPIClient: ContentstackClient = await managementSDKClient(exportQueryConfig);
@@ -94,16 +98,18 @@ export default class ExportQueryCommand extends Command {
9498

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

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

102-
log(exportQueryConfig, 'Query-based export completed successfully!', 'success');
103-
log(exportQueryConfig, `Export files saved to: ${this.exportDir}`, 'info');
109+
log.success('Query-based export completed successfully!', exportQueryConfig.context);
110+
log.info(`Export files saved to: ${this.exportDir}`, exportQueryConfig.context);
104111
} catch (error) {
105-
log({ exportDir: this.exportDir } as QueryExportConfig, `Export failed: ${formatError(error)}`, 'error');
106-
throw error;
112+
handleAndLogError(error);
107113
}
108114
}
109115
}

src/core/module-exporter.ts

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

65

76
export class ModuleExporter {
@@ -14,7 +13,9 @@ export class ModuleExporter {
1413

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

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

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

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

3638
// success message
37-
log(this.exportQueryConfig, `Successfully exported ${moduleName}`, 'success');
39+
log.success(`Successfully exported ${moduleName}`, moduleLogContext);
3840
} catch (error) {
39-
log(this.exportQueryConfig, `Failed to export ${moduleName}: ${formatError(error)}`, 'error');
41+
const moduleLogContext = { ...this.exportQueryConfig.context, module: moduleName };
42+
handleAndLogError(error, moduleLogContext, `Failed to export ${moduleName}`);
4043
throw error;
4144
}
4245
}

0 commit comments

Comments
 (0)