Skip to content

Commit a5293ed

Browse files
Integrated centralized logger for query based export
1 parent 4ff9b5b commit a5293ed

File tree

12 files changed

+160
-106
lines changed

12 files changed

+160
-106
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: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ import {
66
formatError,
77
managementSDKClient,
88
ContentstackClient,
9+
log,
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';
@@ -99,10 +100,13 @@ export default class ExportQueryCommand extends Command {
99100
const queryExporter = new QueryExporter(managementAPIClient, exportQueryConfig);
100101
await queryExporter.execute();
101102

102-
log(exportQueryConfig, 'Query-based export completed successfully!', 'success');
103-
log(exportQueryConfig, `Export files saved to: ${this.exportDir}`, 'info');
103+
const context = createLogContext(exportQueryConfig);
104+
log.info('Query-based export completed successfully!', context);
105+
log.info(`Export files saved to: ${this.exportDir}`, context);
104106
} catch (error) {
105-
log({ exportDir: this.exportDir } as QueryExportConfig, `Export failed: ${formatError(error)}`, 'error');
107+
const errorConfig = { exportDir: this.exportDir, stackApiKey: '' } as QueryExportConfig;
108+
const errorContext = createLogContext(errorConfig);
109+
log.error(`Export failed: ${formatError(error)}`, errorContext);
106110
throw error;
107111
}
108112
}

src/core/module-exporter.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
import { formatError } from '@contentstack/cli-utilities';
1+
import { formatError, log } 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';
4+
import { createLogContext } from '../utils/logger';
55

66

77
export class ModuleExporter {
88
private exportQueryConfig: QueryExportConfig;
99
private exportedModules: string[] = [];
10+
private logContext: any;
1011

1112
constructor(exportQueryConfig: QueryExportConfig) {
1213
this.exportQueryConfig = exportQueryConfig;
14+
this.logContext = createLogContext(exportQueryConfig);
1315
}
1416

1517
async exportModule(moduleName: Modules, options: ExportOptions = {}): Promise<void> {
1618
try {
17-
log(this.exportQueryConfig, `Exporting module: ${moduleName}`, 'info');
19+
log.info(`Exporting module: ${moduleName}`, this.logContext);
1820

1921
// Build command arguments
2022
const cmd = this.buildExportCommand(moduleName, options);
@@ -34,9 +36,9 @@ export class ModuleExporter {
3436
}
3537

3638
// success message
37-
log(this.exportQueryConfig, `Successfully exported ${moduleName}`, 'success');
39+
log.info(`Successfully exported ${moduleName}`, this.logContext);
3840
} catch (error) {
39-
log(this.exportQueryConfig, `Failed to export ${moduleName}: ${formatError(error)}`, 'error');
41+
log.error(`Failed to export ${moduleName}: ${formatError(error)}`, this.logContext);
4042
throw error;
4143
}
4244
}

0 commit comments

Comments
 (0)