@contentstack/cli-cm-import 1.28.0 → 2.0.0-beta
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 +5 -7
- package/lib/commands/cm/stacks/import.d.ts +2 -0
- package/lib/commands/cm/stacks/import.js +46 -11
- package/lib/config/index.js +0 -1
- package/lib/import/module-importer.d.ts +2 -2
- package/lib/import/module-importer.js +9 -25
- package/lib/import/modules/assets.d.ts +6 -0
- package/lib/import/modules/assets.js +102 -25
- package/lib/import/modules/base-class.d.ts +17 -0
- package/lib/import/modules/base-class.js +45 -0
- package/lib/import/modules/content-types.d.ts +7 -10
- package/lib/import/modules/content-types.js +132 -68
- package/lib/import/modules/custom-roles.d.ts +6 -2
- package/lib/import/modules/custom-roles.js +80 -69
- package/lib/import/modules/entries.d.ts +7 -0
- package/lib/import/modules/entries.js +278 -163
- package/lib/import/modules/environments.d.ts +3 -0
- package/lib/import/modules/environments.js +69 -38
- package/lib/import/modules/extensions.d.ts +3 -0
- package/lib/import/modules/extensions.js +99 -64
- package/lib/import/modules/global-fields.d.ts +8 -1
- package/lib/import/modules/global-fields.js +123 -63
- package/lib/import/modules/index.d.ts +1 -0
- package/lib/import/modules/index.js +1 -0
- package/lib/import/modules/labels.d.ts +3 -0
- package/lib/import/modules/labels.js +104 -54
- package/lib/import/modules/locales.d.ts +15 -4
- package/lib/import/modules/locales.js +194 -94
- package/lib/import/modules/marketplace-apps.d.ts +6 -3
- package/lib/import/modules/marketplace-apps.js +177 -102
- package/lib/import/modules/personalize.d.ts +11 -4
- package/lib/import/modules/personalize.js +138 -47
- package/lib/import/modules/stack.d.ts +6 -0
- package/lib/import/modules/stack.js +71 -27
- package/lib/import/modules/taxonomies.d.ts +4 -2
- package/lib/import/modules/taxonomies.js +60 -46
- package/lib/import/modules/variant-entries.d.ts +7 -4
- package/lib/import/modules/variant-entries.js +76 -35
- package/lib/import/modules/webhooks.d.ts +3 -0
- package/lib/import/modules/webhooks.js +71 -40
- package/lib/import/modules/workflows.d.ts +3 -0
- package/lib/import/modules/workflows.js +98 -48
- package/lib/types/default-config.d.ts +0 -1
- package/lib/types/import-config.d.ts +0 -1
- package/lib/types/index.d.ts +1 -12
- package/lib/utils/backup-handler.js +1 -2
- package/lib/utils/constants.d.ts +243 -0
- package/lib/utils/constants.js +264 -0
- package/lib/utils/import-config-handler.js +2 -7
- package/lib/utils/import-path-resolver.d.ts +1 -1
- package/lib/utils/import-path-resolver.js +5 -5
- package/lib/utils/index.d.ts +1 -1
- package/lib/utils/index.js +6 -2
- package/lib/utils/marketplace-app-helper.js +3 -8
- package/lib/utils/progress-strategy-registry.d.ts +7 -0
- package/lib/utils/progress-strategy-registry.js +72 -0
- package/lib/utils/setup-branch.js +1 -1
- package/oclif.manifest.json +2 -2
- package/package.json +2 -2
- package/lib/import/modules-js/assets.d.ts +0 -33
- package/lib/import/modules-js/assets.js +0 -428
- package/lib/import/modules-js/content-types.d.ts +0 -34
- package/lib/import/modules-js/content-types.js +0 -204
- package/lib/import/modules-js/custom-roles.d.ts +0 -15
- package/lib/import/modules-js/custom-roles.js +0 -143
- package/lib/import/modules-js/entries.d.ts +0 -54
- package/lib/import/modules-js/entries.js +0 -1280
- package/lib/import/modules-js/environments.d.ts +0 -13
- package/lib/import/modules-js/environments.js +0 -85
- package/lib/import/modules-js/extensions.d.ts +0 -18
- package/lib/import/modules-js/extensions.js +0 -86
- package/lib/import/modules-js/global-fields.d.ts +0 -13
- package/lib/import/modules-js/global-fields.js +0 -106
- package/lib/import/modules-js/index.d.ts +0 -1
- package/lib/import/modules-js/index.js +0 -33
- package/lib/import/modules-js/labels.d.ts +0 -20
- package/lib/import/modules-js/labels.js +0 -148
- package/lib/import/modules-js/locales.d.ts +0 -24
- package/lib/import/modules-js/locales.js +0 -196
- package/lib/import/modules-js/marketplace-apps.d.ts +0 -63
- package/lib/import/modules-js/marketplace-apps.js +0 -429
- package/lib/import/modules-js/webhooks.d.ts +0 -17
- package/lib/import/modules-js/webhooks.js +0 -85
- package/lib/import/modules-js/workflows.d.ts +0 -19
- package/lib/import/modules-js/workflows.js +0 -170
- package/lib/utils/log.d.ts +0 -12
- package/lib/utils/log.js +0 -31
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
export = ContentTypesImport;
|
|
2
|
-
declare class ContentTypesImport {
|
|
3
|
-
constructor(importConfig: any, stackAPIClient: any);
|
|
4
|
-
stackAPIClient: any;
|
|
5
|
-
importConfig: any;
|
|
6
|
-
contentTypeConfig: any;
|
|
7
|
-
globalFieldConfig: any;
|
|
8
|
-
importConcurrency: any;
|
|
9
|
-
writeConcurrency: any;
|
|
10
|
-
contentTypesFolderPath: string;
|
|
11
|
-
mapperFolderPath: string;
|
|
12
|
-
existingContentTypesPath: string;
|
|
13
|
-
globalFieldsFolderPath: string;
|
|
14
|
-
globalFieldMapperFolderPath: string;
|
|
15
|
-
globalFieldPendingPath: string;
|
|
16
|
-
ignoredFilesInContentTypesFolder: Map<string, string>;
|
|
17
|
-
contentTypes: any[];
|
|
18
|
-
existingContentTypesUIds: any[];
|
|
19
|
-
titleToUIdMap: Map<any, any>;
|
|
20
|
-
requestOptions: {
|
|
21
|
-
json: {};
|
|
22
|
-
};
|
|
23
|
-
fieldRules: any[];
|
|
24
|
-
installedExtensions: any[];
|
|
25
|
-
globalFields: any[];
|
|
26
|
-
existingGlobalFields: any[];
|
|
27
|
-
pendingGlobalFields: any[];
|
|
28
|
-
start(): Promise<void>;
|
|
29
|
-
seedContentType(contentType: any): Promise<boolean>;
|
|
30
|
-
updateContentType(contentType: any): Promise<void>;
|
|
31
|
-
updateGlobalFields(uid: any): Promise<boolean>;
|
|
32
|
-
mapUidToTitle(): Promise<void>;
|
|
33
|
-
updateFieldRules(contentType: any): any[];
|
|
34
|
-
}
|
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
const chalk = require('chalk');
|
|
4
|
-
const { cloneDeep, find, findIndex } = require('lodash');
|
|
5
|
-
const { fileHelper, log, executeTask, formatError, schemaTemplate, lookupExtension } = require('../../utils');
|
|
6
|
-
const { sanitizePath } = require('@contentstack/cli-utilities');
|
|
7
|
-
class ContentTypesImport {
|
|
8
|
-
constructor(importConfig, stackAPIClient) {
|
|
9
|
-
this.stackAPIClient = stackAPIClient;
|
|
10
|
-
this.importConfig = importConfig;
|
|
11
|
-
this.contentTypeConfig = importConfig.modules.content_types;
|
|
12
|
-
this.globalFieldConfig = importConfig.modules.globalfields;
|
|
13
|
-
this.importConcurrency = this.contentTypeConfig.importConcurrency || this.importConfig.importConcurrency;
|
|
14
|
-
this.writeConcurrency = this.contentTypeConfig.writeConcurrency || this.importConfig.writeConcurrency;
|
|
15
|
-
this.contentTypesFolderPath = path.join(sanitizePath(this.importConfig.data), sanitizePath(this.contentTypeConfig.dirName));
|
|
16
|
-
this.mapperFolderPath = path.join(sanitizePath(this.importConfig.data), 'mapper', 'content_types');
|
|
17
|
-
this.existingContentTypesPath = path.join(sanitizePath(this.mapperFolderPath), 'success.json');
|
|
18
|
-
this.globalFieldsFolderPath = path.resolve(sanitizePath(this.importConfig.data), sanitizePath(this.globalFieldConfig.dirName));
|
|
19
|
-
this.globalFieldMapperFolderPath = path.join(sanitizePath(importConfig.data), 'mapper', 'global_fields', 'success.json');
|
|
20
|
-
this.globalFieldPendingPath = path.join(sanitizePath(importConfig.data), 'mapper', 'global_fields', 'pending_global_fields.js');
|
|
21
|
-
this.ignoredFilesInContentTypesFolder = new Map([
|
|
22
|
-
['__master.json', 'true'],
|
|
23
|
-
['__priority.json', 'true'],
|
|
24
|
-
['schema.json', 'true'],
|
|
25
|
-
['.DS_Store', 'true'],
|
|
26
|
-
]);
|
|
27
|
-
this.contentTypes = [];
|
|
28
|
-
this.existingContentTypesUIds = [];
|
|
29
|
-
this.titleToUIdMap = new Map();
|
|
30
|
-
this.requestOptions = {
|
|
31
|
-
json: {},
|
|
32
|
-
};
|
|
33
|
-
this.fieldRules = [];
|
|
34
|
-
this.installedExtensions = [];
|
|
35
|
-
this.globalFields = [];
|
|
36
|
-
this.existingGlobalFields = [];
|
|
37
|
-
this.pendingGlobalFields = [];
|
|
38
|
-
}
|
|
39
|
-
async start() {
|
|
40
|
-
try {
|
|
41
|
-
const appMapperPath = path.join(this.importConfig.data, 'mapper', 'marketplace_apps', 'uid-mapping.json');
|
|
42
|
-
this.installedExtensions = ((await fileHelper.readFileSync(appMapperPath)) || { extension_uid: {} }).extension_uid;
|
|
43
|
-
// read content types
|
|
44
|
-
// remove content types already existing
|
|
45
|
-
if (fs.existsSync(this.existingContentTypesPath)) {
|
|
46
|
-
this.existingContentTypesUIds = fileHelper.readFileSync(this.existingContentTypesPath) || [];
|
|
47
|
-
this.existingContentTypesUIds = new Map(this.existingContentTypesUIds.map((id) => [id, 'true']));
|
|
48
|
-
}
|
|
49
|
-
const contentTypeFiles = fileHelper.readdirSync(this.contentTypesFolderPath);
|
|
50
|
-
for (let contentTypeName of contentTypeFiles) {
|
|
51
|
-
if (!this.ignoredFilesInContentTypesFolder.has(contentTypeName)) {
|
|
52
|
-
const contentTypePath = path.join(this.contentTypesFolderPath, contentTypeName);
|
|
53
|
-
const contentType = await fileHelper.readFile(contentTypePath);
|
|
54
|
-
if (!this.existingContentTypesUIds.length || !this.existingContentTypesUIds.has(contentType.uid)) {
|
|
55
|
-
this.contentTypes.push(await fileHelper.readFile(contentTypePath));
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
// seed content type
|
|
60
|
-
log(this.importConfig, 'Started to seed content types', 'info');
|
|
61
|
-
await executeTask(this.contentTypes, this.seedContentType.bind(this), { concurrency: this.importConcurrency });
|
|
62
|
-
log(this.importConfig, 'Created content types', 'success');
|
|
63
|
-
log(this.importConfig, 'Started to update content types with references', 'info');
|
|
64
|
-
await executeTask(this.contentTypes, this.updateContentType.bind(this), { concurrency: this.importConcurrency });
|
|
65
|
-
log(this.importConfig, 'Updated content types with references', 'success');
|
|
66
|
-
// global field update
|
|
67
|
-
this.pendingGlobalFields = fileHelper.readFileSync(this.globalFieldPendingPath);
|
|
68
|
-
if (Array.isArray(this.pendingGlobalFields) && this.pendingGlobalFields.length > 0) {
|
|
69
|
-
this.globalFields = fileHelper.readFileSync(path.resolve(this.globalFieldsFolderPath, this.globalFieldConfig.fileName));
|
|
70
|
-
this.existingGlobalFields = fileHelper.readFileSync(this.globalFieldMapperFolderPath);
|
|
71
|
-
try {
|
|
72
|
-
log(this.importConfig, 'Started to update pending global field with content type references', 'info');
|
|
73
|
-
await executeTask(this.pendingGlobalFields, this.updateGlobalFields.bind(this), {
|
|
74
|
-
concurrency: this.importConcurrency,
|
|
75
|
-
});
|
|
76
|
-
log(this.importConfig, 'Updated pending global fields with content type with references', 'success');
|
|
77
|
-
}
|
|
78
|
-
catch (error) {
|
|
79
|
-
log(this.importConfig, `Failed to updates global fields with content type reference ${formatError(error)}`, 'error');
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
// write field rules
|
|
83
|
-
if (this.fieldRules.length > 0) {
|
|
84
|
-
try {
|
|
85
|
-
await fileHelper.writeFile(path.join(this.contentTypesFolderPath, 'field_rules_uid.json'), this.fieldRules);
|
|
86
|
-
}
|
|
87
|
-
catch (error) {
|
|
88
|
-
log(this.importConfig, `Failed to write field rules ${formatError(error)}`, 'success');
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
log(this.importConfig, chalk.green('Content types imported successfully'), 'success');
|
|
92
|
-
}
|
|
93
|
-
catch (error) {
|
|
94
|
-
let message_content_type = "";
|
|
95
|
-
if (error.request !== undefined && JSON.parse(error.request.data).content_type !== undefined) {
|
|
96
|
-
if (JSON.parse(error.request.data).content_type.uid) {
|
|
97
|
-
message_content_type =
|
|
98
|
-
' Update the content type with content_type_uid - ' + JSON.parse(error.request.data).content_type.uid;
|
|
99
|
-
}
|
|
100
|
-
else if (JSON.parse(error.request.data).content_type.title) {
|
|
101
|
-
message_content_type =
|
|
102
|
-
' Update the content type with content_type_title - ' + JSON.parse(error.request.data).content_type.title;
|
|
103
|
-
}
|
|
104
|
-
error.errorMessage = error.errorMessage + message_content_type;
|
|
105
|
-
}
|
|
106
|
-
log(this.importConfig, formatError(error.errorMessage), 'error');
|
|
107
|
-
log(this.importConfig, formatError(error), 'error');
|
|
108
|
-
throw new Error('Failed to import content types');
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
async seedContentType(contentType) {
|
|
112
|
-
const body = cloneDeep(schemaTemplate);
|
|
113
|
-
body.content_type.uid = contentType.uid;
|
|
114
|
-
body.content_type.title = contentType.title;
|
|
115
|
-
const requestObject = cloneDeep(this.requestOptions);
|
|
116
|
-
requestObject.json = body;
|
|
117
|
-
try {
|
|
118
|
-
await this.stackAPIClient.contentType().create(requestObject.json);
|
|
119
|
-
}
|
|
120
|
-
catch (error) {
|
|
121
|
-
if (error.errorCode === 115 && (error.errors.uid || error.errors.title)) {
|
|
122
|
-
// content type uid already exists
|
|
123
|
-
// _.remove(self.contentTypes, { uid: uid });
|
|
124
|
-
return true;
|
|
125
|
-
}
|
|
126
|
-
throw error;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
async updateContentType(contentType) {
|
|
130
|
-
if (typeof contentType !== 'object')
|
|
131
|
-
return;
|
|
132
|
-
const requestObject = cloneDeep(this.requestOptions);
|
|
133
|
-
if (contentType.field_rules) {
|
|
134
|
-
contentType.field_rules = this.updateFieldRules(contentType);
|
|
135
|
-
if (!contentType.field_rules.length) {
|
|
136
|
-
delete contentType.field_rules;
|
|
137
|
-
}
|
|
138
|
-
this.fieldRules.push(contentType.uid);
|
|
139
|
-
}
|
|
140
|
-
lookupExtension(this.importConfig, contentType.schema, this.importConfig.preserveStackVersion, this.installedExtensions);
|
|
141
|
-
requestObject.json.content_type = contentType;
|
|
142
|
-
const contentTypeResponse = this.stackAPIClient.contentType(contentType.uid);
|
|
143
|
-
Object.assign(contentTypeResponse, cloneDeep(contentType));
|
|
144
|
-
await contentTypeResponse.update();
|
|
145
|
-
log(this.importConfig, contentType.uid + ' updated with references', 'success');
|
|
146
|
-
}
|
|
147
|
-
async updateGlobalFields(uid) {
|
|
148
|
-
const globalField = find(this.globalFields, { uid });
|
|
149
|
-
if (globalField) {
|
|
150
|
-
lookupExtension(this.importConfig, globalField.schema, this.importConfig.preserveStackVersion, this.installedExtensions);
|
|
151
|
-
let globalFieldObj = this.stackAPIClient.globalField(globalField.uid);
|
|
152
|
-
Object.assign(globalFieldObj, cloneDeep(globalField));
|
|
153
|
-
try {
|
|
154
|
-
const globalFieldResponse = await globalFieldObj.update();
|
|
155
|
-
const existingGlobalField = findIndex(this.existingGlobalFields, (existingGlobalFieldUId) => {
|
|
156
|
-
return globalFieldResponse.uid === existingGlobalFieldUId;
|
|
157
|
-
});
|
|
158
|
-
// Improve write the updated global fields once all updates are completed
|
|
159
|
-
this.existingGlobalFields.splice(existingGlobalField, 1, globalField);
|
|
160
|
-
await fileHelper.writeFile(this.globalFieldMapperFolderPath, this.existingGlobalFields).catch((error) => {
|
|
161
|
-
log(this.importConfig, `failed to write updated the global field ${uid} ${formatError(error)}`);
|
|
162
|
-
});
|
|
163
|
-
log(this.importConfig, `Updated the global field ${uid} with content type references `);
|
|
164
|
-
return true;
|
|
165
|
-
}
|
|
166
|
-
catch (error) {
|
|
167
|
-
log(this.importConfig, `failed to update the global field ${uid} ${formatError(error)}`);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
else {
|
|
171
|
-
log(this.importConfig, `Global field ${uid} does not exist, and hence failed to update.`);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
async mapUidToTitle() {
|
|
175
|
-
this.contentTypes.forEach((ct) => {
|
|
176
|
-
this.titleToUIdMap.set(ct.uid, ct.title);
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
updateFieldRules(contentType) {
|
|
180
|
-
const fieldDataTypeMap = {};
|
|
181
|
-
for (let i = 0; i < contentType.schema.length; i++) {
|
|
182
|
-
const field = contentType.schema[i];
|
|
183
|
-
fieldDataTypeMap[field.uid] = field.data_type;
|
|
184
|
-
}
|
|
185
|
-
const fieldRules = [...contentType.field_rules];
|
|
186
|
-
let len = fieldRules.length;
|
|
187
|
-
// Looping backwards as we need to delete elements as we move.
|
|
188
|
-
for (let i = len - 1; i >= 0; i--) {
|
|
189
|
-
const conditions = fieldRules[i].conditions;
|
|
190
|
-
let isReference = false;
|
|
191
|
-
for (let j = 0; j < conditions.length; j++) {
|
|
192
|
-
const field = conditions[j].operand_field;
|
|
193
|
-
if (fieldDataTypeMap[field] === 'reference') {
|
|
194
|
-
isReference = true;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
if (isReference) {
|
|
198
|
-
fieldRules.splice(i, 1);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
return fieldRules;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
module.exports = ContentTypesImport;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export = ImportCustomRoles;
|
|
2
|
-
declare class ImportCustomRoles {
|
|
3
|
-
constructor(importConfig: any, stackAPIClient: any);
|
|
4
|
-
fails: any[];
|
|
5
|
-
labelUids: any[];
|
|
6
|
-
customRolesUidMapper: {};
|
|
7
|
-
customRolesConfig: {
|
|
8
|
-
dirName: string;
|
|
9
|
-
fileName: string;
|
|
10
|
-
customRolesLocalesFileName: string;
|
|
11
|
-
};
|
|
12
|
-
config: any;
|
|
13
|
-
stackAPIClient: any;
|
|
14
|
-
start(): Promise<void>;
|
|
15
|
-
}
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
const mkdirp = require('mkdirp');
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
const path = require('path');
|
|
5
|
-
const chalk = require('chalk');
|
|
6
|
-
const { merge } = require('lodash');
|
|
7
|
-
const { fileHelper, log, formatError } = require('../../utils');
|
|
8
|
-
let { default: config } = require('../../config');
|
|
9
|
-
module.exports = class ImportCustomRoles {
|
|
10
|
-
constructor(importConfig, stackAPIClient) {
|
|
11
|
-
this.fails = [];
|
|
12
|
-
this.labelUids = [];
|
|
13
|
-
this.customRolesUidMapper = {};
|
|
14
|
-
this.customRolesConfig = config.modules.customRoles;
|
|
15
|
-
this.config = merge(config, importConfig);
|
|
16
|
-
this.stackAPIClient = stackAPIClient;
|
|
17
|
-
}
|
|
18
|
-
async start() {
|
|
19
|
-
const self = this;
|
|
20
|
-
log(this.config, chalk.white('Migrating custom-roles'), 'success');
|
|
21
|
-
let customRolesFolderPath = path.resolve(this.config.data, this.customRolesConfig.dirName);
|
|
22
|
-
let customRolesMapperPath = path.resolve(this.config.data, 'mapper', 'custom-roles');
|
|
23
|
-
let entriesUidMapperFolderPath = path.resolve(this.config.data, 'mapper', 'entries');
|
|
24
|
-
let customRolesFailsPath = path.resolve(this.config.data, 'custom-roles', 'fails.json');
|
|
25
|
-
let environmentsUidMapperFolderPath = path.resolve(this.config.data, 'mapper', 'environments');
|
|
26
|
-
let customRolesUidMapperPath = path.resolve(this.config.data, 'mapper', 'custom-roles', 'uid-mapping.json');
|
|
27
|
-
let customRolesLocalesFilePath = path.resolve(customRolesFolderPath, this.customRolesConfig.customRolesLocalesFileName);
|
|
28
|
-
try {
|
|
29
|
-
self.customRoles = fileHelper.readFileSync(path.resolve(customRolesFolderPath, this.customRolesConfig.fileName));
|
|
30
|
-
self.customRolesLocales = fileHelper.readFileSync(customRolesLocalesFilePath);
|
|
31
|
-
// Mapper file paths.
|
|
32
|
-
if (fs.existsSync(customRolesMapperPath)) {
|
|
33
|
-
this.customRolesUidMapper = fileHelper.readFileSync(customRolesUidMapperPath) || {};
|
|
34
|
-
}
|
|
35
|
-
mkdirp.sync(customRolesMapperPath);
|
|
36
|
-
if (!self.customRoles) {
|
|
37
|
-
log(self.config, chalk.white('No custom-roles found'), 'info');
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
self.customRolesUids = Object.keys(self.customRoles);
|
|
41
|
-
self.localesUidMap = await getLocalesUidMap(self.stackAPIClient, self.config, self.customRolesLocales);
|
|
42
|
-
self.environmentsUidMap = {};
|
|
43
|
-
if (fs.existsSync(environmentsUidMapperFolderPath)) {
|
|
44
|
-
self.environmentsUidMap = fileHelper.readFileSync(path.resolve(environmentsUidMapperFolderPath, 'uid-mapping.json'));
|
|
45
|
-
}
|
|
46
|
-
self.entriesUidMap = {};
|
|
47
|
-
if (fs.existsSync(entriesUidMapperFolderPath)) {
|
|
48
|
-
self.entriesUidMap = fileHelper.readFileSync(path.resolve(entriesUidMapperFolderPath, 'uid-mapping.json'));
|
|
49
|
-
}
|
|
50
|
-
for (const uid of self.customRolesUids) {
|
|
51
|
-
const customRole = self.customRoles[uid];
|
|
52
|
-
if (uid in self.customRolesUidMapper) {
|
|
53
|
-
log(self.config, chalk.white(`The custom-role '${customRole.name}' already exists. Skipping it to avoid duplicates!`), 'success');
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
56
|
-
try {
|
|
57
|
-
customRole.rules.forEach((rule) => {
|
|
58
|
-
const transformUids = getTransformUidsFactory(rule);
|
|
59
|
-
rule = transformUids(rule, self.environmentsUidMap, self.localesUidMap, self.entriesUidMap);
|
|
60
|
-
});
|
|
61
|
-
// rules.branch is required to create custom roles.
|
|
62
|
-
const branchRuleExists = customRole.rules.find((rule) => rule.module === 'branch');
|
|
63
|
-
if (!branchRuleExists) {
|
|
64
|
-
customRole.rules.push({
|
|
65
|
-
module: 'branch',
|
|
66
|
-
branches: ['main'],
|
|
67
|
-
acl: { read: true },
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
const role = await self.stackAPIClient.role().create({ role: customRole });
|
|
71
|
-
self.customRolesUidMapper[uid] = role;
|
|
72
|
-
fileHelper.writeFileSync(customRolesUidMapperPath, self.customRolesUidMapper);
|
|
73
|
-
}
|
|
74
|
-
catch (error) {
|
|
75
|
-
self.fails.push(customRole);
|
|
76
|
-
if (((error && error.errors && error.errors.name) || '').includes('is not a unique.')) {
|
|
77
|
-
log(self.config, `custom-role '${customRole.name}' already exists`, 'info');
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
if (!(error && error.errors && error.errors.name)) {
|
|
81
|
-
log(self.config, `custom-role: ${customRole.name} already exists`, 'error');
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
log(self.config, `custom-role: ${customRole.name} failed`, 'error');
|
|
85
|
-
}
|
|
86
|
-
log(self.config, formatError(error), 'error');
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
log(self.config, chalk.green('Custom-roles have been imported successfully!'), 'success');
|
|
91
|
-
}
|
|
92
|
-
catch (error) {
|
|
93
|
-
fileHelper.writeFileSync(customRolesFailsPath, self.fails);
|
|
94
|
-
log(self.config, 'Custom-roles import failed', 'error');
|
|
95
|
-
log(self.config, formatError(error), 'error');
|
|
96
|
-
throw error;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
const getTransformUidsFactory = (rule) => {
|
|
101
|
-
if (rule.module === 'environment') {
|
|
102
|
-
return environmentUidTransformer;
|
|
103
|
-
}
|
|
104
|
-
else if (rule.module === 'locale') {
|
|
105
|
-
return localeUidTransformer;
|
|
106
|
-
}
|
|
107
|
-
else if (rule.module === 'entry') {
|
|
108
|
-
return entryUidTransformer;
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
return noopTransformer;
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
const environmentUidTransformer = (rule, environmentsUidMap) => {
|
|
115
|
-
rule.environments = rule.environments.map((env) => environmentsUidMap[env]);
|
|
116
|
-
return rule;
|
|
117
|
-
};
|
|
118
|
-
const localeUidTransformer = (rule, environmentsUidMap, localesUidMap) => {
|
|
119
|
-
rule.locales = rule.locales.map((locale) => localesUidMap[locale]);
|
|
120
|
-
return rule;
|
|
121
|
-
};
|
|
122
|
-
const entryUidTransformer = (rule, environmentsUidMap, localesUidMap, entriesUidMap) => {
|
|
123
|
-
rule.entries = rule.entries.map((entry) => entriesUidMap[entry]);
|
|
124
|
-
return rule;
|
|
125
|
-
};
|
|
126
|
-
const noopTransformer = (rule) => {
|
|
127
|
-
return rule;
|
|
128
|
-
};
|
|
129
|
-
const getLocalesUidMap = async (stackAPIClient, config, sourceLocales) => {
|
|
130
|
-
const { items } = await stackAPIClient.locale().query().find();
|
|
131
|
-
const [targetLocalesMap, sourceLocalesMap] = [{}, {}];
|
|
132
|
-
items.forEach((locale) => {
|
|
133
|
-
targetLocalesMap[locale.code] = locale.uid;
|
|
134
|
-
});
|
|
135
|
-
for (const key in sourceLocales) {
|
|
136
|
-
sourceLocalesMap[sourceLocales[key].code] = key;
|
|
137
|
-
}
|
|
138
|
-
const localesUidMap = {};
|
|
139
|
-
for (const key in sourceLocalesMap) {
|
|
140
|
-
localesUidMap[sourceLocalesMap[key]] = targetLocalesMap[key];
|
|
141
|
-
}
|
|
142
|
-
return localesUidMap;
|
|
143
|
-
};
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
export = ImportEntries;
|
|
2
|
-
declare class ImportEntries {
|
|
3
|
-
constructor(importConfig: any, stackAPIClient: any);
|
|
4
|
-
mappedAssetUidPath: string;
|
|
5
|
-
mappedAssetUrlPath: string;
|
|
6
|
-
entryMapperPath: string;
|
|
7
|
-
environmentPath: string;
|
|
8
|
-
entryUidMapperPath: string;
|
|
9
|
-
uniqueUidMapperPath: string;
|
|
10
|
-
modifiedSchemaPath: string;
|
|
11
|
-
createdEntriesWOUidPath: string;
|
|
12
|
-
failedWOPath: string;
|
|
13
|
-
masterLanguage: any;
|
|
14
|
-
reqConcurrency: any;
|
|
15
|
-
eConfig: any;
|
|
16
|
-
ePath: string;
|
|
17
|
-
ctPath: string;
|
|
18
|
-
lPath: string;
|
|
19
|
-
importConcurrency: any;
|
|
20
|
-
skipFiles: string[];
|
|
21
|
-
config: any;
|
|
22
|
-
stackAPIClient: any;
|
|
23
|
-
ctSchemas: {};
|
|
24
|
-
refSchemas: any[];
|
|
25
|
-
ctJsonRte: any[];
|
|
26
|
-
ctJsonRteWithEntryRefs: any[];
|
|
27
|
-
jsonRteEntryRefs: {};
|
|
28
|
-
createdEntriesWOUid: any[];
|
|
29
|
-
uniqueUids: {};
|
|
30
|
-
mappedUids: {};
|
|
31
|
-
success: any[];
|
|
32
|
-
fails: any[];
|
|
33
|
-
installedExtensions: any[];
|
|
34
|
-
environment: any;
|
|
35
|
-
start(): globalThis.Promise<any>;
|
|
36
|
-
createEntries(lang: any, mappedAssetUids: any, mappedAssetUrls: any): Promise<any>;
|
|
37
|
-
getCreatedEntriesWOUid(): Promise<any>;
|
|
38
|
-
repostEntries(lang: any): Promise<any>;
|
|
39
|
-
supressFields(): Promise<any>;
|
|
40
|
-
fetchEntry(query: any): Promise<any>;
|
|
41
|
-
unSuppressFields(): Promise<any>;
|
|
42
|
-
removeBuggedEntries(): Promise<any>;
|
|
43
|
-
field_rules_update(schema: any): Promise<any>;
|
|
44
|
-
publish(langs: any): Promise<any>;
|
|
45
|
-
removeEntryRefsFromJSONRTE(entry: any, ctSchema: any): any;
|
|
46
|
-
doEntryReferencesExist(element: any): any;
|
|
47
|
-
restoreJsonRteEntryRefs(entry: any, sourceStackEntry: any, ctSchema: any): any;
|
|
48
|
-
isEntryRef(element: any): boolean;
|
|
49
|
-
removeUidsFromJsonRteFields(entry: any, ctSchema: any): any;
|
|
50
|
-
removeUidsFromChildren(children: any): any;
|
|
51
|
-
setDirtyTrue(jsonRteChild: any): any;
|
|
52
|
-
resolveAssetRefsInEntryRefsForJsonRte(jsonRteChild: any, mappedAssetUids: any, mappedAssetUrls: any): any;
|
|
53
|
-
}
|
|
54
|
-
import Promise = require("bluebird");
|