Skip to content

Commit ad7489b

Browse files
authored
Merge pull request #1948 from contentstack/feat/DX-3077-v2Logger-integration-export
feat: integrated v2Logger in export plugin
2 parents 6446419 + baab85e commit ad7489b

44 files changed

Lines changed: 639 additions & 363 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.talismanrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,14 @@ fileignoreconfig:
134134
checksum: 023cf08f215cd0778599fb8478c94419373d4687f04421c4eb99d87de86a4a3e
135135
- filename: packages/contentstack-utilities/src/logger/logger.ts
136136
checksum: 09f3b73dd995bafc253265c676f06308513e6b1842d9bc01d39e6b6945a54c7d
137+
- filename: packages/contentstack-export/src/export/modules/environments.ts
138+
checksum: 10cb048a8f30e2645a4c949fd2a51d0c741b7fdacb377768d2c0cfe34bdaf4e2
139+
- filename: packages/contentstack-export/src/utils/basic-login.ts
140+
checksum: f95d4c0976729bd17238bf64713b3851d8852dbf60591210412c12ddaddd60c9
141+
- filename: packages/contentstack-utilities/src/interfaces/index.ts
142+
checksum: 70079d81524ae4c196ffc77f13306184a8944b2903b881947dd06120150f31b0
143+
- filename: packages/contentstack-export/src/commands/cm/stacks/export.ts
144+
checksum: 941c6a8d59ba58e2004030202ee6282cdd2a424cf8b089aef70a85198553fefe
145+
- filename: packages/contentstack-utilities/src/logger/logger.ts
146+
checksum: b56504c1e4fb31b676cc1931eb30afc7b9466f03890fe3c76977309e1fd066a6
137147
version: "1.0"

packages/contentstack-audit/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ $ npm install -g @contentstack/cli-audit
1919
$ csdx COMMAND
2020
running command...
2121
$ csdx (--version|-v)
22-
@contentstack/cli-audit/1.12.2 darwin-arm64 node-v22.14.0
22+
@contentstack/cli-audit/1.13.0 darwin-arm64 node-v22.14.0
2323
$ csdx --help [COMMAND]
2424
USAGE
2525
$ csdx COMMAND
@@ -305,7 +305,7 @@ EXAMPLES
305305
$ csdx plugins
306306
```
307307

308-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.38/src/commands/plugins/index.ts)_
308+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.39/src/commands/plugins/index.ts)_
309309

310310
## `csdx plugins:add PLUGIN`
311311

@@ -379,7 +379,7 @@ EXAMPLES
379379
$ csdx plugins:inspect myplugin
380380
```
381381

382-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.38/src/commands/plugins/inspect.ts)_
382+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.39/src/commands/plugins/inspect.ts)_
383383

384384
## `csdx plugins:install PLUGIN`
385385

@@ -428,7 +428,7 @@ EXAMPLES
428428
$ csdx plugins:install someuser/someplugin
429429
```
430430

431-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.38/src/commands/plugins/install.ts)_
431+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.39/src/commands/plugins/install.ts)_
432432

433433
## `csdx plugins:link PATH`
434434

@@ -459,7 +459,7 @@ EXAMPLES
459459
$ csdx plugins:link myplugin
460460
```
461461

462-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.38/src/commands/plugins/link.ts)_
462+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.39/src/commands/plugins/link.ts)_
463463

464464
## `csdx plugins:remove [PLUGIN]`
465465

@@ -500,7 +500,7 @@ FLAGS
500500
--reinstall Reinstall all plugins after uninstalling.
501501
```
502502

503-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.38/src/commands/plugins/reset.ts)_
503+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.39/src/commands/plugins/reset.ts)_
504504

505505
## `csdx plugins:uninstall [PLUGIN]`
506506

@@ -528,7 +528,7 @@ EXAMPLES
528528
$ csdx plugins:uninstall myplugin
529529
```
530530

531-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.38/src/commands/plugins/uninstall.ts)_
531+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.39/src/commands/plugins/uninstall.ts)_
532532

533533
## `csdx plugins:unlink [PLUGIN]`
534534

@@ -572,5 +572,5 @@ DESCRIPTION
572572
Update installed plugins.
573573
```
574574

575-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.38/src/commands/plugins/update.ts)_
575+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.39/src/commands/plugins/update.ts)_
576576
<!-- commandsstop -->
Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,69 @@
1-
{}
1+
{
2+
"ASSET_EXPORT_COMPLETE": "Asset export process completed successfully",
3+
"ASSET_FOLDERS_EXPORT_COMPLETE": "Asset folder structure exported successfully",
4+
"ASSET_METADATA_EXPORT_COMPLETE": "Asset metadata exported successfully",
5+
"ASSET_VERSIONED_METADATA_EXPORT_COMPLETE": "Versioned asset metadata exported successfully",
6+
"ASSET_DOWNLOAD_COMPLETE": "Asset download completed successfully",
7+
"ASSET_DOWNLOAD_SUCCESS": "Asset '%s' (UID: %s) downloaded successfully",
8+
"ASSET_DOWNLOAD_FAILED": "Failed to download asset '%s' (UID: %s)",
9+
"ASSET_WRITE_FAILED": "Failed to write asset file '%s' (UID: %s)",
10+
"ASSET_QUERY_FAILED": "Failed to query asset data from the API",
11+
"ASSET_VERSIONED_QUERY_FAILED": "Failed to query versioned asset data from the API",
12+
"ASSET_COUNT_QUERY_FAILED": "Failed to retrieve total asset count",
13+
14+
"CONTENT_TYPE_EXPORT_COMPLETE": "Content types exported successfully",
15+
"CONTENT_TYPE_NO_TYPES": "No content types found",
16+
"CONTENT_TYPE_EXPORT_FAILED": "Failed to export content types",
17+
"CONTENT_TYPE_NO_TYPES_RETURNED": "API returned no content types for the given query",
18+
19+
"ENVIRONMENT_EXPORT_COMPLETE": "Successfully exported %s environment(s)",
20+
"ENVIRONMENT_EXPORT_SUCCESS": "Environment '%s' exported successfully",
21+
"ENVIRONMENT_NOT_FOUND": "No environments found in the current stack",
22+
23+
"EXTENSION_EXPORT_COMPLETE": "Successfully exported %s extension(s)",
24+
"EXTENSION_EXPORT_SUCCESS": "Extension '%s' exported successfully",
25+
"EXTENSION_NOT_FOUND": "No extensions found in the current stack",
26+
27+
"GLOBAL_FIELDS_EXPORT_COMPLETE": "Successfully exported %s global field(s)",
28+
29+
"LABELS_EXPORT_COMPLETE": "Successfully exported %s label(s)",
30+
"LABEL_EXPORT_SUCCESS": "Label '%s' exported successfully",
31+
"LABELS_NOT_FOUND": "No labels found in the current stack",
32+
33+
"LOCALES_EXPORT_COMPLETE": "Successfully exported %s locale(s) including %s master locale(s)",
34+
35+
"TAXONOMY_EXPORT_COMPLETE": "Successfully exported %s taxonomy entries",
36+
"TAXONOMY_EXPORT_SUCCESS": "Taxonomy '%s' exported successfully",
37+
"TAXONOMY_NOT_FOUND": "No taxonomies found in the current stack",
38+
39+
"WEBHOOK_EXPORT_COMPLETE": "Successfully exported %s webhook(s)",
40+
"WEBHOOK_EXPORT_SUCCESS": "Webhook '%s' exported successfully",
41+
"WEBHOOK_NOT_FOUND": "No webhooks found in the current stack",
42+
43+
"WORKFLOW_EXPORT_COMPLETE": "Successfully exported %s workflow(s)",
44+
"WORKFLOW_EXPORT_SUCCESS": "Workflow '%s' exported successfully",
45+
"WORKFLOW_NOT_FOUND": "No workflows found in the current stack",
46+
47+
"PERSONALIZE_URL_NOT_SET": "Cannot export Personalize project: URL not configured",
48+
"PERSONALIZE_SKIPPING_WITH_MANAGEMENT_TOKEN": "Skipping Personalize project export: Management token not supported",
49+
"PERSONALIZE_MODULE_NOT_IMPLEMENTED": "Module '%s' implementation not found",
50+
"PERSONALIZE_NOT_ENABLED": "Personalize feature is not enabled for this organization",
51+
52+
"MARKETPLACE_APPS_EXPORT_COMPLETE": "Successfully exported %s marketplace app(s)",
53+
"MARKETPLACE_APP_CONFIG_EXPORT": "Exporting configuration for app '%s'",
54+
"MARKETPLACE_APP_CONFIG_SUCCESS": "Successfully exported configuration for app '%s'",
55+
"MARKETPLACE_APP_EXPORT_SUCCESS": "Successfully exported app '%s'",
56+
"MARKETPLACE_APPS_NOT_FOUND": "No marketplace apps found in the current stack",
57+
"MARKETPLACE_APP_CONFIG_EXPORT_FAILED": "Failed to export configuration for app '%s'",
58+
"MARKETPLACE_APP_MANIFEST_EXPORT_FAILED": "Failed to export manifest for app '%s'",
59+
60+
"ENTRIES_EXPORT_COMPLETE": "Successfully exported entries (Content Type: %s, Locale: %s)",
61+
"ENTRIES_EXPORT_SUCCESS": "All entries exported successfully",
62+
"ENTRIES_VERSIONED_EXPORT_SUCCESS": "Successfully exported versioned entry (Content Type: %s, UID: %s, Locale: %s)",
63+
"ENTRIES_EXPORT_VERSIONS_FAILED": "Failed to export versions for content type '%s' (UID: %s)",
64+
65+
"BRANCH_EXPORT_FAILED": "Failed to export contents from branch (UID: %s)",
66+
67+
"ROLES_NO_CUSTOM_ROLES": "No custom roles found in the current stack",
68+
"ROLES_EXPORTING_ROLE": "Exporting role '%s'"
69+
}

packages/contentstack-export/src/commands/cm/stacks/export.ts

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import path from 'path';
21
import { Command } from '@contentstack/cli-command';
32
import {
43
cliux,
@@ -10,10 +9,15 @@ import {
109
FlagInput,
1110
pathValidator,
1211
sanitizePath,
12+
configHandler,
13+
log,
14+
handleAndLogError,
15+
getLogPath
1316
} from '@contentstack/cli-utilities';
17+
1418
import { ModuleExporter } from '../../../export';
15-
import { setupExportConfig, log, formatError, writeExportMetaFile } from '../../../utils';
16-
import { ExportConfig } from '../../../types';
19+
import { Context, ExportConfig } from '../../../types';
20+
import { setupExportConfig, writeExportMetaFile } from '../../../utils';
1721

1822
export default class ExportCommand extends Command {
1923
static description: string = messageHandler.parse('Export content from a stack');
@@ -72,19 +76,22 @@ export default class ExportCommand extends Command {
7276
}),
7377
module: flags.string({
7478
char: 'm',
75-
description: '[optional] Specific module name. If not specified, the export command will export all the modules to the stack. The available modules are assets, content-types, entries, environments, extensions, marketplace-apps, global-fields, labels, locales, webhooks, workflows, custom-roles, and taxonomies.',
79+
description:
80+
'[optional] Specific module name. If not specified, the export command will export all the modules to the stack. The available modules are assets, content-types, entries, environments, extensions, marketplace-apps, global-fields, labels, locales, webhooks, workflows, custom-roles, and taxonomies.',
7681
parse: printFlagDeprecation(['-m'], ['--module']),
7782
}),
7883
'content-types': flags.string({
7984
char: 't',
80-
description: '[optional] The UID of the content type(s) whose content you want to export. In case of multiple content types, specify the IDs separated by spaces.',
85+
description:
86+
'[optional] The UID of the content type(s) whose content you want to export. In case of multiple content types, specify the IDs separated by spaces.',
8187
multiple: true,
8288
parse: printFlagDeprecation(['-t'], ['--content-types']),
8389
}),
8490
branch: flags.string({
8591
char: 'B',
8692
// default: 'main',
87-
description: '[optional] The name of the branch where you want to export your content. If you don\'t mention the branch name, then by default the content will be exported from all the branches of your stack.',
93+
description:
94+
"[optional] The name of the branch where you want to export your content. If you don't mention the branch name, then by default the content will be exported from all the branches of your stack.",
8895
parse: printFlagDeprecation(['-B'], ['--branch']),
8996
}),
9097
'secured-assets': flags.boolean({
@@ -101,30 +108,57 @@ export default class ExportCommand extends Command {
101108

102109
async run(): Promise<void> {
103110
let exportDir: string = pathValidator('logs');
111+
let exportConfig: ExportConfig;
104112
try {
105113
const { flags } = await this.parse(ExportCommand);
106-
let exportConfig = await setupExportConfig(flags);
107-
// Note setting host to create cma client
108-
exportConfig.host = this.cmaHost;
109-
exportConfig.region = this.region;
110-
if(this.developerHubUrl) exportConfig.developerHubBaseUrl = this.developerHubUrl;
111-
if (this.personalizeUrl) exportConfig.modules.personalize.baseURL[exportConfig.region.name] = this.personalizeUrl;
114+
exportConfig = await setupExportConfig(flags);
115+
// Prepare the context object
116+
const context = this.createExportContext(exportConfig.apiKey);
117+
exportConfig.context = context;
118+
119+
// Assign exportConfig variables
120+
this.assignExportConfig(exportConfig);
121+
112122
exportDir = sanitizePath(exportConfig.cliLogsPath || exportConfig.data || exportConfig.exportDir);
113123
const managementAPIClient: ContentstackClient = await managementSDKClient(exportConfig);
114124
const moduleExporter = new ModuleExporter(managementAPIClient, exportConfig);
115125
await moduleExporter.start();
116126
if (!exportConfig.branches?.length) {
117127
writeExportMetaFile(exportConfig);
118128
}
119-
log(exportConfig, `The content of the stack ${exportConfig.apiKey} has been exported successfully!`, 'success');
120-
log(
121-
exportConfig,
122-
`The log has been stored at '${pathValidator(path.join(exportDir, 'logs', 'export'))}'`,
123-
'success',
124-
);
129+
log.success(`The content of the stack ${exportConfig.apiKey} has been exported successfully!`,exportConfig.context)
130+
log.success(`The log has been stored at '${getLogPath()}'`, exportConfig.context)
125131
} catch (error) {
126-
log({ data: exportDir } as ExportConfig, `Failed to export stack content - ${formatError(error)}`, 'error');
127-
log({ data: exportDir } as ExportConfig, `The log has been stored at ${exportDir}`, 'info');
132+
handleAndLogError(error, { ...exportConfig.context });
133+
}
134+
}
135+
136+
// Create export context object
137+
private createExportContext(apiKey: string): Context {
138+
return {
139+
command: this.context.info.command,
140+
module: '',
141+
userId: configHandler.get('userId'),
142+
email: configHandler.get('email'),
143+
sessionId: this.context.sessionId,
144+
clientId: this.context.clientId,
145+
apiKey: apiKey || '',
146+
orgId: configHandler.get('organization_uid') || '',
147+
};
148+
}
149+
150+
// Assign values to exportConfig
151+
private assignExportConfig(exportConfig: ExportConfig): void {
152+
// Note setting host to create cma client
153+
exportConfig.host = this.cmaHost;
154+
exportConfig.region = this.region;
155+
156+
if (this.developerHubUrl) {
157+
exportConfig.developerHubBaseUrl = this.developerHubUrl;
158+
}
159+
160+
if (this.personalizeUrl) {
161+
exportConfig.modules.personalize.baseURL[exportConfig.region.name] = this.personalizeUrl;
128162
}
129163
}
130164
}

packages/contentstack-export/src/export/module-exporter.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as path from 'path';
2-
import { ContentstackClient } from '@contentstack/cli-utilities';
3-
import { setupBranches, setupExportDir, log, formatError, writeExportMetaFile } from '../utils';
2+
import { ContentstackClient, handleAndLogError, messageHandler, log } from '@contentstack/cli-utilities';
3+
import { setupBranches, setupExportDir, writeExportMetaFile } from '../utils';
44
import startModuleExport from './modules';
55
import startJSModuleExport from './modules-js';
66
import { ExportConfig, Modules } from '../types';
@@ -38,19 +38,29 @@ class ModuleExporter {
3838
this.exportConfig.branchName = branch.uid;
3939
this.stackAPIClient.stackHeaders.branch = branch.uid;
4040
this.exportConfig.branchDir = path.join(this.exportConfig.exportDir, branch.uid);
41-
log(this.exportConfig, `Exporting content from branch ${branch.uid}`, 'success');
41+
log.info(`Exporting content from branch ${branch.uid}`, this.exportConfig.context);
4242
writeExportMetaFile(this.exportConfig, this.exportConfig.branchDir);
4343
await this.export();
44-
log(this.exportConfig, `The content of branch ${branch.uid} has been exported successfully!`, 'success');
44+
log.success(
45+
`The content of branch ${branch.uid} has been exported successfully!`,
46+
this.exportConfig.context,
47+
);
4548
} catch (error) {
46-
log(this.exportConfig, formatError(error), 'error');
47-
throw new Error(`Failed to export contents from branch ${branch.uid}`);
49+
handleAndLogError(
50+
error,
51+
{ ...this.exportConfig.context, branch: branch.uid },
52+
messageHandler.parse('FAILED_EXPORT_CONTENT_BRANCH', { branch: branch.uid }),
53+
);
54+
throw new Error(messageHandler.parse('FAILED_EXPORT_CONTENT_BRANCH', { branch: branch.uid }));
4855
}
4956
}
5057
}
5158

5259
async export() {
53-
log(this.exportConfig, `Started to export content, version is ${this.exportConfig.contentVersion}`, 'info');
60+
log.info(
61+
`Started to export content, version is ${this.exportConfig.contentVersion}`,
62+
this.exportConfig.context,
63+
);
5464
// checks for single module or all modules
5565
if (this.exportConfig.singleModuleExport) {
5666
return this.exportSingleModule(this.exportConfig.moduleName);
@@ -59,7 +69,7 @@ class ModuleExporter {
5969
}
6070

6171
async exportByModuleByName(moduleName: Modules) {
62-
log(this.exportConfig, `Starting export of ${moduleName} module`, 'info');
72+
log.info(`Exporting module: ${moduleName}`, this.exportConfig.context);
6373
// export the modules by name
6474
// calls the module runner which inturn calls the module itself
6575
let exportedModuleResponse;

0 commit comments

Comments
 (0)