@contentstack/cli-cm-import 1.2.4 → 1.3.0
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/README.md +84 -24
- package/oclif.manifest.json +129 -1
- package/package.json +6 -8
- package/src/app.js +47 -59
- package/src/commands/cm/stacks/import.js +1 -1
- package/src/config/default.js +1 -1
- package/src/lib/import/assets.js +261 -247
- package/src/lib/import/content-types.js +19 -21
- package/src/lib/import/custom-roles.js +7 -17
- package/src/lib/import/entries.js +344 -360
- package/src/lib/import/environments.js +5 -7
- package/src/lib/import/extensions.js +6 -9
- package/src/lib/import/global-fields.js +7 -17
- package/src/lib/import/labels.js +5 -8
- package/src/lib/import/locales.js +5 -10
- package/src/lib/import/marketplace-apps.js +389 -414
- package/src/lib/import/webhooks.js +4 -6
- package/src/lib/import/workflows.js +6 -15
- package/src/lib/util/extensionsUidReplace.js +2 -33
- package/src/lib/util/index.js +71 -72
- package/src/lib/util/login.js +45 -42
- package/src/lib/util/lookupReplaceAssets.js +6 -97
- package/src/lib/util/marketplace-app-helper.js +10 -37
- package/src/lib/util/upload.js +30 -23
- package/src/lib/util/contentstack-management-sdk.js +0 -41
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const chalk = require('chalk');
|
|
4
|
+
const { cloneDeep, find, findIndex } = require('lodash');
|
|
5
|
+
|
|
4
6
|
const fileHelper = require('../util/fs');
|
|
5
|
-
const
|
|
7
|
+
const { addlogs } = require('../util/log');
|
|
6
8
|
const supress = require('../util/extensionsUidReplace');
|
|
7
|
-
const { getInstalledExtensions } = require('../util/marketplace-app-helper');
|
|
8
9
|
const { executeTask, formatError } = require('../util');
|
|
9
|
-
const { addlogs } = require('../util/log');
|
|
10
|
-
const { cloneDeep, remove, isEmpty, find, findIndex } = require('lodash');
|
|
11
10
|
const schemaTemplate = require('../util/schemaTemplate');
|
|
12
11
|
|
|
13
12
|
class ContentTypesImport {
|
|
@@ -24,7 +23,6 @@ class ContentTypesImport {
|
|
|
24
23
|
this.globalFieldsFolderPath = path.resolve(this.importConfig.data, this.globalFieldConfig.dirName);
|
|
25
24
|
this.globalFieldMapperFolderPath = path.join(importConfig.data, 'mapper', 'global_fields', 'success.json');
|
|
26
25
|
this.globalFieldPendingPath = path.join(importConfig.data, 'mapper', 'global_fields', 'pending_global_fields.js');
|
|
27
|
-
this.appMapperFolderPath = path.join(importConfig.data, 'mapper', 'marketplace_apps');
|
|
28
26
|
this.ignoredFilesInContentTypesFolder = new Map([
|
|
29
27
|
['__master.json', 'true'],
|
|
30
28
|
['__priority.json', 'true'],
|
|
@@ -32,7 +30,7 @@ class ContentTypesImport {
|
|
|
32
30
|
['.DS_Store', 'true'],
|
|
33
31
|
]);
|
|
34
32
|
this.contentTypes = [];
|
|
35
|
-
this.existingContentTypesUIds;
|
|
33
|
+
this.existingContentTypesUIds = [];
|
|
36
34
|
this.titleToUIdMap = new Map();
|
|
37
35
|
this.requestOptions = {
|
|
38
36
|
json: {},
|
|
@@ -46,6 +44,10 @@ class ContentTypesImport {
|
|
|
46
44
|
|
|
47
45
|
async start() {
|
|
48
46
|
try {
|
|
47
|
+
const appMapperPath = path.join(this.importConfig.data, 'mapper', 'marketplace_apps', 'uid-mapping.json');
|
|
48
|
+
this.installedExtensions = (
|
|
49
|
+
(await fileHelper.readFileSync(appMapperPath)) || { extension_uid: {} }
|
|
50
|
+
).extension_uid;
|
|
49
51
|
// read content types
|
|
50
52
|
// remove content types already existing
|
|
51
53
|
if (fs.existsSync(this.existingContentTypesPath)) {
|
|
@@ -58,27 +60,19 @@ class ContentTypesImport {
|
|
|
58
60
|
if (!this.ignoredFilesInContentTypesFolder.has(contentTypeName)) {
|
|
59
61
|
const contentTypePath = path.join(this.contentTypesFolderPath, contentTypeName);
|
|
60
62
|
const contentType = await fileHelper.readFile(contentTypePath);
|
|
61
|
-
if (!this.existingContentTypesUIds
|
|
63
|
+
if (!this.existingContentTypesUIds.length || !this.existingContentTypesUIds.has(contentType.uid)) {
|
|
62
64
|
this.contentTypes.push(await fileHelper.readFile(contentTypePath));
|
|
63
65
|
}
|
|
64
66
|
}
|
|
65
67
|
}
|
|
66
|
-
// this.mapUidToTitle(this.csontentTypes);
|
|
67
68
|
|
|
68
69
|
// seed content type
|
|
69
70
|
addlogs(this.importConfig, 'Started to seed content types', 'info');
|
|
70
|
-
await executeTask(this.
|
|
71
|
+
await executeTask(this.seedContentType.bind(this), { concurrency: this.importConcurrency }, this.contentTypes);
|
|
71
72
|
addlogs(this.importConfig, 'Created content types', 'success');
|
|
72
73
|
|
|
73
|
-
// update content type
|
|
74
|
-
this.installedExtensions =
|
|
75
|
-
fileHelper.readFileSync(path.join(this.appMapperFolderPath, 'marketplace-apps.json')) || {};
|
|
76
|
-
if (isEmpty(this.installedExtensions)) {
|
|
77
|
-
this.installedExtensions = await getInstalledExtensions(this.importConfig);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
74
|
addlogs(this.importConfig, 'Started to update content types with references', 'info');
|
|
81
|
-
await executeTask(this.
|
|
75
|
+
await executeTask(this.updateContentType.bind(this), { concurrency: this.importConcurrency }, this.contentTypes);
|
|
82
76
|
addlogs(this.importConfig, 'Updated content types with references', 'success');
|
|
83
77
|
|
|
84
78
|
// global field update
|
|
@@ -90,9 +84,13 @@ class ContentTypesImport {
|
|
|
90
84
|
this.existingGlobalFields = fileHelper.readFileSync(this.globalFieldMapperFolderPath);
|
|
91
85
|
try {
|
|
92
86
|
addlogs(this.importConfig, 'Started to update pending global field with content type references', 'info');
|
|
93
|
-
await executeTask(
|
|
94
|
-
|
|
95
|
-
|
|
87
|
+
await executeTask(
|
|
88
|
+
this.updateGlobalFields.bind(this),
|
|
89
|
+
{
|
|
90
|
+
concurrency: this.importConcurrency,
|
|
91
|
+
},
|
|
92
|
+
this.pendingGlobalFields,
|
|
93
|
+
);
|
|
96
94
|
addlogs(this.importConfig, 'Updated pending global fields with content type with references', 'success');
|
|
97
95
|
} catch (error) {
|
|
98
96
|
addlogs(
|
|
@@ -175,7 +173,7 @@ class ContentTypesImport {
|
|
|
175
173
|
return true;
|
|
176
174
|
} catch (error) {
|
|
177
175
|
addlogs(this.importConfig, `failed to update the global field ${uid} ${formatError(error)}`);
|
|
178
|
-
}
|
|
176
|
+
}
|
|
179
177
|
} else {
|
|
180
178
|
addlogs(this.importConfig, `Global field ${uid} does not exist, and hence failed to update.`);
|
|
181
179
|
}
|
|
@@ -10,18 +10,16 @@ const helper = require('../util/fs');
|
|
|
10
10
|
const { addlogs } = require('../util/log');
|
|
11
11
|
const { formatError } = require('../util');
|
|
12
12
|
let config = require('../../config/default');
|
|
13
|
-
const stack = require('../util/contentstack-management-sdk');
|
|
14
13
|
|
|
15
14
|
module.exports = class ImportCustomRoles {
|
|
16
15
|
fails = [];
|
|
17
|
-
client = null;
|
|
18
16
|
labelUids = [];
|
|
19
17
|
customRolesUidMapper = {};
|
|
20
18
|
customRolesConfig = config.modules.customRoles;
|
|
21
19
|
|
|
22
|
-
constructor(
|
|
23
|
-
this.config = merge(config,
|
|
24
|
-
this.
|
|
20
|
+
constructor(importConfig, stackAPIClient) {
|
|
21
|
+
this.config = merge(config, importConfig);
|
|
22
|
+
this.stackAPIClient = stackAPIClient;
|
|
25
23
|
}
|
|
26
24
|
|
|
27
25
|
async start() {
|
|
@@ -56,7 +54,7 @@ module.exports = class ImportCustomRoles {
|
|
|
56
54
|
}
|
|
57
55
|
self.customRolesUids = Object.keys(self.customRoles);
|
|
58
56
|
|
|
59
|
-
self.localesUidMap = await getLocalesUidMap(self.
|
|
57
|
+
self.localesUidMap = await getLocalesUidMap(self.stackAPIClient, self.config, self.customRolesLocales);
|
|
60
58
|
|
|
61
59
|
if (fs.existsSync(environmentsUidMapperFolderPath)) {
|
|
62
60
|
self.environmentsUidMap = helper.readFileSync(
|
|
@@ -93,11 +91,7 @@ module.exports = class ImportCustomRoles {
|
|
|
93
91
|
acl: { read: true },
|
|
94
92
|
});
|
|
95
93
|
}
|
|
96
|
-
const role = await self.
|
|
97
|
-
.stack({ api_key: self.config.target_stack, management_token: self.config.management_token })
|
|
98
|
-
.role()
|
|
99
|
-
.create({ role: customRole });
|
|
100
|
-
|
|
94
|
+
const role = await self.stackAPIClient.role().create({ role: customRole });
|
|
101
95
|
self.customRolesUidMapper[uid] = role;
|
|
102
96
|
helper.writeFileSync(customRolesUidMapperPath, self.customRolesUidMapper);
|
|
103
97
|
} catch (error) {
|
|
@@ -158,12 +152,8 @@ const noopTransformer = (rule) => {
|
|
|
158
152
|
return rule;
|
|
159
153
|
};
|
|
160
154
|
|
|
161
|
-
const getLocalesUidMap = async (
|
|
162
|
-
const { items } = await
|
|
163
|
-
.stack({ api_key: config.target_stack, management_token: config.management_token })
|
|
164
|
-
.locale()
|
|
165
|
-
.query()
|
|
166
|
-
.find();
|
|
155
|
+
const getLocalesUidMap = async (stackAPIClient, config, sourceLocales) => {
|
|
156
|
+
const { items } = await stackAPIClient.locale().query().find();
|
|
167
157
|
const [targetLocalesMap, sourceLocalesMap] = [{}, {}];
|
|
168
158
|
|
|
169
159
|
items.forEach((locale) => {
|