@contentstack/cli-cm-branches 1.0.26 → 1.1.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
CHANGED
|
@@ -37,7 +37,7 @@ $ npm install -g @contentstack/cli-cm-branches
|
|
|
37
37
|
$ csdx COMMAND
|
|
38
38
|
running command...
|
|
39
39
|
$ csdx (--version)
|
|
40
|
-
@contentstack/cli-cm-branches/1.0
|
|
40
|
+
@contentstack/cli-cm-branches/1.1.0 linux-x64 node-v18.20.3
|
|
41
41
|
$ csdx --help [COMMAND]
|
|
42
42
|
USAGE
|
|
43
43
|
$ csdx COMMAND
|
|
@@ -465,6 +465,32 @@ function entryCreateScript(contentType) {
|
|
|
465
465
|
}
|
|
466
466
|
}
|
|
467
467
|
|
|
468
|
+
const getEntries = async (branchName, contentType, skip = 0, limit = 100, entries = []) => {
|
|
469
|
+
let requestObject = {
|
|
470
|
+
skip,
|
|
471
|
+
limit,
|
|
472
|
+
include_count: true,
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
const entriesSearchResponse = await managementAPIClient
|
|
476
|
+
.stack({ api_key: stackSDKInstance.api_key, branch_uid: branchName })
|
|
477
|
+
.contentType(contentType)
|
|
478
|
+
.entry()
|
|
479
|
+
.query(requestObject)
|
|
480
|
+
.find();
|
|
481
|
+
|
|
482
|
+
if (entriesSearchResponse?.items?.length > 0) {
|
|
483
|
+
skip += limit || 100;
|
|
484
|
+
entries = [...entries, ...entriesSearchResponse.items];
|
|
485
|
+
if (skip >= entriesSearchResponse.count) {
|
|
486
|
+
return entries;
|
|
487
|
+
}
|
|
488
|
+
return await getEntries(branchName, contentType, skip, limit, entries);
|
|
489
|
+
}
|
|
490
|
+
return entries;
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
|
|
468
494
|
const createEntryTask = () => {
|
|
469
495
|
return {
|
|
470
496
|
title: 'Create Entries',
|
|
@@ -472,14 +498,9 @@ function entryCreateScript(contentType) {
|
|
|
472
498
|
failedTitle: 'Failed to create entries',
|
|
473
499
|
task: async () => {
|
|
474
500
|
|
|
475
|
-
const compareBranchEntries = await
|
|
476
|
-
.stack({ api_key: stackSDKInstance.api_key, branch_uid: compareBranch })
|
|
477
|
-
.contentType('${contentType}')
|
|
478
|
-
.entry()
|
|
479
|
-
.query()
|
|
480
|
-
.find();
|
|
501
|
+
const compareBranchEntries = await getEntries(compareBranch, '${contentType}')
|
|
481
502
|
|
|
482
|
-
const compareFilteredProperties = compareBranchEntries.
|
|
503
|
+
const compareFilteredProperties = compareBranchEntries.map((entry) => {
|
|
483
504
|
keysToRemove.map((key) => delete entry[key]);
|
|
484
505
|
return entry;
|
|
485
506
|
});
|
|
@@ -489,9 +510,9 @@ function entryCreateScript(contentType) {
|
|
|
489
510
|
.contentType('${contentType}')
|
|
490
511
|
.fetch();
|
|
491
512
|
|
|
492
|
-
for (let i = 0; i < compareBranchEntries?.
|
|
493
|
-
assetRefPath[compareBranchEntries
|
|
494
|
-
findAssets(contentType.schema, compareBranchEntries
|
|
513
|
+
for (let i = 0; i < compareBranchEntries?.length; i++) {
|
|
514
|
+
assetRefPath[compareBranchEntries[i].uid] = []
|
|
515
|
+
findAssets(contentType.schema, compareBranchEntries[i], assetRefPath[compareBranchEntries[i].uid]);
|
|
495
516
|
cAssetDetails = [...new Map(cAssetDetails.map((item) => [item['uid'], item])).values()];
|
|
496
517
|
}
|
|
497
518
|
if (cAssetDetails && cAssetDetails.length) {
|
|
@@ -47,9 +47,9 @@ function entryCreateUpdateScript(contentType) {
|
|
|
47
47
|
|
|
48
48
|
function converter(data) {
|
|
49
49
|
let arr = [];
|
|
50
|
-
for (const elm of data
|
|
50
|
+
for (const elm of data) {
|
|
51
51
|
// @ts-ignore
|
|
52
|
-
arr.push([elm
|
|
52
|
+
arr.push([elm.title, elm]);
|
|
53
53
|
}
|
|
54
54
|
return arr;
|
|
55
55
|
}
|
|
@@ -479,6 +479,30 @@ function entryCreateUpdateScript(contentType) {
|
|
|
479
479
|
}
|
|
480
480
|
};
|
|
481
481
|
|
|
482
|
+
const getEntries = async (branchName, contentType, skip = 0, limit = 100, entries = []) => {
|
|
483
|
+
let requestObject = {
|
|
484
|
+
skip,
|
|
485
|
+
limit,
|
|
486
|
+
include_count: true,
|
|
487
|
+
};
|
|
488
|
+
|
|
489
|
+
const entriesSearchResponse = await managementAPIClient
|
|
490
|
+
.stack({ api_key: stackSDKInstance.api_key, branch_uid: branchName })
|
|
491
|
+
.contentType(contentType)
|
|
492
|
+
.entry()
|
|
493
|
+
.query(requestObject)
|
|
494
|
+
.find();
|
|
495
|
+
|
|
496
|
+
if (entriesSearchResponse?.items?.length > 0) {
|
|
497
|
+
skip += limit || 100;
|
|
498
|
+
entries = [...entries, ...entriesSearchResponse.items];
|
|
499
|
+
if (skip >= entriesSearchResponse.count) {
|
|
500
|
+
return entries;
|
|
501
|
+
}
|
|
502
|
+
return await getEntries(branchName, contentType, skip, limit, entries);
|
|
503
|
+
}
|
|
504
|
+
return entries;
|
|
505
|
+
};
|
|
482
506
|
|
|
483
507
|
const updateEntryTask = () => {
|
|
484
508
|
return {
|
|
@@ -486,28 +510,23 @@ function entryCreateUpdateScript(contentType) {
|
|
|
486
510
|
successMessage: 'Entries Updated Successfully',
|
|
487
511
|
failedMessage: 'Failed to update entries',
|
|
488
512
|
task: async () => {
|
|
489
|
-
|
|
490
|
-
.stack({ api_key: stackSDKInstance.api_key, branch_uid: compareBranch })
|
|
491
|
-
.contentType('${contentType}')
|
|
492
|
-
.entry()
|
|
493
|
-
.query()
|
|
494
|
-
.find();
|
|
513
|
+
let compareBranchEntries = await getEntries(compareBranch, '${contentType}')
|
|
495
514
|
|
|
496
|
-
let baseBranchEntries = await
|
|
515
|
+
let baseBranchEntries = await getEntries(branch, '${contentType}');
|
|
497
516
|
|
|
498
517
|
let contentType = await managementAPIClient
|
|
499
518
|
.stack({ api_key: stackSDKInstance.api_key, branch_uid: compareBranch })
|
|
500
519
|
.contentType('${contentType}')
|
|
501
520
|
.fetch();
|
|
502
521
|
|
|
503
|
-
for (let i = 0; i < compareBranchEntries?.
|
|
504
|
-
assetRefPath[compareBranchEntries
|
|
505
|
-
findAssets(contentType.schema, compareBranchEntries
|
|
522
|
+
for (let i = 0; i < compareBranchEntries?.length; i++) {
|
|
523
|
+
assetRefPath[compareBranchEntries[i].uid] = []
|
|
524
|
+
findAssets(contentType.schema, compareBranchEntries[i], assetRefPath[compareBranchEntries[i].uid]);
|
|
506
525
|
}
|
|
507
526
|
|
|
508
527
|
for (let i = 0; i < baseBranchEntries?.items?.length; i++) {
|
|
509
|
-
assetRefPath[baseBranchEntries
|
|
510
|
-
findAssets(contentType.schema, baseBranchEntries
|
|
528
|
+
assetRefPath[baseBranchEntries[i].uid] = []
|
|
529
|
+
findAssets(contentType.schema, baseBranchEntries[i], assetRefPath[baseBranchEntries[i].uid]);
|
|
511
530
|
}
|
|
512
531
|
assetDetails = [...new Map(assetDetails.map((item) => [item['uid'], item])).values()];
|
|
513
532
|
newAssetDetails = assetDetails;
|
|
@@ -571,12 +590,12 @@ function entryCreateUpdateScript(contentType) {
|
|
|
571
590
|
if(entryDetails !== undefined){
|
|
572
591
|
entryDetails = updateAssetDetailsInEntries(entryDetails);
|
|
573
592
|
|
|
574
|
-
if (baseBranchEntries && baseBranchEntries.
|
|
575
|
-
let baseEntryUid = baseBranchEntries
|
|
593
|
+
if (baseBranchEntries && baseBranchEntries.length) {
|
|
594
|
+
let baseEntryUid = baseBranchEntries[0].uid;
|
|
576
595
|
let entry = await stackSDKInstance.contentType('${contentType}').entry(baseEntryUid);
|
|
577
596
|
|
|
578
597
|
if (flag.references) {
|
|
579
|
-
await updateReferences(entryDetails, baseBranchEntries
|
|
598
|
+
await updateReferences(entryDetails, baseBranchEntries[0], references);
|
|
580
599
|
}
|
|
581
600
|
|
|
582
601
|
await updateEntry(entry, entryDetails);
|
|
@@ -592,19 +611,20 @@ function entryCreateUpdateScript(contentType) {
|
|
|
592
611
|
}
|
|
593
612
|
});
|
|
594
613
|
} else {
|
|
595
|
-
let compareMap = new Map(converter(compareBranchEntries
|
|
596
|
-
let baseMap = new Map(converter(baseBranchEntries
|
|
614
|
+
let compareMap = new Map(converter(compareBranchEntries));
|
|
615
|
+
let baseMap = new Map(converter(baseBranchEntries));
|
|
597
616
|
|
|
598
617
|
//NOTE: Filter distinct entries from the base and compare branches according to their titles.
|
|
599
618
|
//TODO: Need to discuss this approach and replace it with uid condition
|
|
600
619
|
let arr = uniquelyConcatenateArrays(Array.from(compareMap.keys()), Array.from(baseMap.keys()));
|
|
601
620
|
|
|
602
|
-
|
|
603
|
-
|
|
621
|
+
// Change
|
|
622
|
+
for(let i = 0; i < arr.length ; i++){
|
|
623
|
+
let entryDetails = deleteUnwantedKeysFromObject(compareMap.get(arr[i]), keysToRemove);
|
|
604
624
|
//NOTE: In the compare branch, entry must exist. Condition of deleted entry not handled
|
|
605
625
|
if(entryDetails !== undefined){
|
|
606
626
|
entryDetails = updateAssetDetailsInEntries(entryDetails);
|
|
607
|
-
if (compareMap.get(
|
|
627
|
+
if (compareMap.get(arr[i]) && !baseMap.get(arr[i])) {
|
|
608
628
|
let createdEntry = await stackSDKInstance
|
|
609
629
|
.contentType('${contentType}')
|
|
610
630
|
.entry()
|
|
@@ -616,8 +636,8 @@ function entryCreateUpdateScript(contentType) {
|
|
|
616
636
|
}
|
|
617
637
|
await updateEntry(createdEntry, entryDetails);
|
|
618
638
|
}
|
|
619
|
-
} else if (compareMap.get(
|
|
620
|
-
let baseEntry = baseMap.get(
|
|
639
|
+
} else if (compareMap.get(arr[i]) && baseMap.get(arr[i])) {
|
|
640
|
+
let baseEntry = baseMap.get(arr[i]);
|
|
621
641
|
let entry = await stackSDKInstance.contentType('${contentType}').entry(baseEntry.uid);
|
|
622
642
|
|
|
623
643
|
if (flag.references) {
|
|
@@ -627,7 +647,7 @@ function entryCreateUpdateScript(contentType) {
|
|
|
627
647
|
await updateEntry(entry, entryDetails);
|
|
628
648
|
}
|
|
629
649
|
}
|
|
630
|
-
}
|
|
650
|
+
}
|
|
631
651
|
}
|
|
632
652
|
} catch (error) {
|
|
633
653
|
throw error;
|
|
@@ -47,9 +47,9 @@ function entryUpdateScript(contentType) {
|
|
|
47
47
|
|
|
48
48
|
function converter(data) {
|
|
49
49
|
let arr = [];
|
|
50
|
-
for (const elm of data
|
|
50
|
+
for (const elm of data) {
|
|
51
51
|
// @ts-ignore
|
|
52
|
-
arr.push([elm
|
|
52
|
+
arr.push([elm.title, elm]);
|
|
53
53
|
}
|
|
54
54
|
return arr;
|
|
55
55
|
}
|
|
@@ -479,6 +479,31 @@ function entryUpdateScript(contentType) {
|
|
|
479
479
|
}
|
|
480
480
|
};
|
|
481
481
|
|
|
482
|
+
const getEntries = async (branchName, contentType, skip = 0, limit = 100, entries = []) => {
|
|
483
|
+
let requestObject = {
|
|
484
|
+
skip,
|
|
485
|
+
limit,
|
|
486
|
+
include_count: true,
|
|
487
|
+
};
|
|
488
|
+
|
|
489
|
+
const entriesSearchResponse = await managementAPIClient
|
|
490
|
+
.stack({ api_key: stackSDKInstance.api_key, branch_uid: branchName })
|
|
491
|
+
.contentType(contentType)
|
|
492
|
+
.entry()
|
|
493
|
+
.query(requestObject)
|
|
494
|
+
.find();
|
|
495
|
+
|
|
496
|
+
if (entriesSearchResponse?.items?.length > 0) {
|
|
497
|
+
skip += limit || 100;
|
|
498
|
+
entries = [...entries, ...entriesSearchResponse.items];
|
|
499
|
+
if (skip >= entriesSearchResponse.count) {
|
|
500
|
+
return entries;
|
|
501
|
+
}
|
|
502
|
+
return await getEntries(branchName, contentType, skip, limit, entries);
|
|
503
|
+
}
|
|
504
|
+
return entries;
|
|
505
|
+
};
|
|
506
|
+
|
|
482
507
|
const updateEntryTask = () => {
|
|
483
508
|
return {
|
|
484
509
|
title: 'Update Entries',
|
|
@@ -486,28 +511,23 @@ function entryUpdateScript(contentType) {
|
|
|
486
511
|
failedMessage: 'Failed to update entries',
|
|
487
512
|
task: async () => {
|
|
488
513
|
|
|
489
|
-
|
|
490
|
-
.stack({ api_key: stackSDKInstance.api_key, branch_uid: compareBranch })
|
|
491
|
-
.contentType('${contentType}')
|
|
492
|
-
.entry()
|
|
493
|
-
.query()
|
|
494
|
-
.find();
|
|
514
|
+
let compareBranchEntries = await getEntries(compareBranch, '${contentType}');
|
|
495
515
|
|
|
496
|
-
let baseBranchEntries = await
|
|
516
|
+
let baseBranchEntries = await getEntries(branch, '${contentType}');
|
|
497
517
|
|
|
498
518
|
let contentType = await managementAPIClient
|
|
499
519
|
.stack({ api_key: stackSDKInstance.api_key, branch_uid: compareBranch })
|
|
500
520
|
.contentType('${contentType}')
|
|
501
521
|
.fetch();
|
|
502
522
|
|
|
503
|
-
for (let i = 0; i < compareBranchEntries?.
|
|
504
|
-
assetRefPath[compareBranchEntries
|
|
505
|
-
findAssets(contentType.schema, compareBranchEntries
|
|
523
|
+
for (let i = 0; i < compareBranchEntries?.length; i++) {
|
|
524
|
+
assetRefPath[compareBranchEntries[i].uid] = []
|
|
525
|
+
findAssets(contentType.schema, compareBranchEntries[i], assetRefPath[compareBranchEntries[i].uid]);
|
|
506
526
|
}
|
|
507
527
|
|
|
508
|
-
for (let i = 0; i < baseBranchEntries?.
|
|
509
|
-
assetRefPath[baseBranchEntries
|
|
510
|
-
findAssets(contentType.schema, baseBranchEntries
|
|
528
|
+
for (let i = 0; i < baseBranchEntries?.length; i++) {
|
|
529
|
+
assetRefPath[baseBranchEntries[i].uid] = []
|
|
530
|
+
findAssets(contentType.schema, baseBranchEntries[i], assetRefPath[baseBranchEntries[i].uid]);
|
|
511
531
|
}
|
|
512
532
|
assetDetails = [...new Map(assetDetails.map((item) => [item['uid'], item])).values()];
|
|
513
533
|
newAssetDetails = assetDetails;
|
|
@@ -564,16 +584,16 @@ function entryUpdateScript(contentType) {
|
|
|
564
584
|
|
|
565
585
|
try {
|
|
566
586
|
if (contentType?.options?.singleton) {
|
|
567
|
-
compareBranchEntries?.
|
|
587
|
+
compareBranchEntries?.map(async (el) => {
|
|
568
588
|
let entryDetails = deleteUnwantedKeysFromObject(el, keysToRemove);
|
|
569
589
|
if(entryDetails !== undefined){
|
|
570
590
|
entryDetails = updateAssetDetailsInEntries(entryDetails);
|
|
571
|
-
if (baseBranchEntries && baseBranchEntries.
|
|
572
|
-
let baseEntryUid = baseBranchEntries
|
|
591
|
+
if (baseBranchEntries && baseBranchEntries.length) {
|
|
592
|
+
let baseEntryUid = baseBranchEntries[0].uid;
|
|
573
593
|
let entry = await stackSDKInstance.contentType('${contentType}').entry(baseEntryUid);
|
|
574
594
|
|
|
575
595
|
if (flag.references) {
|
|
576
|
-
await updateReferences(entryDetails, baseBranchEntries
|
|
596
|
+
await updateReferences(entryDetails, baseBranchEntries[0], references);
|
|
577
597
|
}
|
|
578
598
|
|
|
579
599
|
await updateEntry(entry, entryDetails);
|
|
@@ -589,8 +609,8 @@ function entryUpdateScript(contentType) {
|
|
|
589
609
|
}
|
|
590
610
|
});
|
|
591
611
|
} else {
|
|
592
|
-
let compareMap = new Map(converter(compareBranchEntries
|
|
593
|
-
let baseMap = new Map(converter(baseBranchEntries
|
|
612
|
+
let compareMap = new Map(converter(compareBranchEntries));
|
|
613
|
+
let baseMap = new Map(converter(baseBranchEntries));
|
|
594
614
|
|
|
595
615
|
//NOTE: Filter distinct entries from the base and compare branches according to their titles.
|
|
596
616
|
//TODO: Need to discuss this approach and replace it with uid approach
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-cm-branches",
|
|
3
3
|
"description": "Contentstack CLI plugin to do branches operations",
|
|
4
|
-
"version": "1.0
|
|
4
|
+
"version": "1.1.0",
|
|
5
5
|
"author": "Contentstack",
|
|
6
6
|
"bugs": "https://github.com/contentstack/cli/issues",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@contentstack/cli-command": "~1.2.18",
|
|
9
9
|
"@contentstack/cli-utilities": "~1.6.2",
|
|
10
|
-
"@oclif/core": "^
|
|
10
|
+
"@oclif/core": "^3.26.5",
|
|
11
11
|
"async": "^3.2.4",
|
|
12
12
|
"big-json": "^3.2.0",
|
|
13
13
|
"bluebird": "^3.7.2",
|
|
@@ -95,4 +95,4 @@
|
|
|
95
95
|
}
|
|
96
96
|
},
|
|
97
97
|
"repository": "https://github.com/contentstack/cli"
|
|
98
|
-
}
|
|
98
|
+
}
|