@contentstack/cli-cm-clone 2.0.0-beta.12 → 2.0.0-beta.14
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
CHANGED
|
@@ -16,7 +16,7 @@ $ npm install -g @contentstack/cli-cm-clone
|
|
|
16
16
|
$ csdx COMMAND
|
|
17
17
|
running command...
|
|
18
18
|
$ csdx (--version)
|
|
19
|
-
@contentstack/cli-cm-clone/2.0.0-beta.
|
|
19
|
+
@contentstack/cli-cm-clone/2.0.0-beta.14 linux-x64 node-v22.22.1
|
|
20
20
|
$ csdx --help [COMMAND]
|
|
21
21
|
USAGE
|
|
22
22
|
$ csdx COMMAND
|
|
@@ -224,7 +224,6 @@ class StackCloneCommand extends cli_command_1.Command {
|
|
|
224
224
|
interrupt.forEach((signal) => process.on(signal, () => cleanUp(true)));
|
|
225
225
|
}
|
|
226
226
|
}
|
|
227
|
-
exports.default = StackCloneCommand;
|
|
228
227
|
StackCloneCommand.description = `Clone data (structure/content or both) of a stack into another stack
|
|
229
228
|
Use this plugin to automate the process of cloning a stack in few steps.
|
|
230
229
|
`;
|
|
@@ -314,3 +313,4 @@ StackCloneCommand.flags = {
|
|
|
314
313
|
}),
|
|
315
314
|
};
|
|
316
315
|
StackCloneCommand.usage = 'cm:stacks:clone [--source-branch <value>] [--target-branch <value>] [--source-management-token-alias <value>] [--destination-management-token-alias <value>] [-n <value>] [--type a|b] [--source-stack-api-key <value>] [--destination-stack-api-key <value>] [--import-webhook-status disable|current]';
|
|
316
|
+
exports.default = StackCloneCommand;
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Clone = exports.
|
|
3
|
+
exports.Clone = exports.BaseCommand = void 0;
|
|
4
|
+
exports.HandleOrgCommand = HandleOrgCommand;
|
|
5
|
+
exports.HandleStackCommand = HandleStackCommand;
|
|
6
|
+
exports.HandleBranchCommand = HandleBranchCommand;
|
|
7
|
+
exports.HandleDestinationStackCommand = HandleDestinationStackCommand;
|
|
8
|
+
exports.HandleExportCommand = HandleExportCommand;
|
|
9
|
+
exports.SetBranchCommand = SetBranchCommand;
|
|
10
|
+
exports.CreateNewStackCommand = CreateNewStackCommand;
|
|
11
|
+
exports.CloneTypeSelectionCommand = CloneTypeSelectionCommand;
|
|
4
12
|
/**
|
|
5
13
|
* Base command class implementing the command pattern
|
|
6
14
|
*/
|
|
@@ -26,35 +34,27 @@ exports.BaseCommand = BaseCommand;
|
|
|
26
34
|
function HandleOrgCommand(params, parentContext) {
|
|
27
35
|
return new BaseCommand(parentContext.handleOrgSelection.bind(parentContext), undefined, params);
|
|
28
36
|
}
|
|
29
|
-
exports.HandleOrgCommand = HandleOrgCommand;
|
|
30
37
|
function HandleStackCommand(params, parentContext) {
|
|
31
38
|
return new BaseCommand(parentContext.handleStackSelection.bind(parentContext), parentContext.execute.bind(parentContext), params);
|
|
32
39
|
}
|
|
33
|
-
exports.HandleStackCommand = HandleStackCommand;
|
|
34
40
|
function HandleBranchCommand(params, parentContext, backStepHandler) {
|
|
35
41
|
return new BaseCommand(parentContext.handleBranchSelection.bind(parentContext), backStepHandler, params);
|
|
36
42
|
}
|
|
37
|
-
exports.HandleBranchCommand = HandleBranchCommand;
|
|
38
43
|
function HandleDestinationStackCommand(params, parentContext) {
|
|
39
44
|
return new BaseCommand(parentContext.handleStackSelection.bind(parentContext), parentContext.executeDestination.bind(parentContext), params);
|
|
40
45
|
}
|
|
41
|
-
exports.HandleDestinationStackCommand = HandleDestinationStackCommand;
|
|
42
46
|
function HandleExportCommand(params, parentContext) {
|
|
43
47
|
return new BaseCommand(parentContext.cmdExport.bind(parentContext), undefined, params);
|
|
44
48
|
}
|
|
45
|
-
exports.HandleExportCommand = HandleExportCommand;
|
|
46
49
|
function SetBranchCommand(params, parentContext) {
|
|
47
50
|
return new BaseCommand(parentContext.setBranch.bind(parentContext), undefined, params);
|
|
48
51
|
}
|
|
49
|
-
exports.SetBranchCommand = SetBranchCommand;
|
|
50
52
|
function CreateNewStackCommand(params, parentContext) {
|
|
51
53
|
return new BaseCommand(parentContext.createNewStack.bind(parentContext), parentContext.executeDestination.bind(parentContext), params);
|
|
52
54
|
}
|
|
53
|
-
exports.CreateNewStackCommand = CreateNewStackCommand;
|
|
54
55
|
function CloneTypeSelectionCommand(params, parentContext) {
|
|
55
56
|
return new BaseCommand(parentContext.cloneTypeSelection.bind(parentContext), undefined, params);
|
|
56
57
|
}
|
|
57
|
-
exports.CloneTypeSelectionCommand = CloneTypeSelectionCommand;
|
|
58
58
|
/**
|
|
59
59
|
* Clone command executor class
|
|
60
60
|
*/
|
|
@@ -5,7 +5,7 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const ora_1 = tslib_1.__importDefault(require("ora"));
|
|
6
6
|
const path = tslib_1.__importStar(require("path"));
|
|
7
7
|
const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
|
|
8
|
-
const
|
|
8
|
+
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
9
9
|
const fs = tslib_1.__importStar(require("fs"));
|
|
10
10
|
const rimraf_1 = require("rimraf");
|
|
11
11
|
const cli_cm_export_1 = tslib_1.__importDefault(require("@contentstack/cli-cm-export"));
|
|
@@ -14,7 +14,7 @@ const cli_cm_import_1 = tslib_1.__importDefault(require("@contentstack/cli-cm-im
|
|
|
14
14
|
const prompt = require('prompt');
|
|
15
15
|
const safe_1 = tslib_1.__importDefault(require("@colors/colors/safe"));
|
|
16
16
|
const cloneDeep_1 = tslib_1.__importDefault(require("lodash/cloneDeep"));
|
|
17
|
-
const
|
|
17
|
+
const cli_utilities_2 = require("@contentstack/cli-utilities");
|
|
18
18
|
const command_helpers_1 = require("../helpers/command-helpers");
|
|
19
19
|
const constants_1 = require("../../utils/constants");
|
|
20
20
|
// Override prompt's stop method
|
|
@@ -42,7 +42,7 @@ class CloneHandler {
|
|
|
42
42
|
message: constants_1.STACK_NAME_PROMPT.message,
|
|
43
43
|
};
|
|
44
44
|
process.stdin.setMaxListeners(50);
|
|
45
|
-
|
|
45
|
+
cli_utilities_2.log.debug('Initializing CloneHandler', Object.assign(Object.assign({}, this.config.cloneContext), { pathDir: opt.pathDir, cloneType: opt.cloneType }));
|
|
46
46
|
}
|
|
47
47
|
setClient(managementSDKClient) {
|
|
48
48
|
this.client = managementSDKClient;
|
|
@@ -55,12 +55,12 @@ class CloneHandler {
|
|
|
55
55
|
choices: [],
|
|
56
56
|
};
|
|
57
57
|
return new Promise(async (resolve, reject) => {
|
|
58
|
-
|
|
58
|
+
cli_utilities_2.log.debug('Fetching organization choices', this.config.cloneContext);
|
|
59
59
|
const spinner = (0, ora_1.default)('Fetching Organization').start();
|
|
60
60
|
try {
|
|
61
61
|
let organizations;
|
|
62
|
-
const configOrgUid =
|
|
63
|
-
|
|
62
|
+
const configOrgUid = cli_utilities_2.configHandler.get('oauthOrgUid');
|
|
63
|
+
cli_utilities_2.log.debug('Getting organizations', Object.assign(Object.assign({}, this.config.cloneContext), { hasConfigOrgUid: !!configOrgUid }));
|
|
64
64
|
if (configOrgUid) {
|
|
65
65
|
organizations = await this.client.organization(configOrgUid).fetch();
|
|
66
66
|
}
|
|
@@ -68,7 +68,7 @@ class CloneHandler {
|
|
|
68
68
|
organizations = await this.client.organization().fetchAll({ limit: 100 });
|
|
69
69
|
}
|
|
70
70
|
spinner.succeed('Fetched Organization');
|
|
71
|
-
|
|
71
|
+
cli_utilities_2.log.debug('Fetched organizations', this.config.cloneContext);
|
|
72
72
|
for (const element of organizations.items || [organizations]) {
|
|
73
73
|
this.orgUidList[element.name] = element.uid;
|
|
74
74
|
orgChoice.choices.push(element.name);
|
|
@@ -85,19 +85,19 @@ class CloneHandler {
|
|
|
85
85
|
return new Promise(async (resolve, reject) => {
|
|
86
86
|
var _a;
|
|
87
87
|
const { msg = '', isSource = true } = options || {};
|
|
88
|
-
|
|
88
|
+
cli_utilities_2.log.debug('Handling organization selection', this.config.cloneContext);
|
|
89
89
|
const orgList = await this.getOrganizationChoices(msg).catch(reject);
|
|
90
90
|
if (orgList) {
|
|
91
|
-
|
|
91
|
+
cli_utilities_2.log.debug(`Found ${((_a = orgList.choices) === null || _a === void 0 ? void 0 : _a.length) || 0} organization(s) to choose from`, this.config.cloneContext);
|
|
92
92
|
const orgSelected = await inquirer_1.default.prompt(orgList);
|
|
93
|
-
|
|
93
|
+
cli_utilities_2.log.debug(`Organization selected: ${orgSelected.Organization}`, this.config.cloneContext);
|
|
94
94
|
if (isSource) {
|
|
95
95
|
this.config.sourceOrg = this.orgUidList[orgSelected.Organization];
|
|
96
|
-
|
|
96
|
+
cli_utilities_2.log.debug(`Source organization UID: ${this.config.sourceOrg}`, this.config.cloneContext);
|
|
97
97
|
}
|
|
98
98
|
else {
|
|
99
99
|
this.config.targetOrg = this.orgUidList[orgSelected.Organization];
|
|
100
|
-
|
|
100
|
+
cli_utilities_2.log.debug(`Target organization UID: ${this.config.targetOrg}`, this.config.cloneContext);
|
|
101
101
|
}
|
|
102
102
|
resolve(orgSelected);
|
|
103
103
|
}
|
|
@@ -111,15 +111,15 @@ class CloneHandler {
|
|
|
111
111
|
choices: [],
|
|
112
112
|
};
|
|
113
113
|
return new Promise(async (resolve, reject) => {
|
|
114
|
-
|
|
114
|
+
cli_utilities_2.log.debug('Fetching stacks', this.config.cloneContext);
|
|
115
115
|
const spinner = (0, ora_1.default)('Fetching stacks').start();
|
|
116
116
|
try {
|
|
117
117
|
const organization_uid = this.orgUidList[answer.Organization];
|
|
118
|
-
|
|
118
|
+
cli_utilities_2.log.debug('Querying stacks for organization', Object.assign(Object.assign({}, this.config.cloneContext), { organizationUid: organization_uid }));
|
|
119
119
|
const stackList = this.client.stack().query({ organization_uid }).find();
|
|
120
120
|
stackList
|
|
121
121
|
.then((stacklist) => {
|
|
122
|
-
|
|
122
|
+
cli_utilities_2.log.debug('Fetched stacks', Object.assign(Object.assign({}, this.config.cloneContext), { count: stacklist.items ? stacklist.items.length : 0 }));
|
|
123
123
|
for (const element of stacklist.items) {
|
|
124
124
|
this.stackUidList[element.name] = element.api_key;
|
|
125
125
|
this.masterLocaleList[element.name] = element.master_locale;
|
|
@@ -140,8 +140,7 @@ class CloneHandler {
|
|
|
140
140
|
});
|
|
141
141
|
}
|
|
142
142
|
displayBackOptionMessage() {
|
|
143
|
-
|
|
144
|
-
ui.updateBottomBar(chalk_1.default.cyan('\nPress shift & left arrow together to undo the operation\n'));
|
|
143
|
+
process.stdout.write((0, cli_utilities_1.getChalk)().cyan('\nPress shift & left arrow together to undo the operation\n'));
|
|
145
144
|
}
|
|
146
145
|
setBackKeyPressHandler(backKeyPressHandler) {
|
|
147
146
|
this.backKeyPressHandler = backKeyPressHandler;
|
|
@@ -160,13 +159,13 @@ class CloneHandler {
|
|
|
160
159
|
var _a;
|
|
161
160
|
try {
|
|
162
161
|
const { org = {}, msg = '', isSource = true } = options || {};
|
|
163
|
-
|
|
162
|
+
cli_utilities_2.log.debug('Handling stack selection', Object.assign(Object.assign({}, this.config.cloneContext), { isSource, orgName: org.Organization, msg }));
|
|
164
163
|
const stackList = await this.getStack(org, msg, isSource).catch(reject);
|
|
165
164
|
if (stackList) {
|
|
166
165
|
this.displayBackOptionMessage();
|
|
167
|
-
|
|
166
|
+
cli_utilities_2.log.debug(`Found ${((_a = stackList.choices) === null || _a === void 0 ? void 0 : _a.length) || 0} stack(s) to choose from`, this.config.cloneContext);
|
|
168
167
|
const selectedStack = await inquirer_1.default.prompt(stackList);
|
|
169
|
-
|
|
168
|
+
cli_utilities_2.log.debug(`Stack selected: ${selectedStack.stack}`, this.config.cloneContext);
|
|
170
169
|
if (this.executingCommand != 1) {
|
|
171
170
|
return reject();
|
|
172
171
|
}
|
|
@@ -174,12 +173,12 @@ class CloneHandler {
|
|
|
174
173
|
this.config.sourceStackName = selectedStack.stack;
|
|
175
174
|
this.master_locale = this.masterLocaleList[selectedStack.stack];
|
|
176
175
|
this.config.source_stack = this.stackUidList[selectedStack.stack];
|
|
177
|
-
|
|
176
|
+
cli_utilities_2.log.debug(`Source stack configured`, this.config.cloneContext);
|
|
178
177
|
}
|
|
179
178
|
else {
|
|
180
179
|
this.config.target_stack = this.stackUidList[selectedStack.stack];
|
|
181
180
|
this.config.destinationStackName = selectedStack.stack;
|
|
182
|
-
|
|
181
|
+
cli_utilities_2.log.debug(`Target stack configured`, this.config.cloneContext);
|
|
183
182
|
}
|
|
184
183
|
resolve(selectedStack);
|
|
185
184
|
}
|
|
@@ -197,18 +196,18 @@ class CloneHandler {
|
|
|
197
196
|
};
|
|
198
197
|
try {
|
|
199
198
|
const branch = isSource ? this.config.sourceStackBranch : this.config.targetStackBranch;
|
|
200
|
-
|
|
199
|
+
cli_utilities_2.log.debug('Validating branch existence', this.config.cloneContext);
|
|
201
200
|
spinner = (0, ora_1.default)(`Validation if ${isSource ? 'source' : 'target'} branch exist.!`).start();
|
|
202
201
|
const isBranchExist = await stackAPIClient
|
|
203
202
|
.branch(branch)
|
|
204
203
|
.fetch()
|
|
205
204
|
.then((data) => data);
|
|
206
205
|
if (isBranchExist && typeof isBranchExist === 'object') {
|
|
207
|
-
|
|
206
|
+
cli_utilities_2.log.debug('Branch validation successful', this.config.cloneContext);
|
|
208
207
|
completeSpinner(`${isSource ? 'Source' : 'Target'} branch verified.!`);
|
|
209
208
|
}
|
|
210
209
|
else {
|
|
211
|
-
|
|
210
|
+
cli_utilities_2.log.error('Branch not found', this.config.cloneContext);
|
|
212
211
|
completeSpinner(`${isSource ? 'Source' : 'Target'} branch not found.!`, 'fail');
|
|
213
212
|
process.exit();
|
|
214
213
|
}
|
|
@@ -220,16 +219,16 @@ class CloneHandler {
|
|
|
220
219
|
}
|
|
221
220
|
async resolveBranchAliases(isSource = false) {
|
|
222
221
|
try {
|
|
223
|
-
|
|
222
|
+
cli_utilities_2.log.debug('Resolving branch aliases', Object.assign(Object.assign({}, this.config.cloneContext), { isSource, alias: isSource ? this.config.sourceStackBranchAlias : this.config.targetStackBranchAlias }));
|
|
224
223
|
if (isSource) {
|
|
225
224
|
const sourceStack = this.client.stack({ api_key: this.config.source_stack });
|
|
226
|
-
this.config.sourceStackBranch = await (0,
|
|
227
|
-
|
|
225
|
+
this.config.sourceStackBranch = await (0, cli_utilities_2.getBranchFromAlias)(sourceStack, this.config.sourceStackBranchAlias);
|
|
226
|
+
cli_utilities_2.log.debug('Source branch alias resolved', Object.assign(Object.assign({}, this.config.cloneContext), { alias: this.config.sourceStackBranchAlias, branch: this.config.sourceStackBranch }));
|
|
228
227
|
}
|
|
229
228
|
else {
|
|
230
229
|
const targetStack = this.client.stack({ api_key: this.config.target_stack });
|
|
231
|
-
this.config.targetStackBranch = await (0,
|
|
232
|
-
|
|
230
|
+
this.config.targetStackBranch = await (0, cli_utilities_2.getBranchFromAlias)(targetStack, this.config.targetStackBranchAlias);
|
|
231
|
+
cli_utilities_2.log.debug('Target branch alias resolved', Object.assign(Object.assign({}, this.config.cloneContext), { alias: this.config.targetStackBranchAlias, branch: this.config.targetStackBranch }));
|
|
233
232
|
}
|
|
234
233
|
}
|
|
235
234
|
catch (error) {
|
|
@@ -241,35 +240,35 @@ class CloneHandler {
|
|
|
241
240
|
return new Promise(async (resolve, reject) => {
|
|
242
241
|
let spinner;
|
|
243
242
|
try {
|
|
244
|
-
|
|
243
|
+
cli_utilities_2.log.debug('Handling branch selection', Object.assign(Object.assign({}, this.config.cloneContext), { isSource, returnBranch, stackApiKey: isSource ? this.config.source_stack : this.config.target_stack }));
|
|
245
244
|
const stackAPIClient = this.client.stack({
|
|
246
245
|
api_key: isSource ? this.config.source_stack : this.config.target_stack,
|
|
247
246
|
management_token: this.config.management_token,
|
|
248
247
|
});
|
|
249
248
|
// NOTE validate if source branch is exist
|
|
250
249
|
if (isSource && this.config.sourceStackBranch) {
|
|
251
|
-
|
|
250
|
+
cli_utilities_2.log.debug('Validating source branch exists', Object.assign(Object.assign({}, this.config.cloneContext), { branch: this.config.sourceStackBranch }));
|
|
252
251
|
await this.validateIfBranchExist(stackAPIClient, true);
|
|
253
252
|
return resolve(undefined);
|
|
254
253
|
}
|
|
255
254
|
else if (isSource && this.config.sourceStackBranchAlias) {
|
|
256
|
-
|
|
255
|
+
cli_utilities_2.log.debug('Resolving source branch alias', Object.assign(Object.assign({}, this.config.cloneContext), { alias: this.config.sourceStackBranchAlias }));
|
|
257
256
|
await this.resolveBranchAliases(true);
|
|
258
257
|
return resolve(undefined);
|
|
259
258
|
}
|
|
260
259
|
// NOTE Validate target branch is exist
|
|
261
260
|
if (!isSource && this.config.targetStackBranch) {
|
|
262
|
-
|
|
261
|
+
cli_utilities_2.log.debug('Validating target branch exists', Object.assign(Object.assign({}, this.config.cloneContext), { branch: this.config.targetStackBranch }));
|
|
263
262
|
await this.validateIfBranchExist(stackAPIClient, false);
|
|
264
263
|
return resolve(undefined);
|
|
265
264
|
}
|
|
266
265
|
else if (!isSource && this.config.targetStackBranchAlias) {
|
|
267
|
-
|
|
266
|
+
cli_utilities_2.log.debug('Resolving target branch alias', Object.assign(Object.assign({}, this.config.cloneContext), { alias: this.config.targetStackBranchAlias }));
|
|
268
267
|
await this.resolveBranchAliases();
|
|
269
268
|
return resolve(undefined);
|
|
270
269
|
}
|
|
271
270
|
spinner = (0, ora_1.default)('Fetching Branches').start();
|
|
272
|
-
|
|
271
|
+
cli_utilities_2.log.debug(`Querying branches for stack: ${isSource ? this.config.source_stack : this.config.target_stack}`, this.config.cloneContext);
|
|
273
272
|
const result = await stackAPIClient
|
|
274
273
|
.branch()
|
|
275
274
|
.query()
|
|
@@ -277,7 +276,7 @@ class CloneHandler {
|
|
|
277
276
|
.then(({ items }) => items)
|
|
278
277
|
.catch((_err) => { });
|
|
279
278
|
const condition = result && Array.isArray(result) && result.length > 0;
|
|
280
|
-
|
|
279
|
+
cli_utilities_2.log.debug(`Found ${(result === null || result === void 0 ? void 0 : result.length) || 0} branch(es)`, this.config.cloneContext);
|
|
281
280
|
// NOTE if want to get only list of branches (Pass param -> returnBranch = true )
|
|
282
281
|
if (returnBranch) {
|
|
283
282
|
resolve(condition ? result : []);
|
|
@@ -296,11 +295,11 @@ class CloneHandler {
|
|
|
296
295
|
}
|
|
297
296
|
if (isSource) {
|
|
298
297
|
this.config.sourceStackBranch = branch;
|
|
299
|
-
|
|
298
|
+
cli_utilities_2.log.debug(`Source branch selected: ${branch}`, this.config.cloneContext);
|
|
300
299
|
}
|
|
301
300
|
else {
|
|
302
301
|
this.config.targetStackBranch = branch;
|
|
303
|
-
|
|
302
|
+
cli_utilities_2.log.debug(`Target branch selected: ${branch}`, this.config.cloneContext);
|
|
304
303
|
}
|
|
305
304
|
}
|
|
306
305
|
else {
|
|
@@ -342,11 +341,11 @@ class CloneHandler {
|
|
|
342
341
|
}
|
|
343
342
|
async executeExport() {
|
|
344
343
|
try {
|
|
345
|
-
|
|
344
|
+
cli_utilities_2.log.debug('Executing export operation', this.config.cloneContext);
|
|
346
345
|
const exportRes = await this.cloneCommand.execute((0, command_helpers_1.HandleExportCommand)(null, this));
|
|
347
346
|
await this.cloneCommand.execute((0, command_helpers_1.SetBranchCommand)(null, this));
|
|
348
347
|
if (exportRes) {
|
|
349
|
-
|
|
348
|
+
cli_utilities_2.log.debug('Export operation completed, proceeding with destination', this.config.cloneContext);
|
|
350
349
|
this.executeDestination().catch(() => {
|
|
351
350
|
throw '';
|
|
352
351
|
});
|
|
@@ -363,10 +362,10 @@ class CloneHandler {
|
|
|
363
362
|
return new Promise(async (resolve, reject) => {
|
|
364
363
|
let keyPressHandler;
|
|
365
364
|
try {
|
|
366
|
-
|
|
365
|
+
cli_utilities_2.log.debug('Starting clone execution', Object.assign(Object.assign({}, this.config.cloneContext), { sourceStack: this.config.source_stack, targetStack: this.config.target_stack }));
|
|
367
366
|
if (!this.config.source_stack) {
|
|
368
367
|
const orgMsg = 'Choose an organization where your source stack exists:';
|
|
369
|
-
|
|
368
|
+
cli_utilities_2.log.debug('Source stack not provided, prompting for organization', this.config.cloneContext);
|
|
370
369
|
this.setExectingCommand(0);
|
|
371
370
|
this.removeBackKeyPressHandler();
|
|
372
371
|
const org = await this.cloneCommand.execute((0, command_helpers_1.HandleOrgCommand)({ msg: orgMsg, isSource: true }, this));
|
|
@@ -398,20 +397,20 @@ class CloneHandler {
|
|
|
398
397
|
}
|
|
399
398
|
}
|
|
400
399
|
else {
|
|
401
|
-
|
|
400
|
+
cli_utilities_2.log.debug('Source stack provided, proceeding with branch selection and export', this.config.cloneContext);
|
|
402
401
|
this.setExectingCommand(2);
|
|
403
402
|
await this.handleBranchSelection({ api_key: this.config.source_stack });
|
|
404
|
-
|
|
403
|
+
cli_utilities_2.log.debug('Starting export operation', this.config.cloneContext);
|
|
405
404
|
const exportRes = await this.cloneCommand.execute((0, command_helpers_1.HandleExportCommand)(null, this));
|
|
406
405
|
await this.cloneCommand.execute((0, command_helpers_1.SetBranchCommand)(null, this));
|
|
407
406
|
if (exportRes) {
|
|
408
|
-
|
|
407
|
+
cli_utilities_2.log.debug('Export completed, proceeding with destination setup', this.config.cloneContext);
|
|
409
408
|
this.executeDestination().catch((error) => {
|
|
410
409
|
return reject(error);
|
|
411
410
|
});
|
|
412
411
|
}
|
|
413
412
|
}
|
|
414
|
-
|
|
413
|
+
cli_utilities_2.log.debug('Clone execution completed successfully', this.config.cloneContext);
|
|
415
414
|
return resolve();
|
|
416
415
|
}
|
|
417
416
|
catch (error) {
|
|
@@ -423,10 +422,10 @@ class CloneHandler {
|
|
|
423
422
|
return new Promise(async (resolve, reject) => {
|
|
424
423
|
let keyPressHandler;
|
|
425
424
|
try {
|
|
426
|
-
|
|
425
|
+
cli_utilities_2.log.debug('Executing destination setup', this.config.cloneContext);
|
|
427
426
|
let canCreateStack = false;
|
|
428
427
|
if (!this.config.target_stack) {
|
|
429
|
-
|
|
428
|
+
cli_utilities_2.log.debug('Target stack not provided, prompting for stack creation', this.config.cloneContext);
|
|
430
429
|
canCreateStack = await inquirer_1.default.prompt(constants_1.STACK_CREATION_CONFIRMATION);
|
|
431
430
|
}
|
|
432
431
|
this.setExectingCommand(0);
|
|
@@ -469,7 +468,7 @@ class CloneHandler {
|
|
|
469
468
|
else {
|
|
470
469
|
await this.executeBranchDestinationPrompt(params);
|
|
471
470
|
}
|
|
472
|
-
|
|
471
|
+
cli_utilities_2.log.debug('Destination setup completed successfully', this.config.cloneContext);
|
|
473
472
|
return resolve();
|
|
474
473
|
}
|
|
475
474
|
catch (error) {
|
|
@@ -511,7 +510,7 @@ class CloneHandler {
|
|
|
511
510
|
async cmdExport() {
|
|
512
511
|
return new Promise((resolve, reject) => {
|
|
513
512
|
var _a;
|
|
514
|
-
|
|
513
|
+
cli_utilities_2.log.debug('Preparing export command', Object.assign(Object.assign({}, this.config.cloneContext), { sourceStack: this.config.source_stack, cloneType: this.config.cloneType }));
|
|
515
514
|
// Creating export specific config by merging external configurations
|
|
516
515
|
let exportConfig = Object.assign({}, (0, cloneDeep_1.default)(this.config), Object.assign({}, (_a = this.config) === null || _a === void 0 ? void 0 : _a.export));
|
|
517
516
|
delete exportConfig.import;
|
|
@@ -522,35 +521,35 @@ class CloneHandler {
|
|
|
522
521
|
// Resolve path to package root - go up 3 levels from __dirname (core/util -> package root)
|
|
523
522
|
const packageRoot = path.resolve(__dirname, '../../..');
|
|
524
523
|
const exportDir = path.join(packageRoot, 'contents');
|
|
525
|
-
|
|
524
|
+
cli_utilities_2.log.debug(`Export directory: ${exportDir}`, this.config.cloneContext);
|
|
526
525
|
const cmd = ['-k', exportConfig.apiKey || exportConfig.source_stack, '-d', exportDir];
|
|
527
526
|
if (exportConfig.cloneType === 'a') {
|
|
528
527
|
exportConfig.filteredModules = ['stack'].concat(constants_1.STRUCTURE_LIST);
|
|
529
|
-
|
|
528
|
+
cli_utilities_2.log.debug(`Filtered modules for structure-only export: ${exportConfig.filteredModules.join(', ')}`, this.config.cloneContext);
|
|
530
529
|
}
|
|
531
530
|
if (exportConfig.source_alias) {
|
|
532
531
|
cmd.push('-a', exportConfig.source_alias);
|
|
533
|
-
|
|
532
|
+
cli_utilities_2.log.debug(`Using source alias: ${exportConfig.source_alias}`, this.config.cloneContext);
|
|
534
533
|
}
|
|
535
534
|
if (exportConfig.sourceStackBranch) {
|
|
536
535
|
cmd.push('--branch', exportConfig.sourceStackBranch);
|
|
537
|
-
|
|
536
|
+
cli_utilities_2.log.debug(`Using source branch: ${exportConfig.sourceStackBranch}`, this.config.cloneContext);
|
|
538
537
|
}
|
|
539
538
|
if (exportConfig.forceStopMarketplaceAppsPrompt) {
|
|
540
539
|
cmd.push('-y');
|
|
541
|
-
|
|
540
|
+
cli_utilities_2.log.debug('Force stop marketplace apps prompt enabled', this.config.cloneContext);
|
|
542
541
|
}
|
|
543
542
|
// dummyConfig.json is in the same directory as this file
|
|
544
543
|
const configFilePath = path.join(__dirname, 'dummyConfig.json');
|
|
545
544
|
cmd.push('-c');
|
|
546
545
|
cmd.push(configFilePath);
|
|
547
|
-
|
|
546
|
+
cli_utilities_2.log.debug(`Writing export config to: ${configFilePath}`, this.config.cloneContext);
|
|
548
547
|
fs.writeFileSync(configFilePath, JSON.stringify(exportConfig));
|
|
549
|
-
|
|
550
|
-
|
|
548
|
+
cli_utilities_2.log.debug('Export command prepared', Object.assign(Object.assign({}, this.config.cloneContext), { cmd: cmd.join(' '), exportDir, sourceStack: exportConfig.apiKey || exportConfig.source_stack, branch: exportConfig.sourceStackBranch }));
|
|
549
|
+
cli_utilities_2.log.debug('Running export command', Object.assign(Object.assign({}, this.config.cloneContext), { cmd }));
|
|
551
550
|
const exportData = cli_cm_export_1.default.run(cmd);
|
|
552
551
|
exportData.then(() => {
|
|
553
|
-
|
|
552
|
+
cli_utilities_2.log.debug('Export command completed successfully', this.config.cloneContext);
|
|
554
553
|
resolve(true);
|
|
555
554
|
}).catch((error) => {
|
|
556
555
|
reject(error);
|
|
@@ -560,7 +559,7 @@ class CloneHandler {
|
|
|
560
559
|
async cmdImport() {
|
|
561
560
|
return new Promise(async (resolve, _reject) => {
|
|
562
561
|
var _a;
|
|
563
|
-
|
|
562
|
+
cli_utilities_2.log.debug('Preparing import command', Object.assign(Object.assign({}, this.config.cloneContext), { targetStack: this.config.target_stack, targetBranch: this.config.targetStackBranch }));
|
|
564
563
|
// Creating export specific config by merging external configurations
|
|
565
564
|
let importConfig = Object.assign({}, (0, cloneDeep_1.default)(this.config), Object.assign({}, (_a = this.config) === null || _a === void 0 ? void 0 : _a.import));
|
|
566
565
|
delete importConfig.import;
|
|
@@ -570,11 +569,11 @@ class CloneHandler {
|
|
|
570
569
|
const cmd = ['-c', configFilePath];
|
|
571
570
|
if (importConfig.destination_alias) {
|
|
572
571
|
cmd.push('-a', importConfig.destination_alias);
|
|
573
|
-
|
|
572
|
+
cli_utilities_2.log.debug(`Using destination alias: ${importConfig.destination_alias}`, this.config.cloneContext);
|
|
574
573
|
}
|
|
575
574
|
if (importConfig.target_stack) {
|
|
576
575
|
importConfig.apiKey = importConfig.target_stack;
|
|
577
|
-
|
|
576
|
+
cli_utilities_2.log.debug(`Using target stack api key for import: ${importConfig.target_stack}`, this.config.cloneContext);
|
|
578
577
|
}
|
|
579
578
|
if (importConfig.data) {
|
|
580
579
|
importConfig.contentDir = importConfig.data;
|
|
@@ -582,36 +581,36 @@ class CloneHandler {
|
|
|
582
581
|
if (!importConfig.contentDir && importConfig.sourceStackBranch && importConfig.pathDir) {
|
|
583
582
|
const dataPath = path.join(importConfig.pathDir, importConfig.sourceStackBranch);
|
|
584
583
|
cmd.push('-d', dataPath);
|
|
585
|
-
|
|
584
|
+
cli_utilities_2.log.debug(`Import data path: ${dataPath}`, this.config.cloneContext);
|
|
586
585
|
}
|
|
587
586
|
if (importConfig.targetStackBranch) {
|
|
588
587
|
cmd.push('--branch', importConfig.targetStackBranch);
|
|
589
|
-
|
|
588
|
+
cli_utilities_2.log.debug(`Using target branch: ${importConfig.targetStackBranch}`, this.config.cloneContext);
|
|
590
589
|
}
|
|
591
590
|
if (importConfig.importWebhookStatus) {
|
|
592
591
|
cmd.push('--import-webhook-status', importConfig.importWebhookStatus);
|
|
593
|
-
|
|
592
|
+
cli_utilities_2.log.debug(`Import webhook status: ${importConfig.importWebhookStatus}`, this.config.cloneContext);
|
|
594
593
|
}
|
|
595
594
|
if (importConfig.skipAudit) {
|
|
596
595
|
cmd.push('--skip-audit');
|
|
597
|
-
|
|
596
|
+
cli_utilities_2.log.debug('Skip audit flag enabled', this.config.cloneContext);
|
|
598
597
|
}
|
|
599
598
|
if (importConfig.forceStopMarketplaceAppsPrompt) {
|
|
600
599
|
cmd.push('-y');
|
|
601
|
-
|
|
600
|
+
cli_utilities_2.log.debug('Force stop marketplace apps prompt enabled', this.config.cloneContext);
|
|
602
601
|
}
|
|
603
|
-
|
|
602
|
+
cli_utilities_2.log.debug(`Writing import config to: ${configFilePath}`, this.config.cloneContext);
|
|
604
603
|
fs.writeFileSync(configFilePath, JSON.stringify(importConfig));
|
|
605
|
-
|
|
606
|
-
|
|
604
|
+
cli_utilities_2.log.debug('Import command prepared', Object.assign(Object.assign({}, this.config.cloneContext), { cmd: cmd.join(' '), targetStack: importConfig.apiKey || importConfig.target_stack, targetBranch: importConfig.targetStackBranch, dataPath: importConfig.contentDir || (importConfig.pathDir && importConfig.sourceStackBranch ? path.join(importConfig.pathDir, importConfig.sourceStackBranch) : undefined) }));
|
|
605
|
+
cli_utilities_2.log.debug('Running import command', Object.assign(Object.assign({}, this.config.cloneContext), { cmd }));
|
|
607
606
|
const importData = cli_cm_import_1.default.run(cmd);
|
|
608
607
|
importData.then(() => {
|
|
609
|
-
|
|
610
|
-
|
|
608
|
+
cli_utilities_2.log.debug('Import command completed successfully', this.config.cloneContext);
|
|
609
|
+
cli_utilities_2.log.debug('Clearing import config file', this.config.cloneContext);
|
|
611
610
|
fs.writeFileSync(configFilePath, JSON.stringify({}));
|
|
612
611
|
resolve();
|
|
613
612
|
}).catch((error) => {
|
|
614
|
-
|
|
613
|
+
cli_utilities_2.log.error('Import command failed', Object.assign(Object.assign({}, this.config.cloneContext), { error }));
|
|
615
614
|
throw error;
|
|
616
615
|
});
|
|
617
616
|
});
|
|
@@ -660,11 +659,11 @@ class CloneHandler {
|
|
|
660
659
|
return new Promise(async (resolve, reject) => {
|
|
661
660
|
try {
|
|
662
661
|
const { orgUid } = options;
|
|
663
|
-
|
|
662
|
+
cli_utilities_2.log.debug('Creating new stack', Object.assign(Object.assign({}, this.config.cloneContext), { orgUid, masterLocale: this.master_locale, stackName: this.config.stackName }));
|
|
664
663
|
this.displayBackOptionMessage();
|
|
665
664
|
let inputvalue;
|
|
666
665
|
if (!this.config.stackName) {
|
|
667
|
-
|
|
666
|
+
cli_utilities_2.log.debug('Stack name not provided, prompting user', this.config.cloneContext);
|
|
668
667
|
prompt.start();
|
|
669
668
|
prompt.message = '';
|
|
670
669
|
this.setCreateNewStackPrompt(prompt);
|
|
@@ -675,21 +674,21 @@ class CloneHandler {
|
|
|
675
674
|
inputvalue = { stack: this.config.stackName };
|
|
676
675
|
}
|
|
677
676
|
if (this.executingCommand === 0 || !inputvalue) {
|
|
678
|
-
|
|
677
|
+
cli_utilities_2.log.debug('Stack creation cancelled or invalid input', this.config.cloneContext);
|
|
679
678
|
return reject();
|
|
680
679
|
}
|
|
681
680
|
let stack = { name: inputvalue.stack, master_locale: this.master_locale };
|
|
682
|
-
|
|
681
|
+
cli_utilities_2.log.debug('Creating stack with configuration', this.config.cloneContext);
|
|
683
682
|
const spinner = (0, ora_1.default)('Creating New stack').start();
|
|
684
|
-
|
|
683
|
+
cli_utilities_2.log.debug('Sending stack creation API request', this.config.cloneContext);
|
|
685
684
|
const newStack = this.client.stack().create({ stack }, { organization_uid: orgUid });
|
|
686
685
|
newStack
|
|
687
686
|
.then((result) => {
|
|
688
|
-
|
|
687
|
+
cli_utilities_2.log.debug('Stack created successfully', Object.assign(Object.assign({}, this.config.cloneContext), { stackName: result.name }));
|
|
689
688
|
spinner.succeed('New Stack created Successfully name as ' + result.name);
|
|
690
689
|
this.config.target_stack = result.api_key;
|
|
691
690
|
this.config.destinationStackName = result.name;
|
|
692
|
-
|
|
691
|
+
cli_utilities_2.log.debug('Target stack configuration updated', this.config.cloneContext);
|
|
693
692
|
return resolve(result);
|
|
694
693
|
})
|
|
695
694
|
.catch((error) => {
|
|
@@ -706,7 +705,7 @@ class CloneHandler {
|
|
|
706
705
|
console.clear();
|
|
707
706
|
return new Promise(async (resolve, reject) => {
|
|
708
707
|
try {
|
|
709
|
-
|
|
708
|
+
cli_utilities_2.log.debug('Starting clone type selection', this.config.cloneContext);
|
|
710
709
|
const choices = [
|
|
711
710
|
'Structure (all modules except entries & assets)',
|
|
712
711
|
'Structure with content (all modules including entries & assets)',
|
|
@@ -724,41 +723,41 @@ class CloneHandler {
|
|
|
724
723
|
// Resolve path to package root - go up 3 levels from __dirname (core/util -> package root)
|
|
725
724
|
const cloneTypePackageRoot = path.resolve(__dirname, '../../..');
|
|
726
725
|
this.config.contentDir = path.join(cloneTypePackageRoot, 'contents', this.config.sourceStackBranch || '');
|
|
727
|
-
|
|
726
|
+
cli_utilities_2.log.debug(`Clone content directory: ${this.config.contentDir}`, this.config.cloneContext);
|
|
728
727
|
if (!this.config.cloneType) {
|
|
729
|
-
|
|
728
|
+
cli_utilities_2.log.debug('Clone type not specified, prompting user for selection', this.config.cloneContext);
|
|
730
729
|
selectedValue = await inquirer_1.default.prompt(cloneTypeSelection);
|
|
731
730
|
}
|
|
732
731
|
else {
|
|
733
|
-
|
|
732
|
+
cli_utilities_2.log.debug(`Using pre-configured clone type: ${this.config.cloneType}`, this.config.cloneContext);
|
|
734
733
|
}
|
|
735
734
|
if (this.config.cloneType === 'a' || selectedValue.type === 'Structure (all modules except entries & assets)') {
|
|
736
735
|
this.config.modules = constants_1.STRUCTURE_LIST;
|
|
737
736
|
successMsg = 'Stack clone Structure completed';
|
|
738
|
-
|
|
737
|
+
cli_utilities_2.log.debug(`Clone type: Structure only. Modules to clone: ${constants_1.STRUCTURE_LIST.join(', ')}`, this.config.cloneContext);
|
|
739
738
|
}
|
|
740
739
|
else {
|
|
741
740
|
successMsg = 'Stack clone completed with structure and content';
|
|
742
|
-
|
|
741
|
+
cli_utilities_2.log.debug('Clone type: Structure with content (all modules)', this.config.cloneContext);
|
|
743
742
|
}
|
|
744
743
|
this.cmdImport()
|
|
745
744
|
.then(async () => {
|
|
746
|
-
|
|
745
|
+
cli_utilities_2.log.debug('Clone type selection and import completed successfully', this.config.cloneContext);
|
|
747
746
|
// Clean up contents directory after import completes
|
|
748
747
|
if (this.config.pathDir) {
|
|
749
748
|
const resolvedPath = path.resolve(this.config.pathDir);
|
|
750
|
-
|
|
749
|
+
cli_utilities_2.log.debug('Cleaning up contents directory after import', Object.assign(Object.assign({}, this.config.cloneContext), { pathDir: this.config.pathDir, resolvedPath }));
|
|
751
750
|
try {
|
|
752
751
|
await (0, rimraf_1.rimraf)(resolvedPath);
|
|
753
|
-
|
|
752
|
+
cli_utilities_2.log.debug('Contents directory cleaned up successfully', Object.assign(Object.assign({}, this.config.cloneContext), { pathDir: this.config.pathDir, resolvedPath }));
|
|
754
753
|
}
|
|
755
754
|
catch (cleanupError) {
|
|
756
|
-
|
|
755
|
+
cli_utilities_2.log.debug('Cleanup error (non-fatal)', Object.assign(Object.assign({}, this.config.cloneContext), { pathDir: this.config.pathDir, resolvedPath, error: cleanupError === null || cleanupError === void 0 ? void 0 : cleanupError.message, code: cleanupError === null || cleanupError === void 0 ? void 0 : cleanupError.code }));
|
|
757
756
|
// Don't fail the clone if cleanup fails
|
|
758
757
|
}
|
|
759
758
|
}
|
|
760
759
|
else {
|
|
761
|
-
|
|
760
|
+
cli_utilities_2.log.debug('No pathDir configured, skipping cleanup', this.config.cloneContext);
|
|
762
761
|
}
|
|
763
762
|
resolve(successMsg);
|
|
764
763
|
})
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-cm-clone",
|
|
3
3
|
"description": "Contentstack stack clone plugin",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.14",
|
|
5
5
|
"author": "Contentstack",
|
|
6
6
|
"bugs": "https://github.com/rohitmishra209/cli-cm-clone/issues",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@colors/colors": "^1.6.0",
|
|
9
|
-
"@contentstack/cli-cm-export": "~2.0.0-beta.
|
|
10
|
-
"@contentstack/cli-cm-import": "~2.0.0-beta.
|
|
11
|
-
"@contentstack/cli-command": "~2.0.0-beta.
|
|
12
|
-
"@contentstack/cli-utilities": "~2.0.0-beta.
|
|
9
|
+
"@contentstack/cli-cm-export": "~2.0.0-beta.13",
|
|
10
|
+
"@contentstack/cli-cm-import": "~2.0.0-beta.13",
|
|
11
|
+
"@contentstack/cli-command": "~2.0.0-beta.4",
|
|
12
|
+
"@contentstack/cli-utilities": "~2.0.0-beta.4",
|
|
13
13
|
"@oclif/core": "^4.3.0",
|
|
14
14
|
"@oclif/plugin-help": "^6.2.28",
|
|
15
|
-
"chalk": "^
|
|
16
|
-
"inquirer": "
|
|
15
|
+
"chalk": "^5.6.2",
|
|
16
|
+
"inquirer": "12.11.1",
|
|
17
17
|
"lodash": "^4.17.23",
|
|
18
18
|
"merge": "^2.1.1",
|
|
19
19
|
"ora": "^5.4.1",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"@oclif/test": "^4.1.13",
|
|
25
25
|
"@types/chai": "^4.3.0",
|
|
26
26
|
"@types/mocha": "^10.0.0",
|
|
27
|
-
"@types/node": "^
|
|
27
|
+
"@types/node": "^18.11.9",
|
|
28
28
|
"@types/sinon": "^10.0.0",
|
|
29
29
|
"@typescript-eslint/eslint-plugin": "^5.62.0",
|
|
30
30
|
"chai": "^4.5.0",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"oclif": "^4.17.46",
|
|
36
36
|
"sinon": "^21.0.1",
|
|
37
37
|
"ts-node": "^10.9.2",
|
|
38
|
-
"typescript": "^
|
|
38
|
+
"typescript": "^5.9.3"
|
|
39
39
|
},
|
|
40
40
|
"engines": {
|
|
41
41
|
"node": ">=14.0.0"
|
|
@@ -78,4 +78,4 @@
|
|
|
78
78
|
"cm:stacks:clone": "CLN"
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
|
-
}
|
|
81
|
+
}
|