@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.
@@ -0,0 +1,47 @@
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 delete_branch_1 = require("../../../utils/delete-branch");
6
+ const utils_1 = require("../../../utils");
7
+ class BranchDeleteCommand extends cli_command_1.Command {
8
+ async run() {
9
+ const { flags: branchDeleteFlags } = await this.parse(BranchDeleteCommand);
10
+ let apiKey = branchDeleteFlags['stack-api-key'];
11
+ if (!apiKey) {
12
+ apiKey = await utils_1.interactive.askStackAPIKey();
13
+ }
14
+ if (!branchDeleteFlags.uid) {
15
+ branchDeleteFlags.uid = await utils_1.interactive.askBranchUid();
16
+ }
17
+ if (!branchDeleteFlags.yes) {
18
+ const confirmBranch = await utils_1.interactive.askBranchNameConfirmation();
19
+ if (confirmBranch !== branchDeleteFlags.uid) {
20
+ cli_utilities_1.cliux.error(`error: To delete the branch, enter a valid branch name '${branchDeleteFlags.uid}'`);
21
+ process.exit(1);
22
+ }
23
+ }
24
+ await (0, delete_branch_1.deleteBranch)(this.cmaHost, apiKey, branchDeleteFlags.uid);
25
+ }
26
+ }
27
+ exports.default = BranchDeleteCommand;
28
+ BranchDeleteCommand.description = cli_utilities_1.messageHandler.parse('Delete a branch');
29
+ BranchDeleteCommand.examples = [
30
+ 'csdx cm:branches:delete',
31
+ 'csdx cm:branches:delete --uid main -k bltxxxxxxxx',
32
+ 'csdx cm:branches:delete --uid main --stack-api-key bltxxxxxxxx',
33
+ 'csdx cm:branches:delete --uid main --stack-api-key bltxxxxxxxx --yes',
34
+ ];
35
+ BranchDeleteCommand.usage = [
36
+ 'cm:branches:delete [-uid <value>] [-k <value>]',
37
+ 'cm:branches:delete [--uid <value>] [--stack-api-key <value>]',
38
+ ]; // Note: Add and modify the usage
39
+ BranchDeleteCommand.flags = {
40
+ uid: cli_utilities_1.flags.string({ description: 'Branch UID to be deleted' }),
41
+ 'stack-api-key': cli_utilities_1.flags.string({ char: 'k', description: 'Stack API key' }),
42
+ yes: cli_utilities_1.flags.boolean({
43
+ char: 'y',
44
+ description: 'Force the deletion of the branch by skipping the confirmation',
45
+ }),
46
+ };
47
+ BranchDeleteCommand.aliases = []; // Note: alternative usage if any
@@ -0,0 +1,65 @@
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 branch_1 = require("../../../branch");
6
+ class BranchDiffCommand extends cli_command_1.Command {
7
+ async run() {
8
+ try {
9
+ const { flags: branchDiffFlags } = await this.parse(BranchDiffCommand);
10
+ let options = {
11
+ baseBranch: branchDiffFlags['base-branch'],
12
+ stackAPIKey: branchDiffFlags['stack-api-key'],
13
+ compareBranch: branchDiffFlags['compare-branch'],
14
+ module: branchDiffFlags.module,
15
+ format: branchDiffFlags.format,
16
+ host: this.cmaHost
17
+ };
18
+ const diffHandler = new branch_1.BranchDiffHandler(options);
19
+ await diffHandler.run();
20
+ }
21
+ catch (error) {
22
+ this.error(error, { exit: 1, suggestions: error.suggestions });
23
+ }
24
+ }
25
+ }
26
+ exports.default = BranchDiffCommand;
27
+ BranchDiffCommand.description = cli_utilities_1.messageHandler.parse('Differences between two branches');
28
+ BranchDiffCommand.examples = [
29
+ 'csdx cm:branches:diff',
30
+ 'csdx cm:branches:diff --stack-api-key "bltxxxxxxxx"',
31
+ 'csdx cm:branches:diff --compare-branch "develop"',
32
+ 'csdx cm:branches:diff --compare-branch "develop" --stack-api-key "bltxxxxxxxx"',
33
+ 'csdx cm:branches:diff --compare-branch "develop" --module "content-types"',
34
+ 'csdx cm:branches:diff --module "content-types" --format "detailed-text"',
35
+ 'csdx cm:branches:diff --compare-branch "develop" --format "detailed-text"',
36
+ 'csdx cm:branches:diff --stack-api-key "bltxxxxxxxx" --base-branch "main"',
37
+ 'csdx cm:branches:diff --stack-api-key "bltxxxxxxxx" --base-branch "main" --compare-branch "develop"',
38
+ 'csdx cm:branches:diff --stack-api-key "bltxxxxxxxx" --base-branch "main" --module "content-types"',
39
+ 'csdx cm:branches:diff --stack-api-key "bltxxxxxxxx" --base-branch "main" --compare-branch "develop" --module "content-types"',
40
+ 'csdx cm:branches:diff --stack-api-key "bltxxxxxxxx" --base-branch "main" --compare-branch "develop" --module "content-types" --format "detailed-text"',
41
+ ];
42
+ BranchDiffCommand.usage = 'cm:branches:diff [--base-branch <value>] [--compare-branch <value>] [-k <value>][--module <value>]';
43
+ BranchDiffCommand.flags = {
44
+ 'base-branch': cli_utilities_1.flags.string({
45
+ description: 'Base branch',
46
+ }),
47
+ 'compare-branch': cli_utilities_1.flags.string({
48
+ description: 'Compare branch',
49
+ }),
50
+ module: cli_utilities_1.flags.string({
51
+ description: 'Module',
52
+ options: ['content-types', 'global-fields', 'all'],
53
+ }),
54
+ 'stack-api-key': cli_utilities_1.flags.string({
55
+ char: 'k',
56
+ description: 'Provide Stack API key to show difference between branches',
57
+ }),
58
+ format: cli_utilities_1.flags.string({
59
+ default: 'compact-text',
60
+ multiple: false,
61
+ options: ['compact-text', 'detailed-text'],
62
+ description: '[Optional] Type of flags to show branches differences',
63
+ }),
64
+ };
65
+ BranchDiffCommand.aliases = []; // Note: alternative usage if any
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const cli_command_1 = require("@contentstack/cli-command");
5
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
6
+ const index_1 = require("../../../utils/index");
7
+ const chalk_1 = tslib_1.__importDefault(require("chalk"));
8
+ class BranchListCommand extends cli_command_1.Command {
9
+ async run() {
10
+ var _a;
11
+ try {
12
+ const managementAPIClient = await (0, cli_utilities_1.managementSDKClient)({ host: this.cmaHost });
13
+ const { flags: branchListFlags } = await this.parse(BranchListCommand);
14
+ let stackApiKey = branchListFlags['stack-api-key'];
15
+ let verbose = branchListFlags['verbose'];
16
+ if (!stackApiKey) {
17
+ stackApiKey = await index_1.interactive.askStackAPIKey();
18
+ }
19
+ const baseBranch = (0, index_1.getbranchConfig)(stackApiKey) || 'main';
20
+ const listOfBranch = await managementAPIClient
21
+ .stack({ api_key: stackApiKey })
22
+ .branch()
23
+ .query()
24
+ .find()
25
+ .then(({ items }) => items)
26
+ .catch((err) => {
27
+ (0, index_1.handleErrorMsg)(err);
28
+ });
29
+ if (listOfBranch && listOfBranch.length > 0) {
30
+ let { currentBranch, otherBranches, branches } = (0, index_1.getbranchesList)(listOfBranch, baseBranch);
31
+ if (!verbose) {
32
+ ((_a = currentBranch[0]) === null || _a === void 0 ? void 0 : _a.Source)
33
+ ? cli_utilities_1.cliux.print(`* ${chalk_1.default.bold(currentBranch[0].Branch)} (source: ${currentBranch[0].Source})`, {
34
+ color: 'blue',
35
+ })
36
+ : cli_utilities_1.cliux.print(`* ${chalk_1.default.bold(currentBranch[0].Branch)}`, {
37
+ color: 'blue',
38
+ });
39
+ otherBranches.map(({ Branch, Source }) => {
40
+ Source
41
+ ? cli_utilities_1.cliux.print(`${Branch} (source: ${Source})`, { color: 'blue' })
42
+ : cli_utilities_1.cliux.print(Branch, { color: 'blue' });
43
+ });
44
+ }
45
+ else {
46
+ cli_utilities_1.cliux.table(branches, {
47
+ Branch: {
48
+ minWidth: 8,
49
+ },
50
+ Source: {
51
+ minWidth: 8,
52
+ },
53
+ Aliases: {
54
+ minWidth: 8,
55
+ },
56
+ Created: {
57
+ minWidth: 8,
58
+ },
59
+ Updated: {
60
+ minWidth: 8,
61
+ },
62
+ }, {
63
+ printLine: cli_utilities_1.cliux.print,
64
+ });
65
+ }
66
+ }
67
+ }
68
+ catch (error) {
69
+ cli_utilities_1.cliux.error('error', error);
70
+ }
71
+ }
72
+ }
73
+ exports.default = BranchListCommand;
74
+ BranchListCommand.description = cli_utilities_1.messageHandler.parse('List the branches'); // Note: Update the description
75
+ BranchListCommand.examples = ['csdx cm:branches', 'csdx cm:branches --verbose', 'csdx cm:branches -k <stack api key>']; // Note: Add and modify the examples
76
+ BranchListCommand.usage = 'cm:branches'; // Note: Add and modify the usage
77
+ BranchListCommand.flags = {
78
+ 'stack-api-key': cli_utilities_1.flags.string({ char: 'k', description: 'Stack API Key' }),
79
+ verbose: cli_utilities_1.flags.boolean({ description: 'Verbose' }),
80
+ };
81
+ BranchListCommand.aliases = []; // Note: alternative usage if any
@@ -0,0 +1,94 @@
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 utils_1 = require("../../../utils");
6
+ const branch_1 = require("../../../branch");
7
+ class BranchMergeCommand extends cli_command_1.Command {
8
+ async run() {
9
+ try {
10
+ let { flags: branchMergeFlags } = await this.parse(BranchMergeCommand);
11
+ branchMergeFlags = await (0, utils_1.setupMergeInputs)(branchMergeFlags);
12
+ // display branch status
13
+ const branchCompareData = await (0, utils_1.displayBranchStatus)({
14
+ stackAPIKey: branchMergeFlags['stack-api-key'],
15
+ baseBranch: branchMergeFlags['base-branch'],
16
+ compareBranch: branchMergeFlags['compare-branch'],
17
+ host: this.cmaHost,
18
+ format: 'compact-text',
19
+ });
20
+ await new branch_1.MergeHandler({
21
+ stackAPIKey: branchMergeFlags['stack-api-key'],
22
+ compareBranch: branchMergeFlags['compare-branch'],
23
+ strategy: branchMergeFlags.strategy,
24
+ strategySubOption: branchMergeFlags['strategy-sub-options'],
25
+ baseBranch: branchMergeFlags['base-branch'],
26
+ branchCompareData: branchCompareData,
27
+ mergeComment: branchMergeFlags.comment,
28
+ executeOption: branchMergeFlags['merge-action'],
29
+ noRevert: branchMergeFlags['no-revert'],
30
+ format: 'compact-text',
31
+ exportSummaryPath: branchMergeFlags['export-summary-path'],
32
+ useMergeSummary: branchMergeFlags['use-merge-summary'],
33
+ host: this.cmaHost,
34
+ enableEntryExp: true,
35
+ }).start();
36
+ }
37
+ catch (error) {
38
+ console.log('Error in Merge operations', error);
39
+ }
40
+ }
41
+ }
42
+ exports.default = BranchMergeCommand;
43
+ BranchMergeCommand.description = 'Merge changes from a branch'; //TBD update the description
44
+ BranchMergeCommand.examples = [
45
+ 'csdx cm:branches:merge --stack-api-key bltxxxxxxxx --compare-branch feature-branch',
46
+ 'csdx cm:branches:merge --stack-api-key bltxxxxxxxx --comment "merge comment"',
47
+ 'csdx cm:branches:merge -k bltxxxxxxxx --base-branch base-branch',
48
+ 'csdx cm:branches:merge --export-summary-path file/path',
49
+ 'csdx cm:branches:merge --use-merge-summary file-path',
50
+ 'csdx cm:branches:merge -k bltxxxxxxxx --no-revert',
51
+ 'csdx cm:branches:merge -k bltxxxxxxxx --compare-branch feature-branch --no-revert',
52
+ ];
53
+ BranchMergeCommand.usage = 'cm:branches:merge [-k <value>][--compare-branch <value>] [--no-revert] [--export-summary-path <value>] [--use-merge-summary <value>] [--comment <value>] [--base-branch <value>]';
54
+ // TBD improve flag descriptions
55
+ BranchMergeCommand.flags = {
56
+ 'compare-branch': cli_utilities_1.flags.string({
57
+ description: 'Compare branch name',
58
+ }),
59
+ 'base-branch': cli_utilities_1.flags.string({
60
+ description: 'Base branch',
61
+ }),
62
+ comment: cli_utilities_1.flags.string({
63
+ description: 'Merge comment',
64
+ }),
65
+ 'stack-api-key': cli_utilities_1.flags.string({
66
+ char: 'k',
67
+ description: 'Provide Stack API key to show difference between branches',
68
+ }),
69
+ 'export-summary-path': cli_utilities_1.flags.string({
70
+ description: 'Export summary file path',
71
+ }),
72
+ 'use-merge-summary': cli_utilities_1.flags.string({
73
+ description: 'Path of merge summary file',
74
+ }),
75
+ 'no-revert': cli_utilities_1.flags.boolean({
76
+ description: 'If passed, will not create the new revert branch',
77
+ }),
78
+ strategy: cli_utilities_1.flags.string({
79
+ description: 'Merge strategy',
80
+ options: ['merge_prefer_base', 'merge_prefer_compare', 'overwrite_with_compare', 'custom_preferences'],
81
+ hidden: true,
82
+ }),
83
+ 'strategy-sub-options': cli_utilities_1.flags.string({
84
+ description: 'Merge strategy sub options',
85
+ options: ['new', 'modified', 'both'],
86
+ hidden: true,
87
+ }),
88
+ 'merge-action': cli_utilities_1.flags.string({
89
+ description: 'Merge strategy',
90
+ options: ['export', 'execute', 'both'],
91
+ hidden: true,
92
+ }),
93
+ };
94
+ BranchMergeCommand.aliases = []; // Note: alternative usage if any
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const config = {
4
+ skip: 0,
5
+ limit: 100
6
+ };
7
+ exports.default = config;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });