Skip to content
Draft
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
26 changes: 20 additions & 6 deletions .talismanrc
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
fileignoreconfig:
- filename: package-lock.json
checksum: 10993a3e930b77c3c6e09afcb50c23e6a8a901302172b699e92b0a4bfec0cffa
- filename: pnpm-lock.yaml
checksum: 3e47ed021491e9f3c21d25e4ea72a1101b51f16ebedd279019df1792b72417a4
- filename: packages/contentstack-bootstrap/src/bootstrap/utils.ts
checksum: 6e6fb00bb11b03141e5ad27eeaa4af9718dc30520c3e73970bc208cc0ba2a7d2
- filename: pnpm-lock.yaml
checksum: 8a476e69987ac9fda9f8b622cbbf3c35d0625654f0a8b0510e37d17af0b15948
- filename: package-lock.json
checksum: 001e74018a692910c4748816ae9d2ac06d0a105681b89d421a9e99481fb8196c
- filename: packages/contentstack-branches/test/unit/commands/cm/branches/create.test.js
checksum: ee5622594afb486aec7ffe3fa03162bee4e74bc6578358cb515636faaf79f0fd
- filename: packages/contentstack-branches/test/unit/utils/interactive.test.js
checksum: a11c00354f2c770ca2195c368bcaa35d5b2b857ff11edda55d820285f9b262ef
- filename: packages/contentstack-branches/test/unit/commands/cm/branches/delete.test.js
checksum: 9e62382be1b51f123563458b0ee7e530f8ce8cd81e3ddc4a7f709c5a15cdda5a
- filename: packages/contentstack-branches/test/unit/utils/create-merge-scripts.test.js
checksum: bec39d1d3fa042d388c3a5b1ddebd9aef7d970384a1fde7c40399bb7d5854585
- filename: packages/contentstack-branches/src/branch/merge-handler.ts
checksum: 5216f83ab87f3f0c20ee537b1fc16f9c9b3e980b6f4ddf8f8154c9f72dd6efda
- filename: packages/contentstack-branches/test/unit/commands/cm/branches/list.test.js
checksum: 33686e7e986ccc98e3c7fc2b1b6933b04714e0cff1e5b4254b863ff4c202e951
- filename: packages/contentstack-branches/test/unit/utils/diff-branch-handler.test.js
checksum: 83a9b67bfa5c0dd7a8f6735dac546da77ba49da592c2285e2fa7f7a17d4731ba
- filename: packages/contentstack-branches/test/unit/mock/data.js
checksum: 783c530873621536d5763dcc7e03f7fe23e324f0f4bb42244d28a85b9e936f75
version: '1.0'
3,402 changes: 1,711 additions & 1,691 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions packages/contentstack-audit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ $ npm install -g @contentstack/cli-audit
$ csdx COMMAND
running command...
$ csdx (--version|-v)
@contentstack/cli-audit/1.17.1 darwin-arm64 node-v24.13.0
@contentstack/cli-audit/1.18.0 darwin-arm64 node-v24.14.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down Expand Up @@ -309,7 +309,7 @@ EXAMPLES
$ csdx plugins
```

_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.55/src/commands/plugins/index.ts)_
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.56/src/commands/plugins/index.ts)_

## `csdx plugins:add PLUGIN`

Expand Down Expand Up @@ -383,7 +383,7 @@ EXAMPLES
$ csdx plugins:inspect myplugin
```

_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.55/src/commands/plugins/inspect.ts)_
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.56/src/commands/plugins/inspect.ts)_

## `csdx plugins:install PLUGIN`

Expand Down Expand Up @@ -432,7 +432,7 @@ EXAMPLES
$ csdx plugins:install someuser/someplugin
```

_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.55/src/commands/plugins/install.ts)_
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.56/src/commands/plugins/install.ts)_

## `csdx plugins:link PATH`

Expand Down Expand Up @@ -463,7 +463,7 @@ EXAMPLES
$ csdx plugins:link myplugin
```

_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.55/src/commands/plugins/link.ts)_
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.56/src/commands/plugins/link.ts)_

## `csdx plugins:remove [PLUGIN]`

Expand Down Expand Up @@ -504,7 +504,7 @@ FLAGS
--reinstall Reinstall all plugins after uninstalling.
```

_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.55/src/commands/plugins/reset.ts)_
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.56/src/commands/plugins/reset.ts)_

## `csdx plugins:uninstall [PLUGIN]`

Expand Down Expand Up @@ -532,7 +532,7 @@ EXAMPLES
$ csdx plugins:uninstall myplugin
```

