@contentstack/cli-cm-clone 1.4.11 → 1.4.13
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 +8 -4
- package/oclif.manifest.json +1 -1
- package/package.json +6 -5
- package/src/commands/cm/stacks/clone.js +2 -2
- package/src/lib/util/clone-handler.js +53 -16
package/README.md
CHANGED
|
@@ -1,27 +1,29 @@
|
|
|
1
|
-
@contentstack/cli-cm-clone
|
|
2
|
-
==========================
|
|
1
|
+
# @contentstack/cli-cm-clone
|
|
3
2
|
|
|
4
3
|
It is Contentstack’s CLI plugin to clone a stack. Using this command, you can export a stack’s content/schema to a new or existing stack. Refer to the [Clone a Stack](https://www.contentstack.com/docs/developers/cli/clone-a-stack/) documentation to learn more.
|
|
5
4
|
|
|
6
|
-
|
|
7
5
|
<!-- toc -->
|
|
6
|
+
* [@contentstack/cli-cm-clone](#contentstackcli-cm-clone)
|
|
8
7
|
* [Usage](#usage)
|
|
9
8
|
* [Commands](#commands)
|
|
10
9
|
<!-- tocstop -->
|
|
10
|
+
|
|
11
11
|
# Usage
|
|
12
|
+
|
|
12
13
|
<!-- usage -->
|
|
13
14
|
```sh-session
|
|
14
15
|
$ npm install -g @contentstack/cli-cm-clone
|
|
15
16
|
$ csdx COMMAND
|
|
16
17
|
running command...
|
|
17
18
|
$ csdx (--version)
|
|
18
|
-
@contentstack/cli-cm-clone/1.4.
|
|
19
|
+
@contentstack/cli-cm-clone/1.4.13 linux-x64 node-v18.17.0
|
|
19
20
|
$ csdx --help [COMMAND]
|
|
20
21
|
USAGE
|
|
21
22
|
$ csdx COMMAND
|
|
22
23
|
...
|
|
23
24
|
```
|
|
24
25
|
<!-- usagestop -->
|
|
26
|
+
|
|
25
27
|
```sh-session
|
|
26
28
|
$ npm install -g @contentstack/cli-cm-clone
|
|
27
29
|
$ csdx COMMAND
|
|
@@ -31,7 +33,9 @@ USAGE
|
|
|
31
33
|
$ csdx COMMAND
|
|
32
34
|
...
|
|
33
35
|
```
|
|
36
|
+
|
|
34
37
|
# Commands
|
|
38
|
+
|
|
35
39
|
<!-- commands -->
|
|
36
40
|
* [`csdx 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]`](#csdx-cmstacksclone---source-branch-value---target-branch-value---source-management-token-alias-value---destination-management-token-alias-value--n-value---type-ab---source-stack-api-key-value---destination-stack-api-key-value---import-webhook-status-disablecurrent)
|
|
37
41
|
* [`csdx 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]`](#csdx-cmstacksclone---source-branch-value---target-branch-value---source-management-token-alias-value---destination-management-token-alias-value--n-value---type-ab---source-stack-api-key-value---destination-stack-api-key-value---import-webhook-status-disablecurrent-1)
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-cm-clone",
|
|
3
3
|
"description": "Contentstack stack clone plugin",
|
|
4
|
-
"version": "1.4.
|
|
4
|
+
"version": "1.4.13",
|
|
5
5
|
"author": "Contentstack",
|
|
6
6
|
"bugs": "https://github.com/rohitmishra209/cli-cm-clone/issues",
|
|
7
7
|
"dependencies": {
|
|
8
|
+
"@contentstack/cli-cm-export": "^1.7.0",
|
|
9
|
+
"@contentstack/cli-cm-import": "^1.7.0",
|
|
10
|
+
"@contentstack/cli-command": "^1.2.11",
|
|
11
|
+
"@contentstack/cli-utilities": "^1.5.1",
|
|
12
|
+
"@contentstack/management": "~1.10.0",
|
|
8
13
|
"@colors/colors": "^1.5.0",
|
|
9
|
-
"@contentstack/cli-cm-export": "^1.5.9",
|
|
10
|
-
"@contentstack/cli-cm-import": "^1.5.11",
|
|
11
|
-
"@contentstack/cli-command": "^1.2.9",
|
|
12
|
-
"@contentstack/cli-utilities": "^1.4.5",
|
|
13
14
|
"async": "^3.2.4",
|
|
14
15
|
"chalk": "^4.1.0",
|
|
15
16
|
"child_process": "^1.0.2",
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
const { Command } = require('@contentstack/cli-command');
|
|
2
2
|
const { configHandler, flags, isAuthenticated, managementSDKClient } = require('@contentstack/cli-utilities');
|
|
3
3
|
const { CloneHandler } = require('../../../lib/util/clone-handler');
|
|
4
|
-
let config = require('../../../lib/util/dummyConfig.json');
|
|
5
4
|
const path = require('path');
|
|
6
5
|
const rimraf = require('rimraf');
|
|
7
6
|
let pathdir = path.join(__dirname.split('src')[0], 'contents');
|
|
8
7
|
const { readdirSync } = require('fs');
|
|
8
|
+
let config = {};
|
|
9
9
|
|
|
10
10
|
class StackCloneCommand extends Command {
|
|
11
11
|
async run() {
|
|
@@ -76,7 +76,7 @@ class StackCloneCommand extends Command {
|
|
|
76
76
|
const cloneHandler = new CloneHandler(config);
|
|
77
77
|
const managementAPIClient = await managementSDKClient(config);
|
|
78
78
|
cloneHandler.setClient(managementAPIClient);
|
|
79
|
-
cloneHandler.execute().catch((error)=>{
|
|
79
|
+
cloneHandler.execute().catch((error) => {
|
|
80
80
|
console.log(error);
|
|
81
81
|
});
|
|
82
82
|
};
|
|
@@ -2,12 +2,13 @@ const ora = require('ora');
|
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const inquirer = require('inquirer');
|
|
4
4
|
const chalk = require('chalk');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
let { default: exportCmd } = require('@contentstack/cli-cm-export');
|
|
7
|
+
let { default: importCmd } = require('@contentstack/cli-cm-import');
|
|
8
|
+
const { CustomAbortController } = require('./abort-controller');
|
|
5
9
|
const prompt = require('prompt');
|
|
6
10
|
const colors = require('@colors/colors/safe');
|
|
7
11
|
|
|
8
|
-
let exportCmd = require('@contentstack/cli-cm-export');
|
|
9
|
-
let importCmd = require('@contentstack/cli-cm-import');
|
|
10
|
-
|
|
11
12
|
const {
|
|
12
13
|
HandleOrgCommand,
|
|
13
14
|
HandleStackCommand,
|
|
@@ -19,6 +20,7 @@ const {
|
|
|
19
20
|
Clone,
|
|
20
21
|
HandleBranchCommand,
|
|
21
22
|
} = require('../helpers/command-helpers');
|
|
23
|
+
const { configHandler } = require('@contentstack/cli-utilities')
|
|
22
24
|
|
|
23
25
|
let client = {};
|
|
24
26
|
let config;
|
|
@@ -60,7 +62,7 @@ let master_locale;
|
|
|
60
62
|
// Overrides prompt's stop method
|
|
61
63
|
prompt.stop = function () {
|
|
62
64
|
if (prompt.stopped) {
|
|
63
|
-
|
|
65
|
+
return;
|
|
64
66
|
}
|
|
65
67
|
prompt.emit('stop');
|
|
66
68
|
prompt.stopped = true;
|
|
@@ -301,7 +303,13 @@ class CloneHandler {
|
|
|
301
303
|
async executeBranchPrompt(parentParams) {
|
|
302
304
|
try {
|
|
303
305
|
this.setExectingCommand(2);
|
|
304
|
-
await cloneCommand.execute(
|
|
306
|
+
await cloneCommand.execute(
|
|
307
|
+
new HandleBranchCommand(
|
|
308
|
+
{ api_key: config.source_stack },
|
|
309
|
+
this,
|
|
310
|
+
this.executeStackPrompt.bind(this, parentParams),
|
|
311
|
+
),
|
|
312
|
+
);
|
|
305
313
|
await this.executeExport();
|
|
306
314
|
} catch (error) {
|
|
307
315
|
throw error;
|
|
@@ -314,7 +322,9 @@ class CloneHandler {
|
|
|
314
322
|
await cloneCommand.execute(new SetBranchCommand(null, this));
|
|
315
323
|
|
|
316
324
|
if (exportRes) {
|
|
317
|
-
this.executeDestination().catch(() => {
|
|
325
|
+
this.executeDestination().catch(() => {
|
|
326
|
+
throw '';
|
|
327
|
+
});
|
|
318
328
|
}
|
|
319
329
|
} catch (error) {
|
|
320
330
|
throw error;
|
|
@@ -340,9 +350,14 @@ class CloneHandler {
|
|
|
340
350
|
|
|
341
351
|
let org;
|
|
342
352
|
if (!config.target_stack) {
|
|
343
|
-
org = await cloneCommand.execute(
|
|
344
|
-
|
|
345
|
-
|
|
353
|
+
org = await cloneCommand.execute(
|
|
354
|
+
new HandleOrgCommand(
|
|
355
|
+
{
|
|
356
|
+
msg: !canCreateStack.stackCreate ? orgMsgExistingStack : orgMsgNewStack,
|
|
357
|
+
},
|
|
358
|
+
this,
|
|
359
|
+
),
|
|
360
|
+
);
|
|
346
361
|
}
|
|
347
362
|
|
|
348
363
|
const params = { org, canCreateStack };
|
|
@@ -402,7 +417,13 @@ class CloneHandler {
|
|
|
402
417
|
async executeBranchDestinationPrompt(parentParams) {
|
|
403
418
|
try {
|
|
404
419
|
this.setExectingCommand(2);
|
|
405
|
-
await cloneCommand.execute(
|
|
420
|
+
await cloneCommand.execute(
|
|
421
|
+
new HandleBranchCommand(
|
|
422
|
+
{ isSource: false, api_key: config.target_stack },
|
|
423
|
+
this,
|
|
424
|
+
this.executeStackDestinationPrompt.bind(this, parentParams),
|
|
425
|
+
),
|
|
426
|
+
);
|
|
406
427
|
this.removeBackKeyPressHandler();
|
|
407
428
|
await cloneCommand.execute(new CloneTypeSelectionCommand(null, this));
|
|
408
429
|
} catch (error) {
|
|
@@ -441,9 +462,17 @@ class CloneHandler {
|
|
|
441
462
|
return new Promise(async (resolve, reject) => {
|
|
442
463
|
const spinner = ora('Fetching Organization').start();
|
|
443
464
|
try {
|
|
444
|
-
let organizations
|
|
465
|
+
let organizations;
|
|
466
|
+
const configOrgUid = configHandler.get('oauthOrgUid');
|
|
467
|
+
|
|
468
|
+
if (configOrgUid) {
|
|
469
|
+
organizations = await client.organization(configOrgUid).fetch();
|
|
470
|
+
} else {
|
|
471
|
+
organizations = await client.organization().fetchAll({ limit: 100 });
|
|
472
|
+
}
|
|
473
|
+
|
|
445
474
|
spinner.succeed('Fetched Organization');
|
|
446
|
-
for (const element of organizations.items) {
|
|
475
|
+
for (const element of organizations.items || [organizations]) {
|
|
447
476
|
orgUidList[element.name] = element.uid;
|
|
448
477
|
orgChoice.choices.push(element.name);
|
|
449
478
|
}
|
|
@@ -529,7 +558,12 @@ class CloneHandler {
|
|
|
529
558
|
|
|
530
559
|
getNewStackPromptResult() {
|
|
531
560
|
return new Promise((resolve) => {
|
|
532
|
-
prompt.get(
|
|
561
|
+
prompt.get(
|
|
562
|
+
{
|
|
563
|
+
properties: {
|
|
564
|
+
name: { description: colors.white(stackName.message), default: colors.grey(stackName.default) },
|
|
565
|
+
},
|
|
566
|
+
},
|
|
533
567
|
function (_, result) {
|
|
534
568
|
if (prompt.stopped) {
|
|
535
569
|
prompt.stopped = false;
|
|
@@ -539,7 +573,8 @@ class CloneHandler {
|
|
|
539
573
|
_name = _name.replace(//g, '');
|
|
540
574
|
resolve({ stack: _name });
|
|
541
575
|
}
|
|
542
|
-
}
|
|
576
|
+
},
|
|
577
|
+
);
|
|
543
578
|
});
|
|
544
579
|
}
|
|
545
580
|
|
|
@@ -597,6 +632,7 @@ class CloneHandler {
|
|
|
597
632
|
|
|
598
633
|
if (config.forceStopMarketplaceAppsPrompt) cmd.push('-y');
|
|
599
634
|
|
|
635
|
+
fs.writeFileSync(path.join(__dirname, 'dummyConfig.json'), JSON.stringify(config));
|
|
600
636
|
let exportData = exportCmd.run(cmd);
|
|
601
637
|
exportData.then(() => resolve(true)).catch(reject);
|
|
602
638
|
});
|
|
@@ -609,8 +645,8 @@ class CloneHandler {
|
|
|
609
645
|
if (config.destination_alias) {
|
|
610
646
|
cmd.push('-a', config.destination_alias);
|
|
611
647
|
}
|
|
612
|
-
if (config.sourceStackBranch) {
|
|
613
|
-
cmd.push('-d', path.join(
|
|
648
|
+
if (!config.data && config.sourceStackBranch) {
|
|
649
|
+
cmd.push('-d', path.join(config.pathDir, config.sourceStackBranch));
|
|
614
650
|
}
|
|
615
651
|
if (config.targetStackBranch) {
|
|
616
652
|
cmd.push('--branch', config.targetStackBranch);
|
|
@@ -621,6 +657,7 @@ class CloneHandler {
|
|
|
621
657
|
|
|
622
658
|
if (config.forceStopMarketplaceAppsPrompt) cmd.push('-y');
|
|
623
659
|
|
|
660
|
+
fs.writeFileSync(path.join(__dirname, 'dummyConfig.json'), JSON.stringify(config));
|
|
624
661
|
await importCmd.run(cmd);
|
|
625
662
|
return resolve();
|
|
626
663
|
});
|