Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .talismanrc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
fileignoreconfig:
- filename: package-lock.json
checksum: 560538910aada20a4c770b19f977bbe62680ca86ec6f5c3eb4b5a61e4f3f1a49
checksum: fcf443a7d000c204976bec6de43a0d454184090bf7133325df0009fe245295b2
- filename: pnpm-lock.yaml
checksum: 713cd001a5929ee85ab17eb7ef96c32a2b23878685a3ed74604a6ba6fd579058
checksum: 577582ed82062ad359d8bc2bc0a309ab4d344a2a4122573d8cf77aeb481268f2
- filename: packages/contentstack-import-setup/test/unit/backup-handler.test.ts
checksum: 0582d62b88834554cf12951c8690a73ef3ddbb78b82d2804d994cf4148e1ef93
- filename: packages/contentstack-import-setup/test/config.json
Expand Down
423 changes: 212 additions & 211 deletions package-lock.json

Large diffs are not rendered by default.

15 changes: 11 additions & 4 deletions packages/contentstack-branches/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ $ npm install -g @contentstack/cli-cm-branches
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-branches/1.5.0 darwin-arm64 node-v23.11.0
@contentstack/cli-cm-branches/1.6.0 darwin-arm64 node-v22.13.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand All @@ -51,7 +51,7 @@ USAGE
* [`csdx cm:branches`](#csdx-cmbranches)
* [`csdx cm:branches:create`](#csdx-cmbranchescreate)
* [`csdx cm:branches:delete [-uid <value>] [-k <value>]`](#csdx-cmbranchesdelete--uid-value--k-value)
* [`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)
* [`csdx cm:branches:diff [--base-branch <value>] [--compare-branch <value>] [-k <value>][--module <value>] [--format <value>] [--csv-path <value>]`](#csdx-cmbranchesdiff---base-branch-value---compare-branch-value--k-value--module-value---format-value---csv-path-value)
* [`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)

## `csdx cm:branches`
Expand Down Expand Up @@ -136,18 +136,21 @@ EXAMPLES

_See code: [src/commands/cm/branches/delete.ts](https://github.com/contentstack/cli/blob/main/packages/contentstack-export/src/commands/cm/branches/delete.ts)_

## `csdx cm:branches:diff [--base-branch <value>] [--compare-branch <value>] [-k <value>][--module <value>]`
## `csdx cm:branches:diff [--base-branch <value>] [--compare-branch <value>] [-k <value>][--module <value>] [--format <value>] [--csv-path <value>]`

Differences between two branches

```
USAGE
$ csdx cm:branches:diff [--base-branch <value>] [--compare-branch <value>] [-k <value>][--module <value>]
$ csdx cm:branches:diff [--base-branch <value>] [--compare-branch <value>] [-k <value>][--module <value>] [--format
<value>] [--csv-path <value>]

FLAGS
-k, --stack-api-key=<value> [optional] Provide the stack API key to show the difference between branches.
--base-branch=<value> [optional] Base branch (Target branch).
--compare-branch=<value> [optional] Compare branch (Source branch).
--csv-path=<value> [optional] Custom path for CSV output file. If not provided, will use the current
working directory.
--format=<option> [default: compact-text] [default: compact-text] [optional] Type of flags to show the
difference between two branches. <options: compact-text, detailed-text>
<options: compact-text|detailed-text>
Expand Down Expand Up @@ -181,6 +184,10 @@ EXAMPLES
$ csdx cm:branches:diff --stack-api-key "bltxxxxxxxx" --base-branch "main" --compare-branch "develop" --module "content-types"

$ csdx cm:branches:diff --stack-api-key "bltxxxxxxxx" --base-branch "main" --compare-branch "develop" --module "content-types" --format "detailed-text"

$ csdx cm:branches:diff --stack-api-key "bltxxxxxxxx" --base-branch "main" --compare-branch "develop" --module "content-types" --format "compact-text"

$ csdx cm:branches:diff --stack-api-key "bltxxxxxxxx" --base-branch "main" --compare-branch "develop" --module "content-types" --format "detailed-text" --csv-path "./reports/diff-report.csv"
```

_See code: [src/commands/cm/branches/diff.ts](https://github.com/contentstack/cli/blob/main/packages/contentstack-export/src/commands/cm/branches/diff.ts)_
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-branches/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@contentstack/cli-cm-branches",
"description": "Contentstack CLI plugin to do branches operations",
"version": "1.5.2",
"version": "1.6.0",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
Expand Down
17 changes: 12 additions & 5 deletions packages/contentstack-branches/src/branch/diff-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import startCase from 'lodash/startCase';
import camelCase from 'lodash/camelCase';
import { cliux } from '@contentstack/cli-utilities';
import { getbranchConfig } from '../utils';
import { BranchOptions, BranchDiffRes, BranchDiffPayload } from '../interfaces';
import { BranchOptions, BranchDiffPayload } from '../interfaces';
import { askBaseBranch, askCompareBranch, askStackAPIKey, selectModule } from '../utils/interactive';
import {
fetchBranchesDiff,
Expand All @@ -14,6 +14,7 @@ import {
printVerboseTextView,
filterBranchDiffDataByModule,
} from '../utils/branch-diff-utility';
import { exportCSVReport } from '../utils/csv-utility';

export default class BranchDiffHandler {
private options: BranchOptions;
Expand Down Expand Up @@ -55,6 +56,10 @@ export default class BranchDiffHandler {
this.options.module = await selectModule();
}

if (this.options.format === 'detailed-text' && !this.options.csvPath) {
this.options.csvPath = process.cwd();
}

if(baseBranch){
cliux.print(`\nBase branch: ${baseBranch}`, { color: 'grey' });
}
Expand Down Expand Up @@ -87,15 +92,15 @@ export default class BranchDiffHandler {

if(this.options.module === 'all'){
for (let module in diffData) {
const branchDiff = diffData[module];
const branchDiff = diffData[module];
payload.module = module;
this.displaySummary(branchDiff, module);
await this.displayBranchDiffTextAndVerbose(branchDiff, payload);
}
}else{
const branchDiff = diffData[payload.module];
this.displaySummary(branchDiff, this.options.module);
await this.displayBranchDiffTextAndVerbose(branchDiff, payload);
const branchDiff = diffData[payload.module];
this.displaySummary(branchDiff, this.options.module);
await this.displayBranchDiffTextAndVerbose(branchDiff, payload);
}
}

Expand Down Expand Up @@ -126,6 +131,8 @@ export default class BranchDiffHandler {
const verboseRes = await parseVerbose(branchDiffData, payload);
cliux.loaderV2('', spinner);
printVerboseTextView(verboseRes);

exportCSVReport(payload.module, verboseRes, this.options.csvPath);
}
}
}
18 changes: 13 additions & 5 deletions packages/contentstack-branches/src/commands/cm/branches/diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ export default class BranchDiffCommand extends Command {
'csdx cm:branches:diff --stack-api-key "bltxxxxxxxx" --base-branch "main" --module "content-types"',
'csdx cm:branches:diff --stack-api-key "bltxxxxxxxx" --base-branch "main" --compare-branch "develop" --module "content-types"',
'csdx cm:branches:diff --stack-api-key "bltxxxxxxxx" --base-branch "main" --compare-branch "develop" --module "content-types" --format "detailed-text"',
]
'csdx cm:branches:diff --stack-api-key "bltxxxxxxxx" --base-branch "main" --compare-branch "develop" --module "content-types" --format "compact-text"',
'csdx cm:branches:diff --stack-api-key "bltxxxxxxxx" --base-branch "main" --compare-branch "develop" --module "content-types" --format "detailed-text" --csv-path "./reports/diff-report.csv"',
];

static usage: string = 'cm:branches:diff [--base-branch <value>] [--compare-branch <value>] [-k <value>][--module <value>]';
static usage: string =
'cm:branches:diff [--base-branch <value>] [--compare-branch <value>] [-k <value>][--module <value>] [--format <value>] [--csv-path <value>]';

static flags = {
'base-branch': flags.string({
Expand All @@ -43,9 +46,13 @@ export default class BranchDiffCommand extends Command {
default: 'compact-text',
multiple: false,
options: ['compact-text', 'detailed-text'],
description: '[default: compact-text] [optional] Type of flags to show the difference between two branches. <options: compact-text, detailed-text>',
description:
'[default: compact-text] [optional] Type of flags to show the difference between two branches. <options: compact-text, detailed-text>',
}),
};
'csv-path': flags.string({
description: '[optional] Custom path for CSV output file. If not provided, will use the current working directory.',
}),
};

static aliases: string[] = []; // Note: alternative usage if any

Expand All @@ -58,7 +65,8 @@ export default class BranchDiffCommand extends Command {
compareBranch: branchDiffFlags['compare-branch'],
module: branchDiffFlags.module,
format: branchDiffFlags.format,
host: this.cmaHost
csvPath: branchDiffFlags['csv-path'],
host: this.cmaHost,
};
if (!isAuthenticated()) {
const err = { errorMessage: 'You are not logged in. Please login with command $ csdx auth:login' };
Expand Down
42 changes: 42 additions & 0 deletions packages/contentstack-branches/src/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface BranchOptions {
baseBranch?: string;
authToken?: string;
host?: string;
csvPath?: string;
}

export interface BranchDiffRes {
Expand Down Expand Up @@ -64,6 +65,46 @@ export interface ModifiedFieldsType {
displayName: string;
path: string;
field: string;
propertyChanges?: PropertyChange[];
changeCount?: number;
changeDetails?: string;
oldValue?: any;
newValue?: any;
}

export interface PropertyChange {
property: string;
changeType: 'modified' | 'added' | 'deleted';
oldValue?: any;
newValue?: any;
}

export interface CSVRow {
srNo: number;
contentTypeName: string;
fieldName: string;
fieldPath: string;
operation: string;
sourceBranchValue: string;
targetBranchValue: string;
}

export interface AddCSVRowParams {
srNo: number;
contentTypeName: string;
fieldName: string;
fieldType: string;
sourceValue: string;
targetValue: string;
}

export const FIELD_TYPES = ['modified', 'added', 'deleted'] as const;

export const CSV_HEADER = 'Sr No,Content Type Name,Field Name,Field Path,Operation,Source Branch Value,Target Branch Value\n';

export interface ContentTypeItem {
title?: string;
uid?: string;
}

export interface ModifiedFieldsInput {
Expand All @@ -81,6 +122,7 @@ export interface BranchDiffVerboseRes {
modified?: BranchModifiedDetails[];
added?: BranchDiffRes[];
deleted?: BranchDiffRes[];
csvData?: CSVRow[]; // Pre-processed CSV data
}

export interface BranchDiffPayload {
Expand Down
Loading
Loading