@contentstack/cli-cm-import 1.5.10 → 1.6.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 +372 -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 +69 -0
- package/lib/import/modules/base-class.js +165 -0
- package/lib/import/modules/index.d.ts +2 -0
- package/lib/import/modules/index.js +19 -0
- package/lib/import/modules/locales.d.ts +31 -0
- package/lib/import/modules/locales.js +152 -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 +141 -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 +17 -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 +130 -0
- package/lib/types/default-config.js +2 -0
- package/lib/types/import-config.d.ts +51 -0
- package/lib/types/import-config.js +2 -0
- package/lib/types/index.d.ts +30 -0
- package/lib/types/index.js +2 -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 +49 -0
- package/lib/utils/content-type-helper.js +143 -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 +10 -0
- package/lib/utils/extension-helper.js +72 -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 +29 -0
- package/lib/utils/interactive.d.ts +2 -0
- package/lib/utils/interactive.js +23 -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 +4 -0
- package/lib/utils/marketplace-app-helper.js +31 -0
- package/messages/index.json +1 -7
- package/oclif.manifest.json +2 -2
- package/package.json +47 -21
- 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 -1480
- 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
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const mkdirp = require('mkdirp');
|
|
4
|
-
const fs = require('fs');
|
|
5
|
-
const path = require('path');
|
|
6
|
-
const chalk = require('chalk');
|
|
7
|
-
const { merge } = require('lodash');
|
|
8
|
-
|
|
9
|
-
const helper = require('../util/fs');
|
|
10
|
-
const { addlogs } = require('../util/log');
|
|
11
|
-
const { formatError } = require('../util');
|
|
12
|
-
let config = require('../../config/default');
|
|
13
|
-
|
|
14
|
-
module.exports = class ImportCustomRoles {
|
|
15
|
-
fails = [];
|
|
16
|
-
labelUids = [];
|
|
17
|
-
customRolesUidMapper = {};
|
|
18
|
-
customRolesConfig = config.modules.customRoles;
|
|
19
|
-
|
|
20
|
-
constructor(importConfig, stackAPIClient) {
|
|
21
|
-
this.config = merge(config, importConfig);
|
|
22
|
-
this.stackAPIClient = stackAPIClient;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
async start() {
|
|
26
|
-
const self = this;
|
|
27
|
-
addlogs(this.config, chalk.white('Migrating custom-roles'), 'success');
|
|
28
|
-
|
|
29
|
-
let customRolesFolderPath = path.resolve(this.config.data, this.customRolesConfig.dirName);
|
|
30
|
-
let customRolesMapperPath = path.resolve(this.config.data, 'mapper', 'custom-roles');
|
|
31
|
-
let entriesUidMapperFolderPath = path.resolve(this.config.data, 'mapper', 'entries');
|
|
32
|
-
let customRolesFailsPath = path.resolve(this.config.data, 'custom-roles', 'fails.json');
|
|
33
|
-
let environmentsUidMapperFolderPath = path.resolve(this.config.data, 'mapper', 'environments');
|
|
34
|
-
let customRolesUidMapperPath = path.resolve(this.config.data, 'mapper', 'custom-roles', 'uid-mapping.json');
|
|
35
|
-
let customRolesLocalesFilePath = path.resolve(
|
|
36
|
-
customRolesFolderPath,
|
|
37
|
-
this.customRolesConfig.customRolesLocalesFileName,
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
try {
|
|
41
|
-
self.customRoles = helper.readFileSync(path.resolve(customRolesFolderPath, this.customRolesConfig.fileName));
|
|
42
|
-
self.customRolesLocales = helper.readFileSync(customRolesLocalesFilePath);
|
|
43
|
-
// Mapper file paths.
|
|
44
|
-
|
|
45
|
-
if (fs.existsSync(customRolesMapperPath)) {
|
|
46
|
-
this.customRolesUidMapper = helper.readFileSync(customRolesUidMapperPath) || {};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
mkdirp.sync(customRolesMapperPath);
|
|
50
|
-
|
|
51
|
-
if (!self.customRoles) {
|
|
52
|
-
addlogs(self.config, chalk.white('No custom-roles found'), 'info');
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
self.customRolesUids = Object.keys(self.customRoles);
|
|
56
|
-
|
|
57
|
-
self.localesUidMap = await getLocalesUidMap(self.stackAPIClient, self.config, self.customRolesLocales);
|
|
58
|
-
|
|
59
|
-
if (fs.existsSync(environmentsUidMapperFolderPath)) {
|
|
60
|
-
self.environmentsUidMap = helper.readFileSync(
|
|
61
|
-
path.resolve(environmentsUidMapperFolderPath, 'uid-mapping.json'),
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
if (fs.existsSync(entriesUidMapperFolderPath)) {
|
|
65
|
-
self.entriesUidMap = helper.readFileSync(path.resolve(entriesUidMapperFolderPath, 'uid-mapping.json'));
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
for (const uid of self.customRolesUids) {
|
|
69
|
-
const customRole = self.customRoles[uid];
|
|
70
|
-
|
|
71
|
-
if (uid in self.customRolesUidMapper) {
|
|
72
|
-
addlogs(
|
|
73
|
-
self.config,
|
|
74
|
-
chalk.white(`The custom-role '${customRole.name}' already exists. Skipping it to avoid duplicates!`),
|
|
75
|
-
'success',
|
|
76
|
-
);
|
|
77
|
-
continue;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
try {
|
|
81
|
-
customRole.rules.forEach((rule) => {
|
|
82
|
-
const transformUids = getTransformUidsFactory(rule);
|
|
83
|
-
rule = transformUids(rule, self.environmentsUidMap, self.localesUidMap, self.entriesUidMap);
|
|
84
|
-
});
|
|
85
|
-
// rules.branch is required to create custom roles.
|
|
86
|
-
const branchRuleExists = customRole.rules.find((rule) => rule.module === 'branch');
|
|
87
|
-
if (!branchRuleExists) {
|
|
88
|
-
customRole.rules.push({
|
|
89
|
-
module: 'branch',
|
|
90
|
-
branches: ['main'],
|
|
91
|
-
acl: { read: true },
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
const role = await self.stackAPIClient.role().create({ role: customRole });
|
|
95
|
-
self.customRolesUidMapper[uid] = role;
|
|
96
|
-
helper.writeFileSync(customRolesUidMapperPath, self.customRolesUidMapper);
|
|
97
|
-
} catch (error) {
|
|
98
|
-
self.fails.push(customRole);
|
|
99
|
-
|
|
100
|
-
if (((error && error.errors && error.errors.name) || '').includes('is not a unique.')) {
|
|
101
|
-
addlogs(self.config, `custom-role '${customRole.name}' already exists`, 'error');
|
|
102
|
-
} else {
|
|
103
|
-
if (!(error && error.errors && error.errors.name)) {
|
|
104
|
-
addlogs(self.config, `custom-role '${customRole.name}' already exists`, 'error');
|
|
105
|
-
} else {
|
|
106
|
-
addlogs(self.config, `custom-role '${customRole.name}' failed`, 'error');
|
|
107
|
-
}
|
|
108
|
-
addlogs(self.config, formatError(error), 'error');
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
addlogs(self.config, chalk.green('Custom-roles have been imported successfully!'), 'success');
|
|
113
|
-
} catch (error) {
|
|
114
|
-
helper.writeFileSync(customRolesFailsPath, self.fails);
|
|
115
|
-
addlogs(self.config, 'Custom-roles import failed', 'error');
|
|
116
|
-
addlogs(self.config, formatError(error), 'error');
|
|
117
|
-
|
|
118
|
-
throw error;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
const getTransformUidsFactory = (rule) => {
|
|
124
|
-
if (rule.module === 'environment') {
|
|
125
|
-
return environmentUidTransformer;
|
|
126
|
-
} else if (rule.module === 'locale') {
|
|
127
|
-
return localeUidTransformer;
|
|
128
|
-
} else if (rule.module === 'entry') {
|
|
129
|
-
return entryUidTransformer;
|
|
130
|
-
} else {
|
|
131
|
-
return noopTransformer;
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
const environmentUidTransformer = (rule, environmentsUidMap) => {
|
|
136
|
-
rule.environments = rule.environments.map((env) => environmentsUidMap[env]);
|
|
137
|
-
return rule;
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
const localeUidTransformer = (rule, environmentsUidMap, localesUidMap) => {
|
|
141
|
-
rule.locales = rule.locales.map((locale) => localesUidMap[locale]);
|
|
142
|
-
return rule;
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
const entryUidTransformer = (rule, environmentsUidMap, localesUidMap, entriesUidMap) => {
|
|
146
|
-
rule.entries = rule.entries.map((entry) => entriesUidMap[entry]);
|
|
147
|
-
return rule;
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
const noopTransformer = (rule) => {
|
|
151
|
-
return rule;
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
const getLocalesUidMap = async (stackAPIClient, config, sourceLocales) => {
|
|
155
|
-
const { items } = await stackAPIClient.locale().query().find();
|
|
156
|
-
const [targetLocalesMap, sourceLocalesMap] = [{}, {}];
|
|
157
|
-
|
|
158
|
-
items.forEach((locale) => {
|
|
159
|
-
targetLocalesMap[locale.code] = locale.uid;
|
|
160
|
-
});
|
|
161
|
-
for (const key in sourceLocales) {
|
|
162
|
-
sourceLocalesMap[sourceLocales[key].code] = key;
|
|
163
|
-
}
|
|
164
|
-
const localesUidMap = {};
|
|
165
|
-
for (const key in sourceLocalesMap) {
|
|
166
|
-
localesUidMap[sourceLocalesMap[key]] = targetLocalesMap[key];
|
|
167
|
-
}
|
|
168
|
-
return localesUidMap;
|
|
169
|
-
};
|