@contentstack/cli-cm-branches 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Contentstack
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,226 @@
1
+ # @contentstack/cli-cm-export
2
+
3
+ It is Contentstack’s CLI plugin to export content from the stack. To learn how to export and import content in Contentstack, refer to the [Migration guide](https://www.contentstack.com/docs/developers/cli/migration/).
4
+
5
+ [![License](https://img.shields.io/npm/l/@contentstack/cli)](https://github.com/contentstack/cli/blob/main/LICENSE)
6
+
7
+ <!-- toc -->
8
+ * [@contentstack/cli-cm-export](#contentstackcli-cm-export)
9
+ * [Usage](#usage)
10
+ * [Commands](#commands)
11
+ <!-- tocstop -->
12
+
13
+ For switching to EU region update the hosts at config/default.js
14
+
15
+ ```js
16
+ {
17
+ host:'https://eu-api.contentstack.com/v3',
18
+ cdn: 'https://eu-cdn.contentstack.com/v3',
19
+ ...
20
+ }
21
+ ```
22
+
23
+ For switching to AZURE-NA region update the hosts at config/default.js
24
+
25
+ ```js
26
+ {
27
+ host:'https://azure-na-api.contentstack.com/v3',
28
+ cdn: 'https://azure-na-cdn.contentstack.com/v3',
29
+ ...
30
+ }
31
+ ```
32
+
33
+ # Usage
34
+
35
+ <!-- usage -->
36
+ ```sh-session
37
+ $ npm install -g @contentstack/cli-cm-branches
38
+ $ csdx COMMAND
39
+ running command...
40
+ $ csdx (--version)
41
+ @contentstack/cli-cm-branches/1.0.0 linux-x64 node-v16.20.0
42
+ $ csdx --help [COMMAND]
43
+ USAGE
44
+ $ csdx COMMAND
45
+ ...
46
+ ```
47
+ <!-- usagestop -->
48
+
49
+ # Commands
50
+
51
+ <!-- commands -->
52
+ * [`csdx cm:branches`](#csdx-cmbranches)
53
+ * [`csdx cm:branches:create`](#csdx-cmbranchescreate)
54
+ * [`csdx cm:branches:delete [-uid <value>] [-k <value>]`](#csdx-cmbranchesdelete--uid-value--k-value)
55
+ * [`csdx cm:branches:diff [--base-branch <value>] [--compare-branch <value>] [-k <value>][--module <value>]`](#csdx-cmbranchesdiff---base-branch-value---compare-branch-value--k-value--module-value)
56
+ * [`csdx cm:branches:merge [-k <value>][--compare-branch <value>] [--no-revert] [--export-summary-path <value>] [--use-merge-summary <value>] [--comment <value>] [--base-branch <value>]`](#csdx-cmbranchesmerge--k-value--compare-branch-value---no-revert---export-summary-path-value---use-merge-summary-value---comment-value---base-branch-value)
57
+
58
+ ## `csdx cm:branches`
59
+
60
+ List the branches
61
+
62
+ ```
63
+ USAGE
64
+ $ csdx cm:branches
65
+
66
+ FLAGS
67
+ -k, --stack-api-key=<value> Stack API Key
68
+ --verbose Verbose
69
+
70
+ DESCRIPTION
71
+ List the branches
72
+
73
+ EXAMPLES
74
+ $ csdx cm:branches
75
+
76
+ $ csdx cm:branches --verbose
77
+
78
+ $ csdx cm:branches -k <stack api key>
79
+ ```
80
+
81
+ _See code: [src/commands/cm/branches/index.ts](https://github.com/contentstack/cli/blob/main/packages/contentstack-export/src/commands/cm/branches/index.ts)_
82
+
83
+ ## `csdx cm:branches:create`
84
+
85
+ Create a new branch
86
+
87
+ ```
88
+ USAGE
89
+ $ csdx cm:branches:create
90
+ $ csdx cm:branches:create [--source <value>] [--uid <value>] [-k <value>]
91
+ $ csdx cm:branches:create [--source <value>] [--uid <value>] [--stack-api-key <value>]
92
+
93
+ FLAGS
94
+ -k, --stack-api-key=<value> Stack API key
95
+ --source=<value> Source branch from which new branch to be created
96
+ --uid=<value> Branch UID to be created
97
+
98
+ DESCRIPTION
99
+ Create a new branch
100
+
101
+ EXAMPLES
102
+ $ csdx cm:branches:create
103
+
104
+ $ csdx cm:branches:create --source main -uid new_branch -k bltxxxxxxxx
105
+
106
+ $ csdx cm:branches:create --source main --uid new_branch --stack-api-key bltxxxxxxxx
107
+ ```
108
+
109
+ _See code: [src/commands/cm/branches/create.ts](https://github.com/contentstack/cli/blob/main/packages/contentstack-export/src/commands/cm/branches/create.ts)_
110
+
111
+ ## `csdx cm:branches:delete [-uid <value>] [-k <value>]`
112
+
113
+ Delete a branch
114
+
115
+ ```
116
+ USAGE
117
+ $ csdx cm:branches:delete [-uid <value>] [-k <value>]
118
+ $ csdx cm:branches:delete [--uid <value>] [--stack-api-key <value>]
119
+
120
+ FLAGS
121
+ -k, --stack-api-key=<value> Stack API key
122
+ -y, --yes Force the deletion of the branch by skipping the confirmation
123
+ --uid=<value> Branch UID to be deleted
124
+
125
+ DESCRIPTION
126
+ Delete a branch
127
+
128
+ EXAMPLES
129
+ $ csdx cm:branches:delete
130
+
131
+ $ csdx cm:branches:delete --uid main -k bltxxxxxxxx
132
+
133
+ $ csdx cm:branches:delete --uid main --stack-api-key bltxxxxxxxx
134
+
135
+ $ csdx cm:branches:delete --uid main --stack-api-key bltxxxxxxxx --yes
136
+ ```
137
+
138
+ _See code: [src/commands/cm/branches/delete.ts](https://github.com/contentstack/cli/blob/main/packages/contentstack-export/src/commands/cm/branches/delete.ts)_
139
+
140
+ ## `csdx cm:branches:diff [--base-branch <value>] [--compare-branch <value>] [-k <value>][--module <value>]`
141
+
142
+ Differences between two branches
143
+
144
+ ```
145
+ USAGE
146
+ $ csdx cm:branches:diff [--base-branch <value>] [--compare-branch <value>] [-k <value>][--module <value>]
147
+
148
+ FLAGS
149
+ -k, --stack-api-key=<value> Provide Stack API key to show difference between branches
150
+ --base-branch=<value> Base branch
151
+ --compare-branch=<value> Compare branch
152
+ --format=<option> [default: compact-text] [Optional] Type of flags to show branches differences
153
+ <options: compact-text|detailed-text>
154
+ --module=<option> Module
155
+ <options: content-types|global-fields|all>
156
+
157
+ DESCRIPTION
158
+ Differences between two branches
159
+
160
+ EXAMPLES
161
+ $ csdx cm:branches:diff
162
+
163
+ $ csdx cm:branches:diff --stack-api-key "bltxxxxxxxx"
164
+
165
+ $ csdx cm:branches:diff --compare-branch "develop"
166
+
167
+ $ csdx cm:branches:diff --compare-branch "develop" --stack-api-key "bltxxxxxxxx"
168
+
169
+ $ csdx cm:branches:diff --compare-branch "develop" --module "content-types"
170
+
171
+ $ csdx cm:branches:diff --module "content-types" --format "detailed-text"
172
+
173
+ $ csdx cm:branches:diff --compare-branch "develop" --format "detailed-text"
174
+
175
+ $ csdx cm:branches:diff --stack-api-key "bltxxxxxxxx" --base-branch "main"
176
+
177
+ $ csdx cm:branches:diff --stack-api-key "bltxxxxxxxx" --base-branch "main" --compare-branch "develop"
178
+
179
+ $ csdx cm:branches:diff --stack-api-key "bltxxxxxxxx" --base-branch "main" --module "content-types"
180
+
181
+ $ csdx cm:branches:diff --stack-api-key "bltxxxxxxxx" --base-branch "main" --compare-branch "develop" --module "content-types"
182
+
183
+ $ csdx cm:branches:diff --stack-api-key "bltxxxxxxxx" --base-branch "main" --compare-branch "develop" --module "content-types" --format "detailed-text"
184
+ ```
185
+
186
+ _See code: [src/commands/cm/branches/diff.ts](https://github.com/contentstack/cli/blob/main/packages/contentstack-export/src/commands/cm/branches/diff.ts)_
187
+
188
+ ## `csdx cm:branches:merge [-k <value>][--compare-branch <value>] [--no-revert] [--export-summary-path <value>] [--use-merge-summary <value>] [--comment <value>] [--base-branch <value>]`
189
+
190
+ Merge changes from a branch
191
+
192
+ ```
193
+ USAGE
194
+ $ csdx cm:branches:merge [-k <value>][--compare-branch <value>] [--no-revert] [--export-summary-path <value>]
195
+ [--use-merge-summary <value>] [--comment <value>] [--base-branch <value>]
196
+
197
+ FLAGS
198
+ -k, --stack-api-key=<value> Provide Stack API key to show difference between branches
199
+ --base-branch=<value> Base branch
200
+ --comment=<value> Merge comment
201
+ --compare-branch=<value> Compare branch name
202
+ --export-summary-path=<value> Export summary file path
203
+ --no-revert If passed, will not create the new revert branch
204
+ --use-merge-summary=<value> Path of merge summary file
205
+
206
+ DESCRIPTION
207
+ Merge changes from a branch
208
+
209
+ EXAMPLES
210
+ $ csdx cm:branches:merge --stack-api-key bltxxxxxxxx --compare-branch feature-branch
211
+
212
+ $ csdx cm:branches:merge --stack-api-key bltxxxxxxxx --comment "merge comment"
213
+
214
+ $ csdx cm:branches:merge -k bltxxxxxxxx --base-branch base-branch
215
+
216
+ $ csdx cm:branches:merge --export-summary-path file/path
217
+
218
+ $ csdx cm:branches:merge --use-merge-summary file-path
219
+
220
+ $ csdx cm:branches:merge -k bltxxxxxxxx --no-revert
221
+
222
+ $ csdx cm:branches:merge -k bltxxxxxxxx --compare-branch feature-branch --no-revert
223
+ ```
224
+
225
+ _See code: [src/commands/cm/branches/merge.ts](https://github.com/contentstack/cli/blob/main/packages/contentstack-export/src/commands/cm/branches/merge.ts)_
226
+ <!-- commandsstop -->
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const startCase_1 = tslib_1.__importDefault(require("lodash/startCase"));
5
+ const camelCase_1 = tslib_1.__importDefault(require("lodash/camelCase"));
6
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
7
+ const utils_1 = require("../utils");
8
+ const interactive_1 = require("../utils/interactive");
9
+ const branch_diff_utility_1 = require("../utils/branch-diff-utility");
10
+ class BranchDiffHandler {
11
+ constructor(params) {
12
+ this.options = params;
13
+ }
14
+ async run() {
15
+ await this.validateMandatoryFlags();
16
+ await this.initBranchDiffUtility();
17
+ }
18
+ /**
19
+ * @methods validateMandatoryFlags - validate flags and prompt to select required flags
20
+ * @returns {*} {Promise<void>}
21
+ * @memberof BranchDiff
22
+ */
23
+ async validateMandatoryFlags() {
24
+ let baseBranch;
25
+ if (!this.options.stackAPIKey) {
26
+ this.options.stackAPIKey = await (0, interactive_1.askStackAPIKey)();
27
+ }
28
+ if (!this.options.baseBranch) {
29
+ baseBranch = (0, utils_1.getbranchConfig)(this.options.stackAPIKey);
30
+ if (!baseBranch) {
31
+ this.options.baseBranch = await (0, interactive_1.askBaseBranch)();
32
+ }
33
+ else {
34
+ this.options.baseBranch = baseBranch;
35
+ }
36
+ }
37
+ if (!this.options.compareBranch) {
38
+ this.options.compareBranch = await (0, interactive_1.askCompareBranch)();
39
+ }
40
+ if (!this.options.module) {
41
+ this.options.module = await (0, interactive_1.selectModule)();
42
+ }
43
+ if (baseBranch) {
44
+ cli_utilities_1.cliux.print(`\nBase branch: ${baseBranch}`, { color: 'grey' });
45
+ }
46
+ }
47
+ /**
48
+ * @methods initBranchDiffUtility - call utility function to load data and display it
49
+ * @returns {*} {Promise<void>}
50
+ * @memberof BranchDiff
51
+ */
52
+ async initBranchDiffUtility() {
53
+ const spinner = cli_utilities_1.cliux.loaderV2('Loading branch differences...');
54
+ const payload = {
55
+ module: '',
56
+ apiKey: this.options.stackAPIKey,
57
+ baseBranch: this.options.baseBranch,
58
+ compareBranch: this.options.compareBranch,
59
+ host: this.options.host
60
+ };
61
+ if (this.options.module === 'content-types') {
62
+ payload.module = 'content_types';
63
+ }
64
+ else if (this.options.module === 'global-fields') {
65
+ payload.module = 'global_fields';
66
+ }
67
+ payload.spinner = spinner;
68
+ const branchDiffData = await (0, branch_diff_utility_1.fetchBranchesDiff)(payload);
69
+ const diffData = (0, branch_diff_utility_1.filterBranchDiffDataByModule)(branchDiffData);
70
+ cli_utilities_1.cliux.loaderV2('', spinner);
71
+ if (this.options.module === 'all') {
72
+ for (let module in diffData) {
73
+ const branchDiff = diffData[module];
74
+ payload.module = module;
75
+ this.displaySummary(branchDiff, module);
76
+ await this.displayBranchDiffTextAndVerbose(branchDiff, payload);
77
+ }
78
+ }
79
+ else {
80
+ const branchDiff = diffData[payload.module];
81
+ this.displaySummary(branchDiff, this.options.module);
82
+ await this.displayBranchDiffTextAndVerbose(branchDiff, payload);
83
+ }
84
+ }
85
+ /**
86
+ * @methods displaySummary - show branches summary on CLI
87
+ * @returns {*} {void}
88
+ * @memberof BranchDiff
89
+ */
90
+ displaySummary(branchDiffData, module) {
91
+ cli_utilities_1.cliux.print(' ');
92
+ cli_utilities_1.cliux.print(`${(0, startCase_1.default)((0, camelCase_1.default)(module))} Summary:`, { color: 'yellow' });
93
+ const diffSummary = (0, branch_diff_utility_1.parseSummary)(branchDiffData, this.options.baseBranch, this.options.compareBranch);
94
+ (0, branch_diff_utility_1.printSummary)(diffSummary);
95
+ }
96
+ /**
97
+ * @methods displayBranchDiffTextAndVerbose - to show branch differences in compactText or detailText format
98
+ * @returns {*} {void}
99
+ * @memberof BranchDiff
100
+ */
101
+ async displayBranchDiffTextAndVerbose(branchDiffData, payload) {
102
+ const spinner = cli_utilities_1.cliux.loaderV2('Loading branch differences...');
103
+ if (this.options.format === 'compact-text') {
104
+ const branchTextRes = (0, branch_diff_utility_1.parseCompactText)(branchDiffData);
105
+ cli_utilities_1.cliux.loaderV2('', spinner);
106
+ (0, branch_diff_utility_1.printCompactTextView)(branchTextRes);
107
+ }
108
+ else if (this.options.format === 'detailed-text') {
109
+ const verboseRes = await (0, branch_diff_utility_1.parseVerbose)(branchDiffData, payload);
110
+ cli_utilities_1.cliux.loaderV2('', spinner);
111
+ (0, branch_diff_utility_1.printVerboseTextView)(verboseRes);
112
+ }
113
+ }
114
+ }
115
+ exports.default = BranchDiffHandler;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ /**
3
+ * Business logics can be written inside this directory
4
+ */
5
+ var __importDefault = (this && this.__importDefault) || function (mod) {
6
+ return (mod && mod.__esModule) ? mod : { "default": mod };
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.BranchDiffHandler = exports.MergeHandler = void 0;
10
+ var merge_handler_1 = require("./merge-handler");
11
+ Object.defineProperty(exports, "MergeHandler", { enumerable: true, get: function () { return __importDefault(merge_handler_1).default; } });
12
+ var diff_handler_1 = require("./diff-handler");
13
+ Object.defineProperty(exports, "BranchDiffHandler", { enumerable: true, get: function () { return __importDefault(diff_handler_1).default; } });
@@ -0,0 +1,227 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const path_1 = tslib_1.__importDefault(require("path"));
5
+ const forEach_1 = tslib_1.__importDefault(require("lodash/forEach"));
6
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
7
+ const utils_1 = require("../utils");
8
+ const enableEntryExp = false;
9
+ class MergeHandler {
10
+ constructor(options) {
11
+ this.stackAPIKey = options.stackAPIKey;
12
+ this.strategy = options.strategy;
13
+ this.strategySubOption = options.strategySubOption;
14
+ this.executeOption = options.executeOption;
15
+ this.branchCompareData = options.branchCompareData;
16
+ this.displayFormat = options.format;
17
+ this.exportSummaryPath = options.exportSummaryPath || path_1.default.resolve(process.cwd());
18
+ this.useMergeSummary = options.useMergeSummary;
19
+ this.userInputs = options;
20
+ this.mergeSettings = {
21
+ baseBranch: options.baseBranch,
22
+ compareBranch: options.compareBranch,
23
+ mergeComment: options.mergeComment,
24
+ mergeContent: {},
25
+ noRevert: options.noRevert,
26
+ };
27
+ this.host = options.host;
28
+ this.enableEntryExp = options.enableEntryExp;
29
+ }
30
+ async start() {
31
+ await this.collectMergeSettings();
32
+ // Merge final process
33
+ const mergePayload = (0, utils_1.prepareMergeRequestPayload)(this.mergeSettings);
34
+ if (this.executeOption === 'execute') {
35
+ await this.executeMerge(mergePayload);
36
+ }
37
+ else if (this.executeOption === 'export') {
38
+ await this.exportSummary(mergePayload);
39
+ }
40
+ else {
41
+ await this.exportSummary(mergePayload);
42
+ await this.executeMerge(mergePayload);
43
+ }
44
+ }
45
+ async collectMergeSettings() {
46
+ if (!this.strategy) {
47
+ this.strategy = await (0, utils_1.selectMergeStrategy)();
48
+ }
49
+ if (!this.strategySubOption &&
50
+ this.strategy !== 'custom_preferences' &&
51
+ this.strategy !== 'overwrite_with_compare') {
52
+ const strategyResponse = await (0, utils_1.selectMergeStrategySubOptions)();
53
+ if (strategyResponse === 'previous') {
54
+ this.strategy = null;
55
+ return await this.collectMergeSettings();
56
+ }
57
+ else if (strategyResponse === 'restart') {
58
+ return await this.restartMergeProcess();
59
+ }
60
+ else {
61
+ this.strategySubOption = strategyResponse;
62
+ }
63
+ }
64
+ if (this.strategy === 'custom_preferences') {
65
+ this.mergeSettings.itemMergeStrategies = [];
66
+ for (let module in this.branchCompareData) {
67
+ this.mergeSettings.mergeContent[module] = {
68
+ added: [],
69
+ modified: [],
70
+ deleted: [],
71
+ };
72
+ const selectedItems = await (0, utils_1.selectCustomPreferences)(module, this.branchCompareData[module]);
73
+ (0, forEach_1.default)(selectedItems, (item) => {
74
+ this.mergeSettings.mergeContent[module][item.status].push(item.value);
75
+ this.mergeSettings.itemMergeStrategies.push(item.value);
76
+ });
77
+ this.mergeSettings.strategy = 'ignore';
78
+ }
79
+ }
80
+ else if (this.strategy === 'merge_prefer_base') {
81
+ if (this.strategySubOption === 'new') {
82
+ this.mergeSettings.strategy = 'merge_new_only';
83
+ }
84
+ else if (this.strategySubOption === 'modified') {
85
+ this.mergeSettings.strategy = 'merge_modified_only_prefer_base';
86
+ }
87
+ else if (this.strategySubOption === 'both') {
88
+ this.mergeSettings.strategy = 'merge_prefer_base';
89
+ }
90
+ }
91
+ else if (this.strategy === 'merge_prefer_compare') {
92
+ if (this.strategySubOption === 'new') {
93
+ this.mergeSettings.strategy = 'merge_new_only';
94
+ }
95
+ else if (this.strategySubOption === 'modified') {
96
+ this.mergeSettings.strategy = 'merge_modified_only_prefer_compare';
97
+ }
98
+ else if (this.strategySubOption === 'both') {
99
+ this.mergeSettings.strategy = 'merge_prefer_compare';
100
+ }
101
+ }
102
+ else if (this.strategy === 'overwrite_with_compare') {
103
+ this.mergeSettings.strategy = 'overwrite_with_compare';
104
+ }
105
+ await this.displayMergeSummary();
106
+ if (!this.executeOption) {
107
+ const executionResponse = await (0, utils_1.selectMergeExecution)();
108
+ if (executionResponse === 'previous') {
109
+ if (this.strategy !== 'custom_preferences' && this.strategy !== 'overwrite_with_compare') {
110
+ this.strategySubOption = null;
111
+ return await this.collectMergeSettings();
112
+ }
113
+ else {
114
+ return await this.restartMergeProcess();
115
+ }
116
+ }
117
+ else if (executionResponse === 'restart') {
118
+ return await this.restartMergeProcess();
119
+ }
120
+ else {
121
+ this.executeOption = executionResponse;
122
+ }
123
+ }
124
+ }
125
+ displayMergeSummary() {
126
+ if (this.mergeSettings.strategy !== 'ignore') {
127
+ for (let module in this.branchCompareData) {
128
+ this.mergeSettings.mergeContent[module] = {};
129
+ this.filterBranchCompareData(module, this.branchCompareData[module]);
130
+ }
131
+ }
132
+ (0, utils_1.displayMergeSummary)({
133
+ format: this.displayFormat,
134
+ compareData: this.mergeSettings.mergeContent,
135
+ });
136
+ }
137
+ filterBranchCompareData(module, moduleBranchCompareData) {
138
+ const { strategy, mergeContent } = this.mergeSettings;
139
+ switch (strategy) {
140
+ case 'merge_prefer_base':
141
+ mergeContent[module].added = moduleBranchCompareData.added;
142
+ mergeContent[module].modified = moduleBranchCompareData.modified;
143
+ mergeContent[module].deleted = moduleBranchCompareData.deleted;
144
+ break;
145
+ case 'merge_prefer_compare':
146
+ mergeContent[module].added = moduleBranchCompareData.added;
147
+ mergeContent[module].modified = moduleBranchCompareData.modified;
148
+ mergeContent[module].deleted = moduleBranchCompareData.deleted;
149
+ break;
150
+ case 'merge_new_only':
151
+ mergeContent[module].added = moduleBranchCompareData.added;
152
+ break;
153
+ case 'merge_modified_only_prefer_base':
154
+ mergeContent[module].modified = moduleBranchCompareData.modified;
155
+ break;
156
+ case 'merge_modified_only_prefer_compare':
157
+ mergeContent[module].modified = moduleBranchCompareData.modified;
158
+ break;
159
+ case 'merge_modified_only_prefer_compare':
160
+ mergeContent[module].modified = moduleBranchCompareData.modified;
161
+ break;
162
+ case 'overwrite_with_compare':
163
+ mergeContent[module].added = moduleBranchCompareData.added;
164
+ mergeContent[module].modified = moduleBranchCompareData.modified;
165
+ mergeContent[module].deleted = moduleBranchCompareData.deleted;
166
+ break;
167
+ default:
168
+ cli_utilities_1.cliux.error(`error: Invalid strategy ${strategy}`);
169
+ process.exit(1);
170
+ }
171
+ }
172
+ async exportSummary(mergePayload) {
173
+ if (!this.exportSummaryPath) {
174
+ this.exportSummaryPath = await (0, utils_1.askExportMergeSummaryPath)();
175
+ }
176
+ const summary = {
177
+ requestPayload: mergePayload,
178
+ };
179
+ await (0, utils_1.writeFile)(path_1.default.join(this.exportSummaryPath, 'merge-summary.json'), summary);
180
+ cli_utilities_1.cliux.success('Exported the summary successfully');
181
+ }
182
+ async executeMerge(mergePayload) {
183
+ let spinner;
184
+ try {
185
+ if (!this.mergeSettings.mergeComment) {
186
+ this.mergeSettings.mergeComment = await (0, utils_1.askMergeComment)();
187
+ mergePayload.merge_comment = this.mergeSettings.mergeComment;
188
+ }
189
+ spinner = cli_utilities_1.cliux.loaderV2('Merging the changes...');
190
+ const mergeResponse = await (0, utils_1.executeMerge)(this.stackAPIKey, mergePayload, this.host);
191
+ cli_utilities_1.cliux.loaderV2('', spinner);
192
+ cli_utilities_1.cliux.success(`Merged the changes successfully. Merge UID: ${mergeResponse.uid}`);
193
+ if (this.enableEntryExp) {
194
+ this.executeEntryExpFlow(mergeResponse.uid, mergePayload);
195
+ }
196
+ }
197
+ catch (error) {
198
+ cli_utilities_1.cliux.loaderV2('', spinner);
199
+ cli_utilities_1.cliux.error('Failed to merge the changes', error.message || error);
200
+ }
201
+ }
202
+ executeEntryExpFlow(mergeJobUID, mergePayload) {
203
+ let scriptFolderPath = (0, utils_1.generateMergeScripts)(this.mergeSettings.mergeContent, mergeJobUID);
204
+ if (scriptFolderPath !== undefined) {
205
+ cli_utilities_1.cliux.success(`\nSuccess! We have generated entry migration files in the folder ${scriptFolderPath}`);
206
+ cli_utilities_1.cliux.print(`\nKindly follow the steps in the guide "https://www.contentstack.com/docs/developers/cli/migrate-branch-entries" to update the migration scripts, and then run the command \n\ncsdx cm:stacks:migration --multiple --file-path ./${scriptFolderPath} --config compare-branch:${mergePayload.compare_branch} --branch ${mergePayload.base_branch} --stack-api-key ${this.stackAPIKey}`, { color: 'blue' });
207
+ }
208
+ }
209
+ async restartMergeProcess() {
210
+ if (!this.userInputs.strategy) {
211
+ this.strategy = null;
212
+ }
213
+ if (!this.userInputs.strategySubOption) {
214
+ this.strategySubOption = null;
215
+ }
216
+ if (!this.userInputs.executeOption) {
217
+ this.executeOption = null;
218
+ }
219
+ if (!this.userInputs.executeOption) {
220
+ this.executeOption = null;
221
+ }
222
+ this.mergeSettings.strategy = null;
223
+ this.mergeSettings.itemMergeStrategies = [];
224
+ await this.start();
225
+ }
226
+ }
227
+ exports.default = MergeHandler;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const cli_command_1 = require("@contentstack/cli-command");
4
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
5
+ const create_branch_1 = require("../../../utils/create-branch");
6
+ const utils_1 = require("../../../utils");
7
+ class BranchCreateCommand extends cli_command_1.Command {
8
+ async run() {
9
+ const { flags: branchCreateFlags } = await this.parse(BranchCreateCommand);
10
+ let apiKey = branchCreateFlags['stack-api-key'];
11
+ let branch = {
12
+ uid: branchCreateFlags.uid,
13
+ source: branchCreateFlags.source,
14
+ };
15
+ if (!apiKey) {
16
+ apiKey = await utils_1.interactive.askStackAPIKey();
17
+ }
18
+ if (!branchCreateFlags.source) {
19
+ branch.source = await utils_1.interactive.askSourceBranch();
20
+ }
21
+ if (!branchCreateFlags.uid) {
22
+ branch.uid = await utils_1.interactive.askBranchUid();
23
+ }
24
+ await (0, create_branch_1.createBranch)(this.cmaHost, apiKey, branch);
25
+ }
26
+ }
27
+ exports.default = BranchCreateCommand;
28
+ BranchCreateCommand.description = cli_utilities_1.messageHandler.parse('Create a new branch'); // Note: Update the description
29
+ BranchCreateCommand.examples = [
30
+ 'csdx cm:branches:create',
31
+ 'csdx cm:branches:create --source main -uid new_branch -k bltxxxxxxxx',
32
+ 'csdx cm:branches:create --source main --uid new_branch --stack-api-key bltxxxxxxxx',
33
+ ]; // Note: Add and modify the examples
34
+ BranchCreateCommand.usage = [
35
+ 'cm:branches:create',
36
+ 'cm:branches:create [--source <value>] [--uid <value>] [-k <value>]',
37
+ 'cm:branches:create [--source <value>] [--uid <value>] [--stack-api-key <value>]',
38
+ ]; // Note: Add and modify the usage
39
+ BranchCreateCommand.flags = {
40
+ uid: cli_utilities_1.flags.string({ description: 'Branch UID to be created' }),
41
+ source: cli_utilities_1.flags.string({ description: 'Source branch from which new branch to be created' }),
42
+ 'stack-api-key': cli_utilities_1.flags.string({ char: 'k', description: 'Stack API key' }),
43
+ };
44
+ BranchCreateCommand.aliases = []; // Note: alternative usage if any