@contentstack/cli-cm-import 1.28.1 → 2.0.1-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.js +6 -20
- 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 +0 -1
- package/lib/utils/constants.d.ts +243 -0
- package/lib/utils/constants.js +264 -0
- package/lib/utils/import-config-handler.js +2 -0
- package/lib/utils/import-path-resolver.js +3 -13
- 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 +78 -0
- package/lib/utils/setup-branch.js +1 -1
- package/oclif.manifest.json +2 -2
- package/package.json +3 -3
- 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,170 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Contentstack Import
|
|
3
|
-
* Copyright (c) 2024 Contentstack LLC
|
|
4
|
-
* MIT Licensed
|
|
5
|
-
*/
|
|
6
|
-
const fs = require('fs');
|
|
7
|
-
const path = require('path');
|
|
8
|
-
const chalk = require('chalk');
|
|
9
|
-
const mkdirp = require('mkdirp');
|
|
10
|
-
const Promise = require('bluebird');
|
|
11
|
-
const { isEmpty, merge, filter, map, cloneDeep, find } = require('lodash');
|
|
12
|
-
let { default: config } = require('../../config');
|
|
13
|
-
const { fileHelper, log, formatError } = require('../../utils');
|
|
14
|
-
module.exports = class importWorkflows {
|
|
15
|
-
constructor(importConfig, stackAPIClient) {
|
|
16
|
-
this.fails = [];
|
|
17
|
-
this.success = [];
|
|
18
|
-
this.workflowUidMapper = {};
|
|
19
|
-
this.workflowConfig = config.modules.workflows;
|
|
20
|
-
this.reqConcurrency = config.concurrency || config.fetchConcurrency || 1;
|
|
21
|
-
this.config = merge(config, importConfig);
|
|
22
|
-
this.stackAPIClient = stackAPIClient;
|
|
23
|
-
}
|
|
24
|
-
start() {
|
|
25
|
-
log(this.config, chalk.white('Migrating workflows'), 'success');
|
|
26
|
-
let self = this;
|
|
27
|
-
let workflowMapperPath = path.resolve(this.config.data, 'mapper', 'workflows');
|
|
28
|
-
let workflowFailsPath = path.resolve(this.config.data, 'workflows', 'fails.json');
|
|
29
|
-
let workflowSuccessPath = path.resolve(this.config.data, 'workflows', 'success.json');
|
|
30
|
-
let workflowUidMapperPath = path.resolve(this.config.data, 'mapper', 'workflows', 'uid-mapping.json');
|
|
31
|
-
let workflowFolderPath = path.resolve(this.config.data, this.workflowConfig.dirName);
|
|
32
|
-
self.workflows = fileHelper.readFileSync(path.resolve(workflowFolderPath, this.workflowConfig.fileName));
|
|
33
|
-
if (fs.existsSync(workflowUidMapperPath)) {
|
|
34
|
-
this.workflowUidMapper = fileHelper.readFileSync(workflowUidMapperPath);
|
|
35
|
-
this.workflowUidMapper = this.workflowUidMapper || {};
|
|
36
|
-
}
|
|
37
|
-
mkdirp.sync(workflowMapperPath);
|
|
38
|
-
return new Promise(function (resolve, reject) {
|
|
39
|
-
if (self.workflows == undefined || isEmpty(self.workflows)) {
|
|
40
|
-
log(self.config, chalk.white('No workflow Found'), 'success');
|
|
41
|
-
return resolve({ empty: true });
|
|
42
|
-
}
|
|
43
|
-
self.workflowsUids = Object.keys(self.workflows);
|
|
44
|
-
return Promise.map(self.workflowsUids, async function (workflowUid) {
|
|
45
|
-
let workflow = self.workflows[workflowUid];
|
|
46
|
-
if (!self.workflowUidMapper.hasOwnProperty(workflowUid)) {
|
|
47
|
-
const roleNameMap = {};
|
|
48
|
-
const workflowStages = workflow.workflow_stages;
|
|
49
|
-
const oldWorkflowStages = cloneDeep(workflow.workflow_stages);
|
|
50
|
-
const roles = await self.stackAPIClient.role().fetchAll();
|
|
51
|
-
for (const role of roles.items) {
|
|
52
|
-
roleNameMap[role.name] = role.uid;
|
|
53
|
-
}
|
|
54
|
-
for (const stage of workflowStages) {
|
|
55
|
-
delete stage.uid;
|
|
56
|
-
if (!isEmpty(stage.next_available_stages)) {
|
|
57
|
-
stage.next_available_stages = ['$all'];
|
|
58
|
-
}
|
|
59
|
-
if (stage.SYS_ACL.users.uids.length && stage.SYS_ACL.users.uids[0] !== '$all') {
|
|
60
|
-
stage.SYS_ACL.users.uids = ['$all'];
|
|
61
|
-
}
|
|
62
|
-
if (stage.SYS_ACL.roles.uids.length) {
|
|
63
|
-
try {
|
|
64
|
-
for (let i = 0; i < stage.SYS_ACL.roles.uids.length; i++) {
|
|
65
|
-
const roleData = stage.SYS_ACL.roles.uids[i];
|
|
66
|
-
if (!roleNameMap[roleData.name]) {
|
|
67
|
-
// rules.branch is required to create custom roles.
|
|
68
|
-
const branchRuleExists = roleData.rules.find((rule) => rule.module === 'branch');
|
|
69
|
-
if (!branchRuleExists) {
|
|
70
|
-
roleData.rules.push({
|
|
71
|
-
module: 'branch',
|
|
72
|
-
branches: ['main'],
|
|
73
|
-
acl: { read: true },
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
const role = await self.stackAPIClient.role().create({ role: roleData });
|
|
77
|
-
stage.SYS_ACL.roles.uids[i] = role.uid;
|
|
78
|
-
roleNameMap[roleData.name] = role.uid;
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
stage.SYS_ACL.roles.uids[i] = roleNameMap[roleData.name];
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
catch (error) {
|
|
86
|
-
log(self.config, `Error while importing workflows roles. ${formatError(error)}`, 'error');
|
|
87
|
-
reject({ message: 'Error while importing workflows roles' });
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
if (workflow.admin_users !== undefined) {
|
|
92
|
-
log(self.config, chalk.yellow('We are skipping import of `Workflow superuser(s)` from workflow'), 'info');
|
|
93
|
-
delete workflow.admin_users;
|
|
94
|
-
}
|
|
95
|
-
// One branch is required to create workflow.
|
|
96
|
-
if (!workflow.branches) {
|
|
97
|
-
workflow.branches = ['main'];
|
|
98
|
-
}
|
|
99
|
-
return self.stackAPIClient
|
|
100
|
-
.workflow()
|
|
101
|
-
.create({ workflow })
|
|
102
|
-
.then(async function (response) {
|
|
103
|
-
if (!isEmpty(filter(oldWorkflowStages, ({ next_available_stages }) => !isEmpty(next_available_stages)))) {
|
|
104
|
-
let updateRresponse = await self
|
|
105
|
-
.updateNextAvailableStagesUid(response, response.workflow_stages, oldWorkflowStages)
|
|
106
|
-
.catch((error) => {
|
|
107
|
-
log(self.config, `Workflow '${workflow.name}' update failed.`, 'error');
|
|
108
|
-
log(self.config, error, 'error');
|
|
109
|
-
});
|
|
110
|
-
if (updateRresponse)
|
|
111
|
-
response = updateRresponse;
|
|
112
|
-
}
|
|
113
|
-
self.workflowUidMapper[workflowUid] = response;
|
|
114
|
-
fileHelper.writeFileSync(workflowUidMapperPath, self.workflowUidMapper);
|
|
115
|
-
})
|
|
116
|
-
.catch(function (error) {
|
|
117
|
-
self.fails.push(workflow);
|
|
118
|
-
if (error.errors.name) {
|
|
119
|
-
log(self.config, `workflow '${workflow.name}' already exist`, 'error');
|
|
120
|
-
}
|
|
121
|
-
else if (error.errors['workflow_stages.0.users']) {
|
|
122
|
-
log(self.config, "Failed to import Workflows as you've specified certain roles in the Stage transition and access rules section. We currently don't import roles to the stack.", 'error');
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
log(self.config, `Workflow '${workflow.name}' failed.`, 'error');
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
// the workflow has already been created
|
|
131
|
-
log(self.config, chalk.white(`The Workflows ${workflow.name} already exists. Skipping it to avoid duplicates!`), 'success');
|
|
132
|
-
}
|
|
133
|
-
// import 1 workflows at a time
|
|
134
|
-
}, { concurrency: self.reqConcurrency })
|
|
135
|
-
.then(function () {
|
|
136
|
-
fileHelper.writeFileSync(workflowSuccessPath, self.success);
|
|
137
|
-
log(self.config, chalk.green('Workflows have been imported successfully!'), 'success');
|
|
138
|
-
resolve();
|
|
139
|
-
})
|
|
140
|
-
.catch(function (error) {
|
|
141
|
-
fileHelper.writeFileSync(workflowFailsPath, self.fails);
|
|
142
|
-
log(self.config, `Workflows import failed. ${formatError(error)}`, 'error');
|
|
143
|
-
return reject(error);
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
updateNextAvailableStagesUid(workflow, newWorkflowStages, oldWorkflowStages) {
|
|
148
|
-
newWorkflowStages = map(newWorkflowStages, (newStage, index) => {
|
|
149
|
-
const oldStage = oldWorkflowStages[index];
|
|
150
|
-
if (!isEmpty(oldStage.next_available_stages)) {
|
|
151
|
-
newStage.next_available_stages = map(oldStage.next_available_stages, (stageUid) => {
|
|
152
|
-
var _a, _b;
|
|
153
|
-
if (stageUid === '$all')
|
|
154
|
-
return stageUid;
|
|
155
|
-
const stageName = (_a = find(oldWorkflowStages, { uid: stageUid })) === null || _a === void 0 ? void 0 : _a.name;
|
|
156
|
-
return (_b = find(newWorkflowStages, { name: stageName })) === null || _b === void 0 ? void 0 : _b.uid;
|
|
157
|
-
}).filter((val) => val);
|
|
158
|
-
}
|
|
159
|
-
return newStage;
|
|
160
|
-
});
|
|
161
|
-
const updateWorkflow = this.stackAPIClient.workflow(workflow.uid);
|
|
162
|
-
Object.assign(updateWorkflow, {
|
|
163
|
-
name: workflow.name,
|
|
164
|
-
branches: workflow.branches,
|
|
165
|
-
workflow_stages: newWorkflowStages,
|
|
166
|
-
content_types: workflow.content_types
|
|
167
|
-
});
|
|
168
|
-
return updateWorkflow.update();
|
|
169
|
-
}
|
|
170
|
-
};
|
package/lib/utils/log.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { LogEntry } from 'winston/index';
|
|
2
|
-
import { Logger } from '@contentstack/cli-utilities';
|
|
3
|
-
import { LogsType, MessageType } from '@contentstack/cli-utilities/lib/logger';
|
|
4
|
-
import { ImportConfig } from '../types';
|
|
5
|
-
declare let logger: Logger;
|
|
6
|
-
export declare function isImportConfig(config: ImportConfig | MessageType): config is ImportConfig;
|
|
7
|
-
export declare function log(entry: LogEntry): void;
|
|
8
|
-
export declare function log(error: MessageType, logType: LogsType): void;
|
|
9
|
-
export declare function log(error: MessageType, logType: 'error', hidden: boolean): void;
|
|
10
|
-
export declare function initLogger(config?: ImportConfig | undefined): Logger;
|
|
11
|
-
export { logger };
|
|
12
|
-
export declare const trace: typeof log;
|
package/lib/utils/log.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.trace = exports.logger = exports.initLogger = exports.log = exports.isImportConfig = void 0;
|
|
4
|
-
const path_1 = require("path");
|
|
5
|
-
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
6
|
-
let logger;
|
|
7
|
-
exports.logger = logger;
|
|
8
|
-
function isImportConfig(config) {
|
|
9
|
-
return config.data !== undefined && (config === null || config === void 0 ? void 0 : config.contentVersion) !== undefined;
|
|
10
|
-
}
|
|
11
|
-
exports.isImportConfig = isImportConfig;
|
|
12
|
-
function log(entryOrMessage, logType, hidden) {
|
|
13
|
-
exports.logger = logger = initLogger();
|
|
14
|
-
if (logType === 'error') {
|
|
15
|
-
logger.log(entryOrMessage, logType, hidden);
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
logger.log(entryOrMessage, logType);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
exports.log = log;
|
|
22
|
-
function initLogger(config) {
|
|
23
|
-
var _a;
|
|
24
|
-
if (!logger) {
|
|
25
|
-
const basePath = (0, cli_utilities_1.pathValidator)((0, path_1.join)((0, cli_utilities_1.sanitizePath)((_a = config === null || config === void 0 ? void 0 : config.cliLogsPath) !== null && _a !== void 0 ? _a : process.cwd()), 'logs', 'import'));
|
|
26
|
-
exports.logger = logger = new cli_utilities_1.Logger(Object.assign(config !== null && config !== void 0 ? config : {}, { basePath }));
|
|
27
|
-
}
|
|
28
|
-
return logger;
|
|
29
|
-
}
|
|
30
|
-
exports.initLogger = initLogger;
|
|
31
|
-
exports.trace = log;
|