@contentstack/cli-cm-export 1.5.8 → 1.6.1

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.
Files changed (97) hide show
  1. package/README.md +2 -2
  2. package/lib/commands/cm/stacks/export.d.ts +10 -0
  3. package/lib/commands/cm/stacks/export.js +108 -0
  4. package/lib/config/index.d.ts +3 -0
  5. package/lib/config/index.js +393 -0
  6. package/lib/export/index.d.ts +1 -0
  7. package/lib/export/index.js +8 -0
  8. package/lib/export/module-exporter.d.ts +15 -0
  9. package/lib/export/module-exporter.js +93 -0
  10. package/lib/export/modules/assets.d.ts +54 -0
  11. package/lib/export/modules/assets.js +303 -0
  12. package/lib/export/modules/base-class.d.ts +48 -0
  13. package/lib/export/modules/base-class.js +117 -0
  14. package/lib/export/modules/index.d.ts +3 -0
  15. package/lib/export/modules/index.js +38 -0
  16. package/lib/export/modules/locales.d.ts +16 -0
  17. package/lib/export/modules/locales.js +68 -0
  18. package/lib/export/modules-js/assets.d.ts +43 -0
  19. package/lib/export/modules-js/assets.js +391 -0
  20. package/lib/export/modules-js/content-types.d.ts +21 -0
  21. package/lib/export/modules-js/content-types.js +75 -0
  22. package/lib/export/modules-js/custom-roles.d.ts +21 -0
  23. package/lib/export/modules-js/custom-roles.js +76 -0
  24. package/lib/export/modules-js/entries.d.ts +18 -0
  25. package/lib/export/modules-js/entries.js +141 -0
  26. package/lib/export/modules-js/environments.d.ts +16 -0
  27. package/lib/export/modules-js/environments.js +62 -0
  28. package/lib/export/modules-js/extensions.d.ts +18 -0
  29. package/lib/export/modules-js/extensions.js +57 -0
  30. package/lib/export/modules-js/global-fields.d.ts +22 -0
  31. package/lib/export/modules-js/global-fields.js +107 -0
  32. package/lib/export/modules-js/index.d.ts +1 -0
  33. package/lib/export/modules-js/index.js +33 -0
  34. package/lib/export/modules-js/labels.d.ts +14 -0
  35. package/lib/export/modules-js/labels.js +56 -0
  36. package/lib/export/modules-js/locales.d.ts +23 -0
  37. package/lib/export/modules-js/locales.js +67 -0
  38. package/lib/export/modules-js/marketplace-apps.d.ts +21 -0
  39. package/lib/export/modules-js/marketplace-apps.js +144 -0
  40. package/lib/export/modules-js/stack.d.ts +18 -0
  41. package/lib/export/modules-js/stack.js +91 -0
  42. package/lib/export/modules-js/webhooks.d.ts +18 -0
  43. package/lib/export/modules-js/webhooks.js +60 -0
  44. package/lib/export/modules-js/workflows.d.ts +16 -0
  45. package/lib/export/modules-js/workflows.js +89 -0
  46. package/lib/types/default-config.d.ts +158 -0
  47. package/lib/types/default-config.js +2 -0
  48. package/lib/types/export-config.d.ts +34 -0
  49. package/lib/types/export-config.js +2 -0
  50. package/lib/types/index.d.ts +45 -0
  51. package/lib/types/index.js +2 -0
  52. package/lib/utils/basic-login.d.ts +8 -0
  53. package/lib/utils/basic-login.js +45 -0
  54. package/lib/utils/common-helper.d.ts +11 -0
  55. package/lib/utils/common-helper.js +78 -0
  56. package/lib/utils/export-config-handler.d.ts +3 -0
  57. package/lib/utils/export-config-handler.js +72 -0
  58. package/lib/utils/file-helper.d.ts +14 -0
  59. package/lib/utils/file-helper.js +120 -0
  60. package/lib/utils/index.d.ts +10 -0
  61. package/lib/utils/index.js +21 -0
  62. package/lib/utils/interactive.d.ts +6 -0
  63. package/lib/utils/interactive.js +71 -0
  64. package/lib/utils/logger.d.ts +8 -0
  65. package/lib/utils/logger.js +154 -0
  66. package/lib/utils/marketplace-app-helper.d.ts +1 -0
  67. package/lib/utils/marketplace-app-helper.js +23 -0
  68. package/lib/utils/setup-branches.d.ts +3 -0
  69. package/lib/utils/setup-branches.js +49 -0
  70. package/lib/utils/setup-export-dir.d.ts +2 -0
  71. package/lib/utils/setup-export-dir.js +12 -0
  72. package/messages/index.json +1 -7
  73. package/oclif.manifest.json +1 -1
  74. package/package.json +37 -23
  75. package/src/app.js +0 -161
  76. package/src/commands/cm/stacks/export.js +0 -202
  77. package/src/config/default.js +0 -360
  78. package/src/lib/export/assets.js +0 -451
  79. package/src/lib/export/content-types.js +0 -90
  80. package/src/lib/export/custom-roles.js +0 -93
  81. package/src/lib/export/entries.js +0 -200
  82. package/src/lib/export/environments.js +0 -74
  83. package/src/lib/export/extensions.js +0 -69
  84. package/src/lib/export/global-fields.js +0 -122
  85. package/src/lib/export/labels.js +0 -69
  86. package/src/lib/export/locales.js +0 -72
  87. package/src/lib/export/marketplace-apps.js +0 -184
  88. package/src/lib/export/stack.js +0 -99
  89. package/src/lib/export/webhooks.js +0 -76
  90. package/src/lib/export/workflows.js +0 -110
  91. package/src/lib/util/export-flags.js +0 -193
  92. package/src/lib/util/helper.js +0 -113
  93. package/src/lib/util/index.js +0 -80
  94. package/src/lib/util/log.js +0 -158
  95. package/src/lib/util/login.js +0 -79
  96. package/src/lib/util/marketplace-app-helper.js +0 -24
  97. package/src/lib/util/setup-branches.js +0 -56
@@ -1,184 +0,0 @@
1
- /*!
2
- * Contentstack Export
3
- * Copyright (c) 2019 Contentstack LLC
4
- * MIT Licensed
5
- */
6
- const _ = require('lodash');
7
- const path = require('path');
8
- const chalk = require('chalk');
9
- const mkdirp = require('mkdirp');
10
- const {
11
- cliux,
12
- HttpClient,
13
- NodeCrypto,
14
- managementSDKClient,
15
- HttpClientDecorator,
16
- OauthDecorator,
17
- isAuthenticated,
18
- } = require('@contentstack/cli-utilities');
19
-
20
- const { formatError } = require('../util');
21
- const config = require('../../config/default');
22
- const { addlogs: log } = require('../util/log');
23
- const { writeFileSync } = require('../util/helper');
24
- const { getDeveloperHubUrl } = require('../util/marketplace-app-helper');
25
-
26
- module.exports = class ExportMarketplaceApps {
27
- client;
28
- config;
29
- httpClient;
30
- nodeCrypto;
31
- marketplaceAppPath = null;
32
- developerHubBaseUrl = null;
33
- marketplaceAppConfig = config.modules.marketplace_apps;
34
-
35
- constructor(credentialConfig) {
36
- this.config = _.merge(config, credentialConfig);
37
- }
38
-
39
- async start() {
40
- if (!isAuthenticated()) {
41
- cliux.print(
42
- 'WARNING!!! To export Marketplace apps, you must be logged in. Please check csdx auth:login --help to log in',
43
- { color: 'yellow' },
44
- );
45
- return Promise.resolve();
46
- }
47
-
48
- this.developerHubBaseUrl = this.config.developerHubBaseUrl || (await getDeveloperHubUrl());
49
-
50
- await this.getOrgUid();
51
-
52
- const httpClient = new HttpClient();
53
- if (!this.config.auth_token) {
54
- this.httpClient = new OauthDecorator(httpClient);
55
- const headers = await this.httpClient.preHeadersCheck(this.config);
56
- this.httpClient = this.httpClient.headers(headers);
57
- } else {
58
- this.httpClient = new HttpClientDecorator(httpClient);
59
- this.httpClient.headers(this.config);
60
- }
61
-
62
- log(this.config, 'Starting marketplace app export', 'success');
63
- this.marketplaceAppPath = path.resolve(
64
- this.config.data,
65
- this.config.branchName || '',
66
- this.marketplaceAppConfig.dirName,
67
- );
68
- mkdirp.sync(this.marketplaceAppPath);
69
-
70
- return this.exportInstalledExtensions();
71
- }
72
-
73
- async getOrgUid() {
74
- const tempAPIClient = await managementSDKClient({ host: this.config.host });
75
- const tempStackData = await tempAPIClient
76
- .stack({ api_key: this.config.source_stack })
77
- .fetch()
78
- .catch((error) => {
79
- console.log(error);
80
- });
81
-
82
- if (tempStackData && tempStackData.org_uid) {
83
- this.config.org_uid = tempStackData.org_uid;
84
- }
85
- }
86
-
87
- async createNodeCryptoInstance() {
88
- const cryptoArgs = {};
89
-
90
- if (this.config.forceStopMarketplaceAppsPrompt) {
91
- cryptoArgs['encryptionKey'] = this.config.marketplaceAppEncryptionKey;
92
- } else {
93
- cryptoArgs['encryptionKey'] = await cliux.inquire({
94
- type: 'input',
95
- name: 'name',
96
- default: this.config.marketplaceAppEncryptionKey,
97
- validate: (url) => {
98
- if (!url) return "Encryption key can't be empty.";
99
-
100
- return true;
101
- },
102
- message: 'Enter marketplace app configurations encryption key',
103
- });
104
- }
105
-
106
- this.nodeCrypto = new NodeCrypto(cryptoArgs);
107
- }
108
-
109
- async exportInstalledExtensions() {
110
- const installedApps = (await this.getAllStackSpecificApps()) || [];
111
-
112
- if (!_.isEmpty(installedApps)) {
113
- for (const [index, app] of _.entries(installedApps)) {
114
- await this.getAppConfigurations(installedApps, [+index, app]);
115
- }
116
-
117
- await writeFileSync(path.join(this.marketplaceAppPath, this.marketplaceAppConfig.fileName), installedApps);
118
-
119
- log(this.config, chalk.green('All the marketplace apps have been exported successfully'), 'success');
120
- } else {
121
- log(this.config, 'No marketplace apps found', 'success');
122
- }
123
- }
124
-
125
- getAllStackSpecificApps(listOfApps = [], skip = 0) {
126
- return this.httpClient
127
- .get(`${this.developerHubBaseUrl}/installations?target_uids=${this.config.source_stack}&skip=${skip}`)
128
- .then(async ({ data }) => {
129
- const { data: apps, count } = data;
130
-
131
- if (!this.nodeCrypto && _.find(apps, (app) => !_.isEmpty(app.configuration))) {
132
- await this.createNodeCryptoInstance();
133
- }
134
-
135
- listOfApps.push(
136
- ..._.map(apps, (app) => {
137
- if (_.has(app, 'configuration')) {
138
- app['configuration'] = this.nodeCrypto.encrypt(app.configuration || configuration);
139
- }
140
-
141
- return app;
142
- }),
143
- );
144
-
145
- if (count - (skip + 50) > 0) {
146
- return await this.getAllStackSpecificApps(listOfApps, skip + 50);
147
- }
148
-
149
- return listOfApps;
150
- })
151
- .catch((error) => {
152
- log(this.config, `Failed to export marketplace-apps ${formatError(error)}`, 'error');
153
- });
154
- }
155
-
156
- getAppConfigurations(installedApps, [index, app]) {
157
- const appName = app.manifest.name;
158
- log(this.config, `Exporting ${appName} app and it's config.`, 'success');
159
-
160
- return this.httpClient
161
- .get(`${this.developerHubBaseUrl}/installations/${app.uid}/installationData`)
162
- .then(async ({ data: result }) => {
163
- const { data, error } = result;
164
-
165
- if (_.has(data, 'server_configuration')) {
166
- if (!this.nodeCrypto && _.has(data, 'server_configuration')) {
167
- await this.createNodeCryptoInstance();
168
- }
169
-
170
- if (!_.isEmpty(data.server_configuration)) {
171
- installedApps[index]['server_configuration'] = this.nodeCrypto.encrypt(data.server_configuration);
172
- log(this.config, `Exported ${appName} app and it's config.`, 'success');
173
- } else {
174
- log(this.config, `Exported ${appName} app`, 'success');
175
- }
176
- } else if (error) {
177
- log(this.config, `Error on exporting ${appName} app and it's config.`, 'error');
178
- }
179
- })
180
- .catch((err) => {
181
- log(this.config, `Failed to export ${appName} app config ${formatError(err)}`, 'error');
182
- });
183
- }
184
- };
@@ -1,99 +0,0 @@
1
- /*!
2
- * Contentstack Export
3
- * Copyright (c) 2019 Contentstack LLC
4
- * MIT Licensed
5
- */
6
-
7
- const path = require('path');
8
- const mkdirp = require('mkdirp');
9
- const { merge } = require('lodash');
10
- const helper = require('../util/helper');
11
- const { addlogs } = require('../util/log');
12
- const config = require('../../config/default');
13
- const { managementSDKClient, isAuthenticated } = require('@contentstack/cli-utilities');
14
- module.exports = class ExportStack {
15
- stackConfig = config.modules.stack;
16
-
17
- constructor(exportConfig, stackAPIClient, APIClient) {
18
- this.config = merge(config, exportConfig);
19
- this.stackAPIClient = stackAPIClient;
20
- this.APIClient = APIClient;
21
- this.requestOption = {
22
- uri: this.config.host + this.config.apis.stacks,
23
- headers: this.config.headers,
24
- json: true,
25
- };
26
- }
27
-
28
- async start() {
29
- const self = this;
30
- if (isAuthenticated()) {
31
- const tempAPIClient = await managementSDKClient({ host: config.host });
32
- const tempStackData = await tempAPIClient
33
- .stack({ api_key: self.config.source_stack })
34
- .fetch()
35
- .catch((error) => {
36
- console.log(error);
37
- });
38
-
39
- if (tempStackData && tempStackData.org_uid) {
40
- self.config.org_uid = tempStackData.org_uid;
41
- self.config.sourceStackName = tempStackData.name;
42
- }
43
- }
44
-
45
- if (!self.config.preserveStackVersion && !self.config.hasOwnProperty('master_locale')) {
46
- const apiDetails = {
47
- limit: 100,
48
- skip: 0,
49
- include_count: true,
50
- };
51
- return self.getLocales(apiDetails);
52
- } else if (self.config.preserveStackVersion) {
53
- addlogs(self.config, 'Exporting stack details', 'success');
54
- let stackFolderPath = path.resolve(self.config.data, stackConfig.dirName);
55
- let stackContentsFile = path.resolve(stackFolderPath, stackConfig.fileName);
56
-
57
- mkdirp.sync(stackFolderPath);
58
-
59
- return new Promise((resolve, reject) => {
60
- return self.APIClient.stack({ api_key: self.config.source_stack })
61
- .fetch()
62
- .then((response) => {
63
- helper.writeFile(stackContentsFile, response);
64
- addlogs(self.config, 'Exported stack details successfully!', 'success');
65
- return resolve(response);
66
- })
67
- .catch(reject);
68
- });
69
- }
70
- }
71
-
72
- getLocales(apiDetails) {
73
- const self = this;
74
- return new Promise((resolve, reject) => {
75
- const result = self.stackAPIClient.locale().query(apiDetails);
76
-
77
- result
78
- .find()
79
- .then((response) => {
80
- const masterLocalObj = response.items.find((obj) => {
81
- if (obj.fallback_locale === null) {
82
- return obj;
83
- }
84
- });
85
- apiDetails.skip += apiDetails.limit;
86
- if (masterLocalObj) {
87
- return resolve(masterLocalObj);
88
- } else if (apiDetails.skip <= response.count) {
89
- return resolve(self.getLocales(apiDetails));
90
- } else {
91
- return reject('Master locale not found');
92
- }
93
- })
94
- .catch((error) => {
95
- return reject(error);
96
- });
97
- });
98
- }
99
- };
@@ -1,76 +0,0 @@
1
- /*!
2
- * Contentstack Export
3
- * Copyright (c) 2019 Contentstack LLC
4
- * MIT Licensed
5
- */
6
-
7
- const path = require('path');
8
- const chalk = require('chalk');
9
- const mkdirp = require('mkdirp');
10
- const { merge } = require('lodash');
11
-
12
- const helper = require('../util/helper');
13
- const { formatError } = require('../util');
14
- const { addlogs } = require('../util/log');
15
- const config = require('../../config/default');
16
-
17
- // Create folder for environments
18
- module.exports = class ExportWebhooks {
19
- config;
20
- master = {};
21
- webhooks = {};
22
- requestOptions = {
23
- include_count: true,
24
- asc: 'updated_at',
25
- };
26
- webhooksConfig = config.modules.webhooks;
27
-
28
- constructor(exportConfig, stackAPIClient) {
29
- this.config = merge(config, exportConfig);
30
- this.stackAPIClient = stackAPIClient;
31
- }
32
-
33
- start() {
34
- addlogs(this.config, 'Starting webhooks export', 'success');
35
- const self = this;
36
- const webhooksFolderPath = path.resolve(
37
- this.config.data,
38
- this.config.branchName || '',
39
- self.webhooksConfig.dirName,
40
- );
41
- mkdirp.sync(webhooksFolderPath);
42
- return new Promise((resolve, reject) => {
43
- self.stackAPIClient
44
- .webhook()
45
- .fetchAll(self.requestOptions)
46
- .then((webhooks) => {
47
- if (webhooks.items.length !== 0) {
48
- for (let i = 0, total = webhooks.count; i < total; i++) {
49
- const webUid = webhooks.items[i].uid;
50
- self.master[webUid] = '';
51
- self.webhooks[webUid] = webhooks.items[i];
52
- delete self.webhooks[webUid].uid;
53
- delete self.webhooks[webUid].SYS_ACL;
54
- }
55
- helper.writeFileSync(path.join(webhooksFolderPath, self.webhooksConfig.fileName), self.webhooks);
56
- addlogs(self.config, chalk.green('All the webhooks have been exported successfully'), 'success');
57
- return resolve();
58
- }
59
- addlogs(self.config, 'No webhooks found', 'success');
60
- resolve();
61
- })
62
- .catch(function (error) {
63
- if (error.statusCode === 401) {
64
- addlogs(
65
- self.config,
66
- chalk.red('You are not allowed to export webhooks, Unless you provide email and password in config'),
67
- 'error',
68
- );
69
- return resolve();
70
- }
71
- addlogs(self.config, formatError(error), 'error');
72
- reject('Failed export webhooks');
73
- });
74
- });
75
- }
76
- };
@@ -1,110 +0,0 @@
1
- /*!
2
- * Contentstack Export
3
- * Copyright (c) 2019 Contentstack LLC
4
- * MIT Licensed
5
- */
6
-
7
- const path = require('path');
8
- const chalk = require('chalk');
9
- const mkdirp = require('mkdirp');
10
- const { merge } = require('lodash');
11
-
12
- const helper = require('../util/helper');
13
- const { addlogs } = require('../util/log');
14
- const { formatError } = require('../util');
15
- const config = require('../../config/default');
16
-
17
- module.exports = class ExportWorkFlows {
18
- config;
19
- workflows = {};
20
- workFlowConfig = config.modules.workflows;
21
-
22
- constructor(exportConfig, stackAPIClient) {
23
- this.config = merge(config, exportConfig);
24
- this.stackAPIClient = stackAPIClient;
25
- }
26
-
27
- start() {
28
- addlogs(this.config, 'Starting workflow export', 'success');
29
-
30
- const self = this;
31
- const workflowsFolderPath = path.resolve(
32
- this.config.data,
33
- this.config.branchName || '',
34
- this.workFlowConfig.dirName,
35
- );
36
- mkdirp.sync(workflowsFolderPath);
37
-
38
- return new Promise(function (resolve, reject) {
39
- return self.stackAPIClient
40
- .workflow()
41
- .fetchAll()
42
- .then(async (response) => {
43
- try {
44
- if (response.items.length) {
45
- await self.getWorkflowsData(self, response.items);
46
- addlogs(self.config, chalk.green('All the workflow have been exported successfully'), 'success');
47
- }
48
- if (!response.items.length) {
49
- addlogs(self.config, 'No workflow were found in the Stack', 'success');
50
- }
51
- helper.writeFileSync(path.join(workflowsFolderPath, self.workFlowConfig.fileName), self.workflows);
52
- resolve();
53
- } catch (error) {
54
- addlogs(self.config, formatError(error), 'error');
55
- reject(error);
56
- }
57
- })
58
- .catch(function (error) {
59
- if (error.statusCode === 401) {
60
- addlogs(
61
- self.config,
62
- chalk.red(
63
- 'You are not allowed to export workflow, Unless you provide email and password in config',
64
- 'error',
65
- ),
66
- );
67
- return resolve();
68
- }
69
- addlogs(self.config, formatError(error), 'error');
70
- resolve();
71
- });
72
- });
73
- }
74
-
75
- async getWorkflowRoles(self, workflow) {
76
- try {
77
- for (const stage of workflow.workflow_stages) {
78
- if (stage.SYS_ACL.roles.uids.length) {
79
- for (let i = 0; i < stage.SYS_ACL.roles.uids.length; i++) {
80
- const roleUid = stage.SYS_ACL.roles.uids[i];
81
- const roleData = await self.stackAPIClient
82
- .role(roleUid)
83
- .fetch({ include_rules: true, include_permissions: true });
84
- stage.SYS_ACL.roles.uids[i] = roleData;
85
- }
86
- }
87
- }
88
- } catch (error) {
89
- console.log('Error getting roles', error && error.message);
90
- addlogs(self.config, 'Error fetching roles in export workflows task.', 'error');
91
- throw new Error({ message: 'Error fetching roles in export workflows task.' });
92
- }
93
- }
94
-
95
- async getWorkflowsData(self, workflows) {
96
- try {
97
- for (const workflow of workflows) {
98
- addlogs(self.config, workflow.name + ' workflow was exported successfully', 'success');
99
- await self.getWorkflowRoles(self, workflow);
100
- self.workflows[workflow.uid] = workflow;
101
- const deleteItems = config.modules.workflows.invalidKeys;
102
- deleteItems.forEach((e) => delete workflow[e]);
103
- }
104
- } catch (error) {
105
- console.log('Error getting workflow data', error && error.message);
106
- addlogs(self.config, 'Error fetching workflow data in export workflows task.', 'error');
107
- throw error;
108
- }
109
- }
110
- };
@@ -1,193 +0,0 @@
1
- /*!
2
- * Contentstack Export
3
- * Copyright (c) 2019 Contentstack LLC
4
- * MIT Licensed
5
- */
6
- let defaultConfig = require('../../config/default');
7
- let message = require('../../../messages/index.json');
8
- let { initial } = require('../../app');
9
- let path = require('path');
10
- const helper = require('../util/helper');
11
- let _ = require('lodash');
12
- const { cliux } = require('@contentstack/cli-utilities');
13
-
14
- exports.configWithMToken = async (
15
- config,
16
- managementTokens,
17
- host,
18
- contentTypes,
19
- branchName,
20
- securedAssets,
21
- moduleName,
22
- data,
23
- exportCommandFlags,
24
- ) => {
25
- let externalConfig = require(config);
26
- const modules = externalConfig.filteredModules;
27
-
28
- defaultConfig.securedAssets = securedAssets;
29
- defaultConfig.management_token = managementTokens.token;
30
- defaultConfig.host = host.cma;
31
- defaultConfig.cdn = host.cda;
32
- defaultConfig.branchName = branchName;
33
- defaultConfig.source_stack = managementTokens.apiKey;
34
- defaultConfig.isAuthenticated = exportCommandFlags.isAuthenticated;
35
- if (moduleName) {
36
- defaultConfig.moduleName = moduleName;
37
- // Specfic content type setting is only for entries module
38
- if (moduleName === 'entries' && Array.isArray(contentTypes) && contentTypes.length > 0) {
39
- defaultConfig.contentTypes = contentTypes;
40
- }
41
- }
42
- defaultConfig = _.merge(defaultConfig, externalConfig);
43
-
44
- if(!defaultConfig.data) {
45
- defaultConfig.data = data
46
- }
47
-
48
- if (_.isArray(modules)) {
49
- defaultConfig.modules.types = _.filter(defaultConfig.modules.types, (module) => _.includes(modules, module));
50
- }
51
-
52
- await initial(defaultConfig);
53
- };
54
-
55
- exports.parameterWithMToken = async (
56
- managementTokens,
57
- data,
58
- moduleName,
59
- host,
60
- contentTypes,
61
- branchName,
62
- securedAssets,
63
- exportCommandFlags,
64
- ) => {
65
- defaultConfig.management_token = managementTokens.token;
66
- defaultConfig.host = host.cma;
67
- defaultConfig.cdn = host.cda;
68
- defaultConfig.branchName = branchName;
69
- defaultConfig.securedAssets = securedAssets;
70
- defaultConfig.isAuthenticated = exportCommandFlags.isAuthenticated;
71
- if (!moduleName) {
72
- defaultConfig.contentTypes = contentTypes;
73
- } else {
74
- defaultConfig.moduleName = moduleName;
75
- // Specfic content type setting is only for entries module
76
- if (moduleName === 'entries' && Array.isArray(contentTypes) && contentTypes.length > 0) {
77
- defaultConfig.contentTypes = contentTypes;
78
- }
79
- }
80
- defaultConfig.source_stack = managementTokens.apiKey;
81
- defaultConfig.data = data;
82
- await initial(defaultConfig);
83
- };
84
-
85
- // using ManagementToken
86
- exports.withoutParameterMToken = async (
87
- managementTokens,
88
- moduleName,
89
- host,
90
- contentTypes,
91
- branchName,
92
- securedAssets,
93
- exportCommandFlags,
94
- ) => {
95
- const stackUid = managementTokens.apiKey;
96
- const pathOfExport = await cliux.prompt(message.promptMessageList.promptPathStoredData);
97
- defaultConfig.management_token = managementTokens.token;
98
- defaultConfig.host = host.cma;
99
- defaultConfig.cdn = host.cda;
100
- defaultConfig.branchName = branchName;
101
- defaultConfig.securedAssets = securedAssets;
102
- defaultConfig.isAuthenticated = exportCommandFlags.isAuthenticated;
103
- if (moduleName) {
104
- defaultConfig.moduleName = moduleName;
105
- // Specfic content type setting is only for entries module
106
- if (moduleName === 'entries' && Array.isArray(contentTypes) && contentTypes.length > 0) {
107
- defaultConfig.contentTypes = contentTypes;
108
- }
109
- }
110
- defaultConfig.source_stack = stackUid;
111
- defaultConfig.data = pathOfExport;
112
- await initial(defaultConfig);
113
- };
114
-
115
- exports.configWithAuthToken = async function (
116
- config,
117
- moduleName,
118
- host,
119
- contentTypes,
120
- branchName,
121
- securedAssets,
122
- exportCommandFlags,
123
- ) {
124
- let externalConfig = helper.readFileSync(path.resolve(config));
125
- defaultConfig.host = host.cma;
126
- defaultConfig.cdn = host.cda;
127
- defaultConfig.branchName = branchName;
128
- defaultConfig.securedAssets = securedAssets;
129
- defaultConfig.isAuthenticated = exportCommandFlags.isAuthenticated;
130
- if (moduleName) {
131
- defaultConfig.moduleName = moduleName;
132
- // Specfic content type setting is only for entries module
133
- if (moduleName === 'entries' && Array.isArray(contentTypes) && contentTypes.length > 0) {
134
- defaultConfig.contentTypes = contentTypes;
135
- }
136
- }
137
- defaultConfig = _.merge(defaultConfig, externalConfig);
138
- await initial(defaultConfig);
139
- };
140
-
141
- exports.parametersWithAuthToken = async (
142
- sourceStack,
143
- data,
144
- moduleName,
145
- host,
146
- contentTypes,
147
- branchName,
148
- securedAssets,
149
- exportCommandFlags,
150
- ) => {
151
- defaultConfig.source_stack = sourceStack;
152
- defaultConfig.isAuthenticated = exportCommandFlags.isAuthenticated;
153
- if (moduleName) {
154
- defaultConfig.moduleName = moduleName;
155
- // Specfic content type setting is only for entries module
156
- if (moduleName === 'entries' && Array.isArray(contentTypes) && contentTypes.length > 0) {
157
- defaultConfig.contentTypes = contentTypes;
158
- }
159
- }
160
- defaultConfig.branchName = branchName;
161
- defaultConfig.host = host.cma;
162
- defaultConfig.cdn = host.cda;
163
- defaultConfig.data = data;
164
- defaultConfig.securedAssets = securedAssets;
165
- await initial(defaultConfig);
166
- };
167
-
168
- exports.withoutParametersWithAuthToken = async (
169
- moduleName,
170
- host,
171
- contentTypes,
172
- branchName,
173
- securedAssets,
174
- exportCommandFlags,
175
- ) => {
176
- const stackUid = await cliux.prompt(message.promptMessageList.promptSourceStack);
177
- const pathOfExport = await cliux.prompt(message.promptMessageList.promptPathStoredData);
178
- defaultConfig.source_stack = stackUid;
179
- defaultConfig.securedAssets = securedAssets;
180
- defaultConfig.isAuthenticated = exportCommandFlags.isAuthenticated;
181
- if (moduleName) {
182
- defaultConfig.moduleName = moduleName;
183
- // Specfic content type setting is only for entries module
184
- if (moduleName === 'entries' && Array.isArray(contentTypes) && contentTypes.length > 0) {
185
- defaultConfig.contentTypes = contentTypes;
186
- }
187
- }
188
- defaultConfig.branchName = branchName;
189
- defaultConfig.data = pathOfExport;
190
- defaultConfig.host = host.cma;
191
- defaultConfig.cdn = host.cda;
192
- await initial(defaultConfig);
193
- };