@contentstack/cli-cm-export 2.0.0-beta.1 → 2.0.0-beta.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +11 -65
- package/lib/commands/cm/stacks/export.d.ts +0 -1
- package/lib/commands/cm/stacks/export.js +12 -37
- package/lib/config/index.js +7 -0
- package/lib/constants/index.d.ts +57 -0
- package/lib/constants/index.js +59 -0
- package/lib/export/module-exporter.js +3 -2
- package/lib/export/modules/assets.js +5 -5
- package/lib/export/modules/base-class.d.ts +17 -0
- package/lib/export/modules/base-class.js +29 -1
- package/lib/export/modules/composable-studio.d.ts +15 -0
- package/lib/export/modules/composable-studio.js +87 -0
- package/lib/export/modules/content-types.js +6 -8
- package/lib/export/modules/custom-roles.js +2 -2
- package/lib/export/modules/entries.d.ts +1 -1
- package/lib/export/modules/entries.js +18 -19
- package/lib/export/modules/environments.js +2 -3
- package/lib/export/modules/extensions.js +2 -3
- package/lib/export/modules/global-fields.js +8 -5
- package/lib/export/modules/labels.js +2 -3
- package/lib/export/modules/locales.js +2 -3
- package/lib/export/modules/marketplace-apps.js +36 -25
- package/lib/export/modules/personalize.js +1 -2
- package/lib/export/modules/stack.js +29 -29
- package/lib/export/modules/taxonomies.d.ts +52 -8
- package/lib/export/modules/taxonomies.js +278 -104
- package/lib/export/modules/webhooks.js +2 -3
- package/lib/export/modules/workflows.js +3 -4
- package/lib/types/default-config.d.ts +6 -0
- package/lib/types/index.d.ts +27 -2
- package/lib/utils/basic-login.d.ts +1 -1
- package/lib/utils/basic-login.js +5 -5
- package/lib/utils/common-helper.d.ts +1 -1
- package/lib/utils/common-helper.js +4 -4
- package/lib/utils/export-config-handler.js +10 -13
- package/lib/utils/file-helper.js +1 -1
- package/lib/utils/logger.d.ts +1 -1
- package/lib/utils/logger.js +2 -2
- package/lib/utils/marketplace-app-helper.js +2 -4
- package/messages/index.json +73 -67
- package/oclif.manifest.json +4 -42
- package/package.json +20 -17
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -48,7 +48,7 @@ $ npm install -g @contentstack/cli-cm-export
|
|
|
48
48
|
$ csdx COMMAND
|
|
49
49
|
running command...
|
|
50
50
|
$ csdx (--version)
|
|
51
|
-
@contentstack/cli-cm-export/2.0.0-beta.
|
|
51
|
+
@contentstack/cli-cm-export/2.0.0-beta.11 linux-x64 node-v22.22.0
|
|
52
52
|
$ csdx --help [COMMAND]
|
|
53
53
|
USAGE
|
|
54
54
|
$ csdx COMMAND
|
|
@@ -59,93 +59,39 @@ USAGE
|
|
|
59
59
|
# Commands
|
|
60
60
|
|
|
61
61
|
<!-- commands -->
|
|
62
|
-
* [`csdx cm:stacks:export [
|
|
63
|
-
* [`csdx cm:stacks:export [-c <value>] [-k <value>] [-d <value>] [-a <value>] [--module <value>] [--content-types <value>] [--branch <value>] [--secured-assets]`](#csdx-cmstacksexport--c-value--k-value--d-value--a-value---module-value---content-types-value---branch-value---secured-assets)
|
|
62
|
+
* [`csdx cm:stacks:export [--config <value>] [--stack-api-key <value>] [--data-dir <value>] [--alias <value>] [--module <value>] [--content-types <value>] [--branch <value>] [--secured-assets]`](#csdx-cmstacksexport---config-value---stack-api-key-value---data-dir-value---alias-value---module-value---content-types-value---branch-value---secured-assets)
|
|
64
63
|
|
|
65
|
-
## `csdx cm:stacks:export [
|
|
64
|
+
## `csdx cm:stacks:export [--config <value>] [--stack-api-key <value>] [--data-dir <value>] [--alias <value>] [--module <value>] [--content-types <value>] [--branch <value>] [--secured-assets]`
|
|
66
65
|
|
|
67
66
|
Export content from a stack
|
|
68
67
|
|
|
69
68
|
```
|
|
70
69
|
USAGE
|
|
71
|
-
$ csdx cm:
|
|
72
|
-
[--content-types <value>] [--branch <value>] [--secured-assets]
|
|
70
|
+
$ csdx cm:stacks:export [--config <value>] [--stack-api-key <value>] [--data-dir <value>] [--alias <value>]
|
|
71
|
+
[--module <value>] [--content-types <value>] [--branch <value>] [--secured-assets]
|
|
73
72
|
|
|
74
73
|
FLAGS
|
|
75
|
-
-B, --branch=<value> [optional] The name of the branch where you want to export your content. If you don't
|
|
76
|
-
mention the branch name, then by default the content will be exported from all the
|
|
77
|
-
branches of your stack.
|
|
78
74
|
-a, --alias=<value> The management token alias of the source stack from which you will export content.
|
|
79
75
|
-c, --config=<value> [optional] Path of the config
|
|
80
76
|
-d, --data-dir=<value> The path or the location in your file system to store the exported content. For e.g.,
|
|
81
77
|
./content
|
|
82
78
|
-k, --stack-api-key=<value> API Key of the source stack
|
|
83
|
-
-m, --module=<value> [optional] Specific module name. If not specified, the export command will export all
|
|
84
|
-
the modules to the stack. The available modules are assets, content-types, entries,
|
|
85
|
-
environments, extensions, marketplace-apps, global-fields, labels, locales, webhooks,
|
|
86
|
-
workflows, custom-roles, and taxonomies.
|
|
87
|
-
-t, --content-types=<value>... [optional] The UID of the content type(s) whose content you want to export. In case
|
|
88
|
-
of multiple content types, specify the IDs separated by spaces.
|
|
89
79
|
-y, --yes [optional] Force override all Marketplace prompts.
|
|
90
|
-
--branch
|
|
91
|
-
--secured-assets [optional] Use this flag for assets that are secured.
|
|
92
|
-
|
|
93
|
-
DESCRIPTION
|
|
94
|
-
Export content from a stack
|
|
95
|
-
|
|
96
|
-
ALIASES
|
|
97
|
-
$ csdx cm:export
|
|
98
|
-
|
|
99
|
-
EXAMPLES
|
|
100
|
-
$ csdx cm:stacks:export --stack-api-key <stack_api_key> --data-dir <path/of/export/destination/dir>
|
|
101
|
-
|
|
102
|
-
$ csdx cm:stacks:export --config <path/to/config/dir>
|
|
103
|
-
|
|
104
|
-
$ csdx cm:stacks:export --alias <management_token_alias>
|
|
105
|
-
|
|
106
|
-
$ csdx cm:stacks:export --alias <management_token_alias> --data-dir <path/to/export/destination/dir>
|
|
107
|
-
|
|
108
|
-
$ csdx cm:stacks:export --alias <management_token_alias> --config <path/to/config/file>
|
|
109
|
-
|
|
110
|
-
$ csdx cm:stacks:export --module <single module name>
|
|
111
|
-
|
|
112
|
-
$ csdx cm:stacks:export --branch [optional] branch name
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
## `csdx cm:stacks:export [-c <value>] [-k <value>] [-d <value>] [-a <value>] [--module <value>] [--content-types <value>] [--branch <value>] [--secured-assets]`
|
|
116
|
-
|
|
117
|
-
Export content from a stack
|
|
118
|
-
|
|
119
|
-
```
|
|
120
|
-
USAGE
|
|
121
|
-
$ csdx cm:stacks:export [-c <value>] [-k <value>] [-d <value>] [-a <value>] [--module <value>] [--content-types
|
|
122
|
-
<value>] [--branch <value>] [--secured-assets]
|
|
123
|
-
|
|
124
|
-
FLAGS
|
|
125
|
-
-B, --branch=<value> [optional] The name of the branch where you want to export your content. If you don't
|
|
80
|
+
--branch=<value> [optional] The name of the branch where you want to export your content. If you don't
|
|
126
81
|
mention the branch name, then by default the content will be exported from all the
|
|
127
82
|
branches of your stack.
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
-k, --stack-api-key=<value> API Key of the source stack
|
|
133
|
-
-m, --module=<value> [optional] Specific module name. If not specified, the export command will export all
|
|
83
|
+
--branch-alias=<value> (Optional) The alias of the branch from which you want to export content.
|
|
84
|
+
--content-types=<value>... [optional] The UID of the content type(s) whose content you want to export. In case
|
|
85
|
+
of multiple content types, specify the IDs separated by spaces.
|
|
86
|
+
--module=<value> [optional] Specific module name. If not specified, the export command will export all
|
|
134
87
|
the modules to the stack. The available modules are assets, content-types, entries,
|
|
135
88
|
environments, extensions, marketplace-apps, global-fields, labels, locales, webhooks,
|
|
136
|
-
workflows, custom-roles, and
|
|
137
|
-
-t, --content-types=<value>... [optional] The UID of the content type(s) whose content you want to export. In case
|
|
138
|
-
of multiple content types, specify the IDs separated by spaces.
|
|
139
|
-
-y, --yes [optional] Force override all Marketplace prompts.
|
|
140
|
-
--branch-alias=<value> (Optional) The alias of the branch from which you want to export content.
|
|
89
|
+
workflows, custom-roles, taxonomies, and studio.
|
|
141
90
|
--secured-assets [optional] Use this flag for assets that are secured.
|
|
142
91
|
|
|
143
92
|
DESCRIPTION
|
|
144
93
|
Export content from a stack
|
|
145
94
|
|
|
146
|
-
ALIASES
|
|
147
|
-
$ csdx cm:export
|
|
148
|
-
|
|
149
95
|
EXAMPLES
|
|
150
96
|
$ csdx cm:stacks:export --stack-api-key <stack_api_key> --data-dir <path/of/export/destination/dir>
|
|
151
97
|
|
|
@@ -14,21 +14,21 @@ class ExportCommand extends cli_command_1.Command {
|
|
|
14
14
|
// Prepare the context object
|
|
15
15
|
const context = this.createExportContext(exportConfig.apiKey, exportConfig.authenticationMethod);
|
|
16
16
|
exportConfig.context = Object.assign({}, context);
|
|
17
|
-
//log.info(`Using Cli Version: ${this.context?.cliVersion}`, exportConfig.context);
|
|
18
17
|
// Assign exportConfig variables
|
|
19
18
|
this.assignExportConfig(exportConfig);
|
|
20
|
-
exportDir = (0, cli_utilities_1.sanitizePath)(exportConfig.cliLogsPath || exportConfig.
|
|
19
|
+
exportDir = (0, cli_utilities_1.sanitizePath)(exportConfig.cliLogsPath || exportConfig.exportDir);
|
|
21
20
|
const managementAPIClient = await (0, cli_utilities_1.managementSDKClient)(exportConfig);
|
|
22
21
|
const moduleExporter = new export_1.ModuleExporter(managementAPIClient, exportConfig);
|
|
23
22
|
await moduleExporter.start();
|
|
24
|
-
|
|
23
|
+
const sessionLogPath = (0, cli_utilities_1.getSessionLogPath)();
|
|
24
|
+
cli_utilities_1.log.success(`The content of the stack ${exportConfig.apiKey} has been exported successfully!`);
|
|
25
25
|
cli_utilities_1.log.info(`The exported content has been stored at '${exportDir}'`, exportConfig.context);
|
|
26
|
-
cli_utilities_1.log.success(`The log has been stored at '${
|
|
26
|
+
cli_utilities_1.log.success(`The log has been stored at '${sessionLogPath}'`, exportConfig.context);
|
|
27
27
|
// Print comprehensive summary at the end
|
|
28
28
|
if (!exportConfig.branches)
|
|
29
29
|
cli_utilities_1.CLIProgressManager.printGlobalSummary();
|
|
30
30
|
if (!((_a = cli_utilities_1.configHandler.get('log')) === null || _a === void 0 ? void 0 : _a.showConsoleLogs)) {
|
|
31
|
-
cli_utilities_1.cliux.print(`The log has been stored at '${
|
|
31
|
+
cli_utilities_1.cliux.print(`The log has been stored at '${sessionLogPath}'`, { color: 'green' });
|
|
32
32
|
}
|
|
33
33
|
// Clear progress module setting now that export is complete
|
|
34
34
|
(0, cli_utilities_1.clearProgressModuleSetting)();
|
|
@@ -37,9 +37,10 @@ class ExportCommand extends cli_command_1.Command {
|
|
|
37
37
|
// Clear progress module setting even on error
|
|
38
38
|
(0, cli_utilities_1.clearProgressModuleSetting)();
|
|
39
39
|
(0, cli_utilities_1.handleAndLogError)(error);
|
|
40
|
+
const sessionLogPath = (0, cli_utilities_1.getSessionLogPath)();
|
|
40
41
|
if (!((_b = cli_utilities_1.configHandler.get('log')) === null || _b === void 0 ? void 0 : _b.showConsoleLogs)) {
|
|
41
42
|
cli_utilities_1.cliux.print(`Error: ${error}`, { color: 'red' });
|
|
42
|
-
cli_utilities_1.cliux.print(`The log has been stored at '${
|
|
43
|
+
cli_utilities_1.cliux.print(`The log has been stored at '${sessionLogPath}'`, { color: 'green' });
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
46
|
}
|
|
@@ -67,6 +68,9 @@ class ExportCommand extends cli_command_1.Command {
|
|
|
67
68
|
if (this.personalizeUrl) {
|
|
68
69
|
exportConfig.modules.personalize.baseURL[exportConfig.region.name] = this.personalizeUrl;
|
|
69
70
|
}
|
|
71
|
+
if (this.composableStudioUrl) {
|
|
72
|
+
exportConfig.modules['composable-studio'].apiBaseUrl = this.composableStudioUrl;
|
|
73
|
+
}
|
|
70
74
|
}
|
|
71
75
|
}
|
|
72
76
|
exports.default = ExportCommand;
|
|
@@ -80,27 +84,16 @@ ExportCommand.examples = [
|
|
|
80
84
|
'csdx cm:stacks:export --module <single module name>',
|
|
81
85
|
'csdx cm:stacks:export --branch [optional] branch name',
|
|
82
86
|
];
|
|
83
|
-
ExportCommand.usage = 'cm:stacks:export [
|
|
87
|
+
ExportCommand.usage = 'cm:stacks:export [--config <value>] [--stack-api-key <value>] [--data-dir <value>] [--alias <value>] [--module <value>] [--content-types <value>] [--branch <value>] [--secured-assets]';
|
|
84
88
|
ExportCommand.flags = {
|
|
85
89
|
config: cli_utilities_1.flags.string({
|
|
86
90
|
char: 'c',
|
|
87
91
|
description: '[optional] Path of the config',
|
|
88
92
|
}),
|
|
89
|
-
'stack-uid': cli_utilities_1.flags.string({
|
|
90
|
-
char: 's',
|
|
91
|
-
description: 'API key of the source stack',
|
|
92
|
-
hidden: true,
|
|
93
|
-
parse: (0, cli_utilities_1.printFlagDeprecation)(['-s', '--stack-uid'], ['-k', '--stack-api-key']),
|
|
94
|
-
}),
|
|
95
93
|
'stack-api-key': cli_utilities_1.flags.string({
|
|
96
94
|
char: 'k',
|
|
97
95
|
description: 'API Key of the source stack',
|
|
98
96
|
}),
|
|
99
|
-
data: cli_utilities_1.flags.string({
|
|
100
|
-
description: 'path or location to store the data',
|
|
101
|
-
hidden: true,
|
|
102
|
-
parse: (0, cli_utilities_1.printFlagDeprecation)(['--data'], ['--data-dir']),
|
|
103
|
-
}),
|
|
104
97
|
'data-dir': cli_utilities_1.flags.string({
|
|
105
98
|
char: 'd',
|
|
106
99
|
description: 'The path or the location in your file system to store the exported content. For e.g., ./content',
|
|
@@ -109,33 +102,16 @@ ExportCommand.flags = {
|
|
|
109
102
|
char: 'a',
|
|
110
103
|
description: 'The management token alias of the source stack from which you will export content.',
|
|
111
104
|
}),
|
|
112
|
-
'management-token-alias': cli_utilities_1.flags.string({
|
|
113
|
-
description: 'alias of the management token',
|
|
114
|
-
hidden: true,
|
|
115
|
-
parse: (0, cli_utilities_1.printFlagDeprecation)(['--management-token-alias'], ['-a', '--alias']),
|
|
116
|
-
}),
|
|
117
|
-
'auth-token': cli_utilities_1.flags.boolean({
|
|
118
|
-
char: 'A',
|
|
119
|
-
description: 'to use auth token',
|
|
120
|
-
hidden: true,
|
|
121
|
-
parse: (0, cli_utilities_1.printFlagDeprecation)(['-A', '--auth-token']),
|
|
122
|
-
}),
|
|
123
105
|
module: cli_utilities_1.flags.string({
|
|
124
|
-
|
|
125
|
-
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.',
|
|
126
|
-
parse: (0, cli_utilities_1.printFlagDeprecation)(['-m'], ['--module']),
|
|
106
|
+
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, taxonomies, and studio.',
|
|
127
107
|
}),
|
|
128
108
|
'content-types': cli_utilities_1.flags.string({
|
|
129
|
-
char: 't',
|
|
130
109
|
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.',
|
|
131
110
|
multiple: true,
|
|
132
|
-
parse: (0, cli_utilities_1.printFlagDeprecation)(['-t'], ['--content-types']),
|
|
133
111
|
}),
|
|
134
112
|
branch: cli_utilities_1.flags.string({
|
|
135
|
-
char: 'B',
|
|
136
113
|
// default: 'main',
|
|
137
114
|
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.",
|
|
138
|
-
parse: (0, cli_utilities_1.printFlagDeprecation)(['-B'], ['--branch']),
|
|
139
115
|
exclusive: ['branch-alias'],
|
|
140
116
|
}),
|
|
141
117
|
'branch-alias': cli_utilities_1.flags.string({
|
|
@@ -155,4 +131,3 @@ ExportCommand.flags = {
|
|
|
155
131
|
hidden: true,
|
|
156
132
|
}),
|
|
157
133
|
};
|
|
158
|
-
ExportCommand.aliases = ['cm:export'];
|
package/lib/config/index.js
CHANGED
|
@@ -39,6 +39,7 @@ const config = {
|
|
|
39
39
|
'entries',
|
|
40
40
|
'labels',
|
|
41
41
|
'marketplace-apps',
|
|
42
|
+
'composable-studio',
|
|
42
43
|
],
|
|
43
44
|
locales: {
|
|
44
45
|
dirName: 'locales',
|
|
@@ -212,6 +213,12 @@ const config = {
|
|
|
212
213
|
dirName: 'marketplace_apps',
|
|
213
214
|
fileName: 'marketplace_apps.json',
|
|
214
215
|
},
|
|
216
|
+
'composable-studio': {
|
|
217
|
+
dirName: 'composable_studio',
|
|
218
|
+
fileName: 'composable_studio.json',
|
|
219
|
+
apiBaseUrl: 'https://composable-studio-api.contentstack.com',
|
|
220
|
+
apiVersion: 'v1',
|
|
221
|
+
},
|
|
215
222
|
taxonomies: {
|
|
216
223
|
dirName: 'taxonomies',
|
|
217
224
|
fileName: 'taxonomies.json',
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export declare const PATH_CONSTANTS: {
|
|
2
|
+
/** Root mapper directory (contains module-specific mapper subdirs) */
|
|
3
|
+
readonly MAPPER: "mapper";
|
|
4
|
+
/** Common mapper file names */
|
|
5
|
+
readonly FILES: {
|
|
6
|
+
readonly SUCCESS: "success.json";
|
|
7
|
+
readonly FAILS: "fails.json";
|
|
8
|
+
readonly UID_MAPPING: "uid-mapping.json";
|
|
9
|
+
readonly URL_MAPPING: "url-mapping.json";
|
|
10
|
+
readonly UID_MAPPER: "uid-mapper.json";
|
|
11
|
+
readonly SCHEMA: "schema.json";
|
|
12
|
+
readonly SETTINGS: "settings.json";
|
|
13
|
+
readonly MODIFIED_SCHEMAS: "modified-schemas.json";
|
|
14
|
+
readonly UNIQUE_MAPPING: "unique-mapping.json";
|
|
15
|
+
readonly TAXONOMIES: "taxonomies.json";
|
|
16
|
+
readonly ENVIRONMENTS: "environments.json";
|
|
17
|
+
readonly PENDING_EXTENSIONS: "pending_extensions.js";
|
|
18
|
+
readonly PENDING_GLOBAL_FIELDS: "pending_global_fields.js";
|
|
19
|
+
readonly INDEX: "index.json";
|
|
20
|
+
readonly FOLDER_MAPPING: "folder-mapping.json";
|
|
21
|
+
readonly VERSIONED_ASSETS: "versioned-assets.json";
|
|
22
|
+
};
|
|
23
|
+
/** Module subdirectory names within mapper */
|
|
24
|
+
readonly MAPPER_MODULES: {
|
|
25
|
+
readonly ASSETS: "assets";
|
|
26
|
+
readonly ENTRIES: "entries";
|
|
27
|
+
readonly CONTENT_TYPES: "content_types";
|
|
28
|
+
readonly TAXONOMIES: "taxonomies";
|
|
29
|
+
readonly TAXONOMY_TERMS: "terms";
|
|
30
|
+
readonly GLOBAL_FIELDS: "global_fields";
|
|
31
|
+
readonly EXTENSIONS: "extensions";
|
|
32
|
+
readonly WORKFLOWS: "workflows";
|
|
33
|
+
readonly WEBHOOKS: "webhooks";
|
|
34
|
+
readonly LABELS: "labels";
|
|
35
|
+
readonly ENVIRONMENTS: "environments";
|
|
36
|
+
readonly MARKETPLACE_APPS: "marketplace_apps";
|
|
37
|
+
readonly CUSTOM_ROLES: "custom-roles";
|
|
38
|
+
readonly LANGUAGES: "languages";
|
|
39
|
+
};
|
|
40
|
+
/** Content directory names (used in both import and export) */
|
|
41
|
+
readonly CONTENT_DIRS: {
|
|
42
|
+
readonly ASSETS: "assets";
|
|
43
|
+
readonly ENTRIES: "entries";
|
|
44
|
+
readonly CONTENT_TYPES: "content_types";
|
|
45
|
+
readonly TAXONOMIES: "taxonomies";
|
|
46
|
+
readonly GLOBAL_FIELDS: "global_fields";
|
|
47
|
+
readonly EXTENSIONS: "extensions";
|
|
48
|
+
readonly WEBHOOKS: "webhooks";
|
|
49
|
+
readonly WORKFLOWS: "workflows";
|
|
50
|
+
readonly LABELS: "labels";
|
|
51
|
+
readonly ENVIRONMENTS: "environments";
|
|
52
|
+
readonly STACK: "stack";
|
|
53
|
+
readonly LOCALES: "locales";
|
|
54
|
+
readonly MARKETPLACE_APPS: "marketplace_apps";
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
export type PathConstants = typeof PATH_CONSTANTS;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PATH_CONSTANTS = void 0;
|
|
4
|
+
exports.PATH_CONSTANTS = {
|
|
5
|
+
/** Root mapper directory (contains module-specific mapper subdirs) */
|
|
6
|
+
MAPPER: 'mapper',
|
|
7
|
+
/** Common mapper file names */
|
|
8
|
+
FILES: {
|
|
9
|
+
SUCCESS: 'success.json',
|
|
10
|
+
FAILS: 'fails.json',
|
|
11
|
+
UID_MAPPING: 'uid-mapping.json',
|
|
12
|
+
URL_MAPPING: 'url-mapping.json',
|
|
13
|
+
UID_MAPPER: 'uid-mapper.json',
|
|
14
|
+
SCHEMA: 'schema.json',
|
|
15
|
+
SETTINGS: 'settings.json',
|
|
16
|
+
MODIFIED_SCHEMAS: 'modified-schemas.json',
|
|
17
|
+
UNIQUE_MAPPING: 'unique-mapping.json',
|
|
18
|
+
TAXONOMIES: 'taxonomies.json',
|
|
19
|
+
ENVIRONMENTS: 'environments.json',
|
|
20
|
+
PENDING_EXTENSIONS: 'pending_extensions.js',
|
|
21
|
+
PENDING_GLOBAL_FIELDS: 'pending_global_fields.js',
|
|
22
|
+
INDEX: 'index.json',
|
|
23
|
+
FOLDER_MAPPING: 'folder-mapping.json',
|
|
24
|
+
VERSIONED_ASSETS: 'versioned-assets.json',
|
|
25
|
+
},
|
|
26
|
+
/** Module subdirectory names within mapper */
|
|
27
|
+
MAPPER_MODULES: {
|
|
28
|
+
ASSETS: 'assets',
|
|
29
|
+
ENTRIES: 'entries',
|
|
30
|
+
CONTENT_TYPES: 'content_types',
|
|
31
|
+
TAXONOMIES: 'taxonomies',
|
|
32
|
+
TAXONOMY_TERMS: 'terms',
|
|
33
|
+
GLOBAL_FIELDS: 'global_fields',
|
|
34
|
+
EXTENSIONS: 'extensions',
|
|
35
|
+
WORKFLOWS: 'workflows',
|
|
36
|
+
WEBHOOKS: 'webhooks',
|
|
37
|
+
LABELS: 'labels',
|
|
38
|
+
ENVIRONMENTS: 'environments',
|
|
39
|
+
MARKETPLACE_APPS: 'marketplace_apps',
|
|
40
|
+
CUSTOM_ROLES: 'custom-roles',
|
|
41
|
+
LANGUAGES: 'languages',
|
|
42
|
+
},
|
|
43
|
+
/** Content directory names (used in both import and export) */
|
|
44
|
+
CONTENT_DIRS: {
|
|
45
|
+
ASSETS: 'assets',
|
|
46
|
+
ENTRIES: 'entries',
|
|
47
|
+
CONTENT_TYPES: 'content_types',
|
|
48
|
+
TAXONOMIES: 'taxonomies',
|
|
49
|
+
GLOBAL_FIELDS: 'global_fields',
|
|
50
|
+
EXTENSIONS: 'extensions',
|
|
51
|
+
WEBHOOKS: 'webhooks',
|
|
52
|
+
WORKFLOWS: 'workflows',
|
|
53
|
+
LABELS: 'labels',
|
|
54
|
+
ENVIRONMENTS: 'environments',
|
|
55
|
+
STACK: 'stack',
|
|
56
|
+
LOCALES: 'locales',
|
|
57
|
+
MARKETPLACE_APPS: 'marketplace_apps',
|
|
58
|
+
},
|
|
59
|
+
};
|
|
@@ -77,7 +77,7 @@ class ModuleExporter {
|
|
|
77
77
|
return this.exportAllModules();
|
|
78
78
|
}
|
|
79
79
|
async exportByModuleByName(moduleName) {
|
|
80
|
-
cli_utilities_1.log.info(`Exporting module: ${moduleName}
|
|
80
|
+
cli_utilities_1.log.info(`Exporting module: '${moduleName}'...`, this.exportConfig.context);
|
|
81
81
|
// export the modules by name
|
|
82
82
|
// calls the module runner which inturn calls the module itself
|
|
83
83
|
await (0, modules_1.default)({
|
|
@@ -93,7 +93,8 @@ class ModuleExporter {
|
|
|
93
93
|
exportModules.push('stack');
|
|
94
94
|
}
|
|
95
95
|
if (!this.exportConfig.skipDependencies) {
|
|
96
|
-
const
|
|
96
|
+
const moduleConfig = this.exportConfig.modules[moduleName];
|
|
97
|
+
const dependencies = (moduleConfig === null || moduleConfig === void 0 ? void 0 : moduleConfig.dependencies) || [];
|
|
97
98
|
if (dependencies.length > 0) {
|
|
98
99
|
exportModules = exportModules.concat(dependencies);
|
|
99
100
|
}
|
|
@@ -16,6 +16,7 @@ const progress_stream_1 = tslib_1.__importDefault(require("progress-stream"));
|
|
|
16
16
|
const node_fs_1 = require("node:fs");
|
|
17
17
|
const node_path_1 = require("node:path");
|
|
18
18
|
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
19
|
+
const constants_1 = require("../../constants");
|
|
19
20
|
const config_1 = tslib_1.__importDefault(require("../../config"));
|
|
20
21
|
const base_class_1 = tslib_1.__importDefault(require("./base-class"));
|
|
21
22
|
const utils_1 = require("../../utils");
|
|
@@ -36,7 +37,7 @@ class ExportAssets extends base_class_1.default {
|
|
|
36
37
|
};
|
|
37
38
|
}
|
|
38
39
|
async start() {
|
|
39
|
-
this.assetsRootPath = (0, node_path_1.resolve)(this.exportConfig.
|
|
40
|
+
this.assetsRootPath = (0, node_path_1.resolve)(this.exportConfig.exportDir, this.exportConfig.branchName || '', this.assetConfig.dirName);
|
|
40
41
|
cli_utilities_1.log.debug(`Assets root path resolved to: ${this.assetsRootPath}`, this.exportConfig.context);
|
|
41
42
|
cli_utilities_1.log.debug('Fetching assets and folders count...', this.exportConfig.context);
|
|
42
43
|
// NOTE step 1: Get assets and it's folder count in parallel
|
|
@@ -83,8 +84,7 @@ class ExportAssets extends base_class_1.default {
|
|
|
83
84
|
await this.downloadAssets();
|
|
84
85
|
progress.completeProcess(utils_1.PROCESS_NAMES.ASSET_DOWNLOADS, true);
|
|
85
86
|
}
|
|
86
|
-
this.
|
|
87
|
-
cli_utilities_1.log.success(cli_utilities_1.messageHandler.parse('ASSET_EXPORT_COMPLETE'), this.exportConfig.context);
|
|
87
|
+
this.completeProgressWithMessage();
|
|
88
88
|
}
|
|
89
89
|
catch (error) {
|
|
90
90
|
this.completeProgress(false, (error === null || error === void 0 ? void 0 : error.message) || 'Asset export failed');
|
|
@@ -171,7 +171,7 @@ class ExportAssets extends base_class_1.default {
|
|
|
171
171
|
fs = new cli_utilities_1.FsUtility({
|
|
172
172
|
metaHandler,
|
|
173
173
|
moduleName: 'assets',
|
|
174
|
-
indexFileName:
|
|
174
|
+
indexFileName: this.assetConfig.fileName,
|
|
175
175
|
basePath: this.assetsRootPath,
|
|
176
176
|
chunkFileSize: this.assetConfig.chunkFileSize,
|
|
177
177
|
metaPickKeys: (0, merge_1.default)(['uid', 'url', 'filename', 'parent_uid'], this.assetConfig.assetsMetaKeys),
|
|
@@ -236,7 +236,7 @@ class ExportAssets extends base_class_1.default {
|
|
|
236
236
|
if (!fs && !(0, isEmpty_1.default)(response)) {
|
|
237
237
|
fs = new cli_utilities_1.FsUtility({
|
|
238
238
|
moduleName: 'assets',
|
|
239
|
-
indexFileName:
|
|
239
|
+
indexFileName: constants_1.PATH_CONSTANTS.FILES.VERSIONED_ASSETS,
|
|
240
240
|
chunkFileSize: this.assetConfig.chunkFileSize,
|
|
241
241
|
basePath: (0, node_path_1.resolve)(this.assetsRootPath, 'versions'),
|
|
242
242
|
metaPickKeys: (0, merge_1.default)(['uid', 'url', 'filename', '_version', 'parent_uid'], this.assetConfig.assetsMetaKeys),
|
|
@@ -9,6 +9,12 @@ export type ApiOptions = {
|
|
|
9
9
|
reject: (error: any) => void;
|
|
10
10
|
additionalInfo?: Record<any, any>;
|
|
11
11
|
};
|
|
12
|
+
export type CompleteProgressOptions = {
|
|
13
|
+
moduleName?: string;
|
|
14
|
+
customSuccessMessage?: string;
|
|
15
|
+
customWarningMessage?: string;
|
|
16
|
+
context?: Record<string, any>;
|
|
17
|
+
};
|
|
12
18
|
export type EnvType = {
|
|
13
19
|
module: string;
|
|
14
20
|
totalCount: number;
|
|
@@ -44,6 +50,17 @@ export default abstract class BaseClass {
|
|
|
44
50
|
* Complete progress manager
|
|
45
51
|
*/
|
|
46
52
|
protected completeProgress(success?: boolean, error?: string): void;
|
|
53
|
+
/**
|
|
54
|
+
* Complete progress and log success/warning message based on errors
|
|
55
|
+
* Checks the progress manager's failure count to determine if errors occurred
|
|
56
|
+
* @param options - Options object containing:
|
|
57
|
+
* - moduleName: The module name to generate the message (e.g., 'Assets', 'Entries')
|
|
58
|
+
* If not provided, uses this.currentModuleName
|
|
59
|
+
* - customSuccessMessage: Optional custom success message. If not provided, generates: "{moduleName} have been exported successfully!"
|
|
60
|
+
* - customWarningMessage: Optional custom warning message. If not provided, generates: "{moduleName} have been exported with some errors. Please check the logs at: {sessionLogPath}"
|
|
61
|
+
* - context: Optional context for logging
|
|
62
|
+
*/
|
|
63
|
+
protected completeProgressWithMessage(options?: CompleteProgressOptions): void;
|
|
47
64
|
protected withLoadingSpinner<T>(message: string, action: () => Promise<T>): Promise<T>;
|
|
48
65
|
get stack(): any;
|
|
49
66
|
delay(ms: number): Promise<void>;
|
|
@@ -49,6 +49,34 @@ class BaseClass {
|
|
|
49
49
|
(_a = this.progressManager) === null || _a === void 0 ? void 0 : _a.complete(success, error);
|
|
50
50
|
this.progressManager = null;
|
|
51
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Complete progress and log success/warning message based on errors
|
|
54
|
+
* Checks the progress manager's failure count to determine if errors occurred
|
|
55
|
+
* @param options - Options object containing:
|
|
56
|
+
* - moduleName: The module name to generate the message (e.g., 'Assets', 'Entries')
|
|
57
|
+
* If not provided, uses this.currentModuleName
|
|
58
|
+
* - customSuccessMessage: Optional custom success message. If not provided, generates: "{moduleName} have been exported successfully!"
|
|
59
|
+
* - customWarningMessage: Optional custom warning message. If not provided, generates: "{moduleName} have been exported with some errors. Please check the logs at: {sessionLogPath}"
|
|
60
|
+
* - context: Optional context for logging
|
|
61
|
+
*/
|
|
62
|
+
completeProgressWithMessage(options) {
|
|
63
|
+
var _a, _b;
|
|
64
|
+
const logContext = (options === null || options === void 0 ? void 0 : options.context) || ((_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.context) || {};
|
|
65
|
+
const failureCount = ((_b = this.progressManager) === null || _b === void 0 ? void 0 : _b.getFailureCount()) || 0;
|
|
66
|
+
const hasErrors = failureCount > 0;
|
|
67
|
+
const name = (options === null || options === void 0 ? void 0 : options.moduleName) || this.currentModuleName || 'Module';
|
|
68
|
+
// Generate default messages if not provided
|
|
69
|
+
const successMessage = (options === null || options === void 0 ? void 0 : options.customSuccessMessage) || `${name} have been exported successfully!`;
|
|
70
|
+
const sessionLogPath = (0, cli_utilities_1.getSessionLogPath)();
|
|
71
|
+
const warningMessage = (options === null || options === void 0 ? void 0 : options.customWarningMessage) || `${name} have been exported with some errors. Please check the logs at: ${sessionLogPath}`;
|
|
72
|
+
this.completeProgress(true);
|
|
73
|
+
if (hasErrors) {
|
|
74
|
+
cli_utilities_1.log.warn(warningMessage, logContext);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
cli_utilities_1.log.success(successMessage, logContext);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
52
80
|
async withLoadingSpinner(message, action) {
|
|
53
81
|
var _a;
|
|
54
82
|
const logConfig = cli_utilities_1.configHandler.get('log') || {};
|
|
@@ -158,7 +186,7 @@ class BaseClass {
|
|
|
158
186
|
case 'export-taxonomy':
|
|
159
187
|
return this.stack
|
|
160
188
|
.taxonomy(uid)
|
|
161
|
-
.export()
|
|
189
|
+
.export(queryParam)
|
|
162
190
|
.then((response) => resolve({ response, uid }))
|
|
163
191
|
.catch((error) => reject({ error, uid }));
|
|
164
192
|
default:
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { HttpClient } from '@contentstack/cli-utilities';
|
|
2
|
+
import { ModuleClassParams, ComposableStudioConfig, ExportConfig, ComposableStudioProject } from '../../types';
|
|
3
|
+
export default class ExportComposableStudio {
|
|
4
|
+
protected composableStudioConfig: ComposableStudioConfig;
|
|
5
|
+
protected composableStudioProject: ComposableStudioProject | null;
|
|
6
|
+
protected apiClient: HttpClient;
|
|
7
|
+
composableStudioPath: string;
|
|
8
|
+
exportConfig: ExportConfig;
|
|
9
|
+
constructor({ exportConfig }: Omit<ModuleClassParams, 'stackAPIClient' | 'moduleName'>);
|
|
10
|
+
start(): Promise<void>;
|
|
11
|
+
/**
|
|
12
|
+
* Export Studio projects connected to the current stack
|
|
13
|
+
*/
|
|
14
|
+
exportProjects(): Promise<void>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const node_path_1 = require("node:path");
|
|
4
|
+
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
5
|
+
const utils_1 = require("../../utils");
|
|
6
|
+
class ExportComposableStudio {
|
|
7
|
+
constructor({ exportConfig }) {
|
|
8
|
+
this.composableStudioProject = null;
|
|
9
|
+
this.exportConfig = exportConfig;
|
|
10
|
+
this.composableStudioConfig = exportConfig.modules['composable-studio'];
|
|
11
|
+
this.exportConfig.context.module = 'composable-studio';
|
|
12
|
+
// Initialize HttpClient with Studio API base URL
|
|
13
|
+
this.apiClient = new cli_utilities_1.HttpClient();
|
|
14
|
+
this.apiClient.baseUrl(`${this.composableStudioConfig.apiBaseUrl}/${this.composableStudioConfig.apiVersion}`);
|
|
15
|
+
}
|
|
16
|
+
async start() {
|
|
17
|
+
cli_utilities_1.log.debug('Starting Studio project export process...', this.exportConfig.context);
|
|
18
|
+
if (!(0, cli_utilities_1.isAuthenticated)()) {
|
|
19
|
+
cli_utilities_1.cliux.print('WARNING!!! To export Studio projects, you must be logged in. Please check csdx auth:login --help to log in', { color: 'yellow' });
|
|
20
|
+
return Promise.resolve();
|
|
21
|
+
}
|
|
22
|
+
this.composableStudioPath = (0, node_path_1.resolve)(this.exportConfig.exportDir, this.exportConfig.branchName || '', this.composableStudioConfig.dirName);
|
|
23
|
+
cli_utilities_1.log.debug(`Studio folder path: ${this.composableStudioPath}`, this.exportConfig.context);
|
|
24
|
+
await utils_1.fsUtil.makeDirectory(this.composableStudioPath);
|
|
25
|
+
cli_utilities_1.log.debug('Created Studio directory', this.exportConfig.context);
|
|
26
|
+
this.exportConfig.org_uid = this.exportConfig.org_uid || (await (0, utils_1.getOrgUid)(this.exportConfig));
|
|
27
|
+
cli_utilities_1.log.debug(`Organization UID: ${this.exportConfig.org_uid}`, this.exportConfig.context);
|
|
28
|
+
await this.exportProjects();
|
|
29
|
+
cli_utilities_1.log.debug('Studio project export process completed', this.exportConfig.context);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Export Studio projects connected to the current stack
|
|
33
|
+
*/
|
|
34
|
+
async exportProjects() {
|
|
35
|
+
var _a, _b;
|
|
36
|
+
cli_utilities_1.log.debug('Starting Studio project export...', this.exportConfig.context);
|
|
37
|
+
try {
|
|
38
|
+
// Get authentication details - following personalization-api-adapter pattern
|
|
39
|
+
cli_utilities_1.log.debug('Initializing Studio API authentication...', this.exportConfig.context);
|
|
40
|
+
await cli_utilities_1.authenticationHandler.getAuthDetails();
|
|
41
|
+
const token = cli_utilities_1.authenticationHandler.accessToken;
|
|
42
|
+
cli_utilities_1.log.debug(`Authentication type: ${cli_utilities_1.authenticationHandler.isOauthEnabled ? 'OAuth' : 'Token'}`, this.exportConfig.context);
|
|
43
|
+
// Set authentication headers based on auth type
|
|
44
|
+
if (cli_utilities_1.authenticationHandler.isOauthEnabled) {
|
|
45
|
+
cli_utilities_1.log.debug('Setting OAuth authorization header', this.exportConfig.context);
|
|
46
|
+
this.apiClient.headers({ authorization: token });
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
cli_utilities_1.log.debug('Setting authtoken header', this.exportConfig.context);
|
|
50
|
+
this.apiClient.headers({ authtoken: token });
|
|
51
|
+
}
|
|
52
|
+
// Set organization_uid header
|
|
53
|
+
this.apiClient.headers({
|
|
54
|
+
organization_uid: this.exportConfig.org_uid,
|
|
55
|
+
Accept: 'application/json',
|
|
56
|
+
});
|
|
57
|
+
const apiUrl = '/projects';
|
|
58
|
+
cli_utilities_1.log.debug(`Fetching projects from: ${this.composableStudioConfig.apiBaseUrl}${apiUrl}`, this.exportConfig.context);
|
|
59
|
+
// Make API call to fetch projects using HttpClient
|
|
60
|
+
const response = await this.apiClient.get(apiUrl);
|
|
61
|
+
if (response.status < 200 || response.status >= 300) {
|
|
62
|
+
throw new Error(`API call failed with status ${response.status}: ${JSON.stringify(response.data)}`);
|
|
63
|
+
}
|
|
64
|
+
const data = response.data;
|
|
65
|
+
cli_utilities_1.log.debug(`Fetched ${((_a = data.projects) === null || _a === void 0 ? void 0 : _a.length) || 0} total projects`, this.exportConfig.context);
|
|
66
|
+
// Filter projects connected to this stack
|
|
67
|
+
const connectedProject = (_b = data.projects) === null || _b === void 0 ? void 0 : _b.filter((project) => project.connectedStackApiKey === this.exportConfig.apiKey);
|
|
68
|
+
if (!connectedProject || connectedProject.length === 0) {
|
|
69
|
+
cli_utilities_1.log.info(cli_utilities_1.messageHandler.parse('COMPOSABLE_STUDIO_NOT_FOUND'), this.exportConfig.context);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
// Use the first connected project (stacks should have only one project)
|
|
73
|
+
this.composableStudioProject = connectedProject[0];
|
|
74
|
+
cli_utilities_1.log.debug(`Found Studio project: ${this.composableStudioProject.name}`, this.exportConfig.context);
|
|
75
|
+
// Write the project to file
|
|
76
|
+
const composableStudioFilePath = (0, node_path_1.resolve)(this.composableStudioPath, this.composableStudioConfig.fileName);
|
|
77
|
+
cli_utilities_1.log.debug(`Writing Studio project to: ${composableStudioFilePath}`, this.exportConfig.context);
|
|
78
|
+
utils_1.fsUtil.writeFile(composableStudioFilePath, this.composableStudioProject);
|
|
79
|
+
cli_utilities_1.log.success(cli_utilities_1.messageHandler.parse('COMPOSABLE_STUDIO_EXPORT_COMPLETE', this.composableStudioProject.name), this.exportConfig.context);
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
cli_utilities_1.log.debug('Error occurred while exporting Studio project', this.exportConfig.context);
|
|
83
|
+
(0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.exportConfig.context));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.default = ExportComposableStudio;
|