@contentstack/cli-cm-import 1.5.11 → 1.7.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 +6 -14
- package/bin/dev +17 -0
- package/bin/dev.cmd +3 -0
- package/bin/run +6 -0
- package/bin/run.cmd +3 -0
- package/lib/commands/cm/stacks/import.d.ts +10 -0
- package/lib/commands/cm/stacks/import.js +111 -0
- package/lib/config/index.d.ts +3 -0
- package/lib/config/index.js +395 -0
- package/lib/import/index.d.ts +1 -0
- package/lib/import/index.js +8 -0
- package/lib/import/module-importer.d.ts +13 -0
- package/lib/import/module-importer.js +70 -0
- package/lib/import/modules/assets.d.ts +63 -0
- package/lib/import/modules/assets.js +265 -0
- package/lib/import/modules/base-class.d.ts +70 -0
- package/lib/import/modules/base-class.js +218 -0
- package/lib/import/modules/content-types.d.ts +56 -0
- package/lib/import/modules/content-types.js +186 -0
- package/lib/import/modules/custom-roles.d.ts +37 -0
- package/lib/import/modules/custom-roles.js +171 -0
- package/lib/import/modules/environments.d.ts +27 -0
- package/lib/import/modules/environments.js +106 -0
- package/lib/import/modules/extensions.d.ts +27 -0
- package/lib/import/modules/extensions.js +106 -0
- package/lib/import/modules/global-fields.d.ts +34 -0
- package/lib/import/modules/global-fields.js +99 -0
- package/lib/import/modules/index.d.ts +2 -0
- package/lib/import/modules/index.js +19 -0
- package/lib/import/modules/labels.d.ts +34 -0
- package/lib/import/modules/labels.js +171 -0
- package/lib/import/modules/locales.d.ts +31 -0
- package/lib/import/modules/locales.js +144 -0
- package/lib/import/modules/marketplace-apps.d.ts +51 -0
- package/lib/import/modules/marketplace-apps.js +297 -0
- package/lib/import/modules/webhooks.d.ts +27 -0
- package/lib/import/modules/webhooks.js +110 -0
- package/lib/import/modules-js/assets.d.ts +33 -0
- package/lib/import/modules-js/assets.js +415 -0
- package/lib/import/modules-js/content-types.d.ts +33 -0
- package/lib/import/modules-js/content-types.js +176 -0
- package/lib/import/modules-js/custom-roles.d.ts +15 -0
- package/lib/import/modules-js/custom-roles.js +143 -0
- package/lib/import/modules-js/entries.d.ts +54 -0
- package/lib/import/modules-js/entries.js +1260 -0
- package/lib/import/modules-js/environments.d.ts +13 -0
- package/lib/import/modules-js/environments.js +85 -0
- package/lib/import/modules-js/extensions.d.ts +18 -0
- package/lib/import/modules-js/extensions.js +86 -0
- package/lib/import/modules-js/global-fields.d.ts +13 -0
- package/lib/import/modules-js/global-fields.js +109 -0
- package/lib/import/modules-js/index.d.ts +1 -0
- package/lib/import/modules-js/index.js +33 -0
- package/lib/import/modules-js/labels.d.ts +20 -0
- package/lib/import/modules-js/labels.js +148 -0
- package/lib/import/modules-js/locales.d.ts +24 -0
- package/lib/import/modules-js/locales.js +196 -0
- package/lib/import/modules-js/marketplace-apps.d.ts +60 -0
- package/lib/import/modules-js/marketplace-apps.js +409 -0
- package/lib/import/modules-js/webhooks.d.ts +17 -0
- package/lib/import/modules-js/webhooks.js +85 -0
- package/lib/import/modules-js/workflows.d.ts +18 -0
- package/lib/import/modules-js/workflows.js +132 -0
- package/lib/types/default-config.d.ts +143 -0
- package/lib/types/default-config.js +2 -0
- package/lib/types/import-config.d.ts +52 -0
- package/lib/types/import-config.js +2 -0
- package/lib/types/index.d.ts +63 -0
- package/lib/types/index.js +4 -0
- package/lib/utils/asset-helper.d.ts +4 -0
- package/lib/utils/asset-helper.js +387 -0
- package/lib/utils/backup-handler.d.ts +2 -0
- package/lib/utils/backup-handler.js +31 -0
- package/lib/utils/common-helper.d.ts +20 -0
- package/lib/utils/common-helper.js +244 -0
- package/lib/utils/content-type-helper.d.ts +51 -0
- package/lib/utils/content-type-helper.js +145 -0
- package/lib/utils/entries-helper.d.ts +4 -0
- package/lib/utils/entries-helper.js +252 -0
- package/lib/utils/extension-helper.d.ts +5 -0
- package/lib/utils/extension-helper.js +84 -0
- package/lib/utils/file-helper.d.ts +14 -0
- package/lib/utils/file-helper.js +140 -0
- package/lib/utils/import-config-handler.d.ts +3 -0
- package/lib/utils/import-config-handler.js +73 -0
- package/lib/utils/index.d.ts +12 -0
- package/lib/utils/index.js +39 -0
- package/lib/utils/interactive.d.ts +7 -0
- package/lib/utils/interactive.js +88 -0
- package/lib/utils/logger.d.ts +8 -0
- package/lib/utils/logger.js +154 -0
- package/lib/utils/login-handler.d.ts +8 -0
- package/lib/utils/login-handler.js +53 -0
- package/lib/utils/marketplace-app-helper.d.ts +16 -0
- package/lib/utils/marketplace-app-helper.js +143 -0
- package/messages/index.json +1 -7
- package/oclif.manifest.json +2 -2
- package/package.json +46 -20
- package/src/app.js +0 -217
- package/src/commands/cm/stacks/import.js +0 -161
- package/src/config/default.js +0 -352
- package/src/lib/import/assets.js +0 -495
- package/src/lib/import/content-types.js +0 -201
- package/src/lib/import/custom-roles.js +0 -169
- package/src/lib/import/entries.js +0 -1495
- package/src/lib/import/environments.js +0 -106
- package/src/lib/import/extensions.js +0 -108
- package/src/lib/import/global-fields.js +0 -135
- package/src/lib/import/labels.js +0 -175
- package/src/lib/import/locales.js +0 -216
- package/src/lib/import/marketplace-apps.js +0 -542
- package/src/lib/import/webhooks.js +0 -113
- package/src/lib/import/workflows.js +0 -166
- package/src/lib/util/extensionsUidReplace.js +0 -67
- package/src/lib/util/fs.js +0 -124
- package/src/lib/util/import-flags.js +0 -187
- package/src/lib/util/index.js +0 -222
- package/src/lib/util/log.js +0 -144
- package/src/lib/util/login.js +0 -58
- package/src/lib/util/lookupReplaceAssets.js +0 -366
- package/src/lib/util/lookupReplaceEntries.js +0 -250
- package/src/lib/util/marketplace-app-helper.js +0 -31
- package/src/lib/util/removeReferenceFields.js +0 -59
- package/src/lib/util/schemaTemplate.js +0 -38
- package/src/lib/util/supress-mandatory-fields.js +0 -34
- package/src/lib/util/upload.js +0 -56
|
@@ -0,0 +1,143 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
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");
|