_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.55/src/commands/plugins/uninstall.ts)_
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.56/src/commands/plugins/uninstall.ts)_

## `csdx plugins:unlink [PLUGIN]`

Expand Down Expand Up @@ -576,5 +576,5 @@ DESCRIPTION
Update installed plugins.
```

_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.55/src/commands/plugins/update.ts)_
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.56/src/commands/plugins/update.ts)_
<!-- commandsstop -->
2 changes: 1 addition & 1 deletion packages/contentstack-auth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli-auth
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-auth/1.7.2 darwin-arm64 node-v24.13.0
@contentstack/cli-auth/1.7.3 darwin-arm64 node-v24.14.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-bootstrap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ $ npm install -g @contentstack/cli-cm-bootstrap
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-bootstrap/1.18.2 darwin-arm64 node-v24.13.0
@contentstack/cli-cm-bootstrap/1.18.4 darwin-arm64 node-v24.14.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
6 changes: 5 additions & 1 deletion packages/contentstack-branches/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ For switching to AZURE-NA region update the hosts at config/default.js
}
```

## Branch compare cache

Large branch compares write temporary JSONL files under **`<current working directory>/.contentstack-branch-cache/`** (see `cacheDir` in `src/config`). The process needs a **writable working directory**. If disk writes fail, the CLI falls back to an in-memory compare and prints a warning (very large stacks may use more memory).

# Usage

<!-- usage -->
Expand All @@ -37,7 +41,7 @@ $ npm install -g @contentstack/cli-cm-branches
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-branches/1.6.3 darwin-arm64 node-v24.13.0
@contentstack/cli-cm-branches/1.7.0 darwin-arm64 node-v24.14.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
4 changes: 2 additions & 2 deletions 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.6.3",
"version": "1.7.0",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
Expand Down Expand Up @@ -79,4 +79,4 @@
}
},
"repository": "https://github.com/contentstack/cli"
}
}
147 changes: 125 additions & 22 deletions packages/contentstack-branches/src/branch/diff-handler.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import startCase from 'lodash/startCase';
import camelCase from 'lodash/camelCase';
import { cliux } from '@contentstack/cli-utilities';
import { getbranchConfig } from '../utils';
import { BranchOptions, BranchDiffPayload } from '../interfaces';
import { getbranchConfig, cleanupSession } from '../utils';
import { BranchCompareCacheRef, BranchOptions, BranchCompactTextRes, BranchDiffPayload } from '../interfaces';
import { askBaseBranch, askCompareBranch, askStackAPIKey, selectModule } from '../utils/interactive';
import {
fetchBranchesDiff,
Expand All @@ -13,7 +13,14 @@ import {
parseVerbose,
printVerboseTextView,
filterBranchDiffDataByModule,
isBranchCompareCacheRef,
isInlineBranchCompareResult,
summaryFromCompact,
flatCompactToRawArray,
parseSummaryFromJsonlPath,
printCompactTextViewFromJsonlModulePath,
} from '../utils/branch-diff-utility';
import { readAllJsonLines } from '../utils/cache-manager';
import { exportCSVReport } from '../utils/csv-utility';

export default class BranchDiffHandler {
Expand All @@ -24,8 +31,15 @@ export default class BranchDiffHandler {
}

async run(): Promise<any> {
await this.validateMandatoryFlags();
await this.initBranchDiffUtility();
let cacheRef: BranchCompareCacheRef | undefined;
try {
await this.validateMandatoryFlags();
cacheRef = await this.initBranchDiffUtility();
} finally {
if (cacheRef?.kind === 'cache') {
await cleanupSession(cacheRef.sessionId).catch(() => undefined);
}
}
}

/**
Expand All @@ -40,7 +54,7 @@ export default class BranchDiffHandler {
}

if (!this.options.baseBranch) {
baseBranch = getbranchConfig(this.options.stackAPIKey);
baseBranch = getbranchConfig(this.options.stackAPIKey);
if (!baseBranch) {
this.options.baseBranch = await askBaseBranch();
} else {
Expand All @@ -60,24 +74,24 @@ export default class BranchDiffHandler {
this.options.csvPath = process.cwd();
}

if(baseBranch){
if (baseBranch) {
cliux.print(`\nBase branch: ${baseBranch}`, { color: 'grey' });
}
}

/**
* @methods initBranchDiffUtility - call utility function to load data and display it
* @returns {*} {Promise<void>}
* @returns {*} {Promise<BranchCompareCacheRef | undefined>}
* @memberof BranchDiff
*/
async initBranchDiffUtility(): Promise<void> {
async initBranchDiffUtility(): Promise<BranchCompareCacheRef | undefined> {
const spinner = cliux.loaderV2('Loading branch differences...');
const payload: BranchDiffPayload = {
module: '',
apiKey: this.options.stackAPIKey,
baseBranch: this.options.baseBranch,
compareBranch: this.options.compareBranch,
host: this.options.host
host: this.options.host,
};

if (this.options.module === 'content-types') {
Expand All @@ -86,21 +100,107 @@ export default class BranchDiffHandler {
payload.module = 'global_fields';
}
payload.spinner = spinner;
const branchDiffData = await fetchBranchesDiff(payload);
const diffData = filterBranchDiffDataByModule(branchDiffData);
const fetchResult = await fetchBranchesDiff(payload);
cliux.loaderV2('', spinner);

if(this.options.module === 'all'){
for (let module in diffData) {
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);

if (isBranchCompareCacheRef(fetchResult)) {
await this.displayFromCacheRef(fetchResult, payload);
return fetchResult;
}

if (isInlineBranchCompareResult(fetchResult)) {
await this.displayFromInlineResult(fetchResult, payload);
return undefined;
}

const branchDiffData = fetchResult;
const diffData = filterBranchDiffDataByModule(branchDiffData);

if (this.options.module === 'all') {
for (const module in diffData) {
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);
}
return undefined;
}

private async displayFromCacheRef(cacheRef: BranchCompareCacheRef, payload: BranchDiffPayload): Promise<void> {
const modulesToShow =
this.options.module === 'all'
? (['content_types', 'global_fields'] as const)
: payload.module === 'content_types'
? (['content_types'] as const)
: (['global_fields'] as const);

for (const module of modulesToShow) {
const modulePath = cacheRef.paths[module];
const displayModule = module === 'content_types' ? 'content-types' : 'global-fields';
payload.module = module;
cliux.print(' ');
cliux.print(`${startCase(camelCase(module))} Summary:`, { color: 'yellow' });
const diffSummary = await parseSummaryFromJsonlPath(
modulePath,
this.options.baseBranch,
this.options.compareBranch,
);
printSummary(diffSummary);
const spinner1 = cliux.loaderV2('Loading branch differences...');
if (this.options.format === 'compact-text') {
cliux.loaderV2('', spinner1);
await printCompactTextViewFromJsonlModulePath(modulePath);
} else if (this.options.format === 'detailed-text') {
const branchModuleData = await readAllJsonLines(modulePath);
const verboseRes = await parseVerbose(branchModuleData, payload);
cliux.loaderV2('', spinner1);
printVerboseTextView(verboseRes);
exportCSVReport(displayModule, verboseRes, this.options.csvPath);
if (verboseRes.verboseCacheSessionId) {
await cleanupSession(verboseRes.verboseCacheSessionId).catch(() => undefined);
}
}
}
}

private async displayFromInlineResult(
inline: { content_types: BranchCompactTextRes; global_fields: BranchCompactTextRes },
payload: BranchDiffPayload,
): Promise<void> {
const modulesToShow =
this.options.module === 'all'
? (['content_types', 'global_fields'] as const)
: payload.module === 'content_types'
? (['content_types'] as const)
: (['global_fields'] as const);

for (const module of modulesToShow) {
const compact = inline[module];
const displayModule = module === 'content_types' ? 'content-types' : 'global-fields';
payload.module = module;
cliux.print(' ');
cliux.print(`${startCase(camelCase(module))} Summary:`, { color: 'yellow' });
const diffSummary = summaryFromCompact(compact, this.options.baseBranch, this.options.compareBranch);
printSummary(diffSummary);
const spinner1 = cliux.loaderV2('Loading branch differences...');
if (this.options.format === 'compact-text') {
cliux.loaderV2('', spinner1);
printCompactTextView(compact);
} else if (this.options.format === 'detailed-text') {
const branchModuleData = flatCompactToRawArray(compact);
const verboseRes = await parseVerbose(branchModuleData, payload);
cliux.loaderV2('', spinner1);
printVerboseTextView(verboseRes);
exportCSVReport(displayModule, verboseRes, this.options.csvPath);
if (verboseRes.verboseCacheSessionId) {
await cleanupSession(verboseRes.verboseCacheSessionId).catch(() => undefined);
}
}
}
}

Expand Down Expand Up @@ -133,6 +233,9 @@ export default class BranchDiffHandler {
printVerboseTextView(verboseRes);

exportCSVReport(payload.module, verboseRes, this.options.csvPath);
if (verboseRes.verboseCacheSessionId) {
await cleanupSession(verboseRes.verboseCacheSessionId).catch(() => undefined);
}
}
}
}
Loading
Loading