Skip to content

Commit 1c045da

Browse files
authored
Merge pull request #36 from contentstack/enhc/DX-5171
fix(import): align import with single-branch export, import; path resolution and target branch handling
2 parents 4a2e217 + 35f524a commit 1c045da

57 files changed

Lines changed: 1912 additions & 1904 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/contentstack-clone/src/core/util/clone-handler.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -644,8 +644,8 @@ export class CloneHandler {
644644
importConfig.contentDir = importConfig.data;
645645
}
646646

647-
if (!importConfig.contentDir && importConfig.sourceStackBranch && importConfig.pathDir) {
648-
const dataPath = path.join(importConfig.pathDir, importConfig.sourceStackBranch);
647+
if (!importConfig.contentDir && importConfig.pathDir) {
648+
const dataPath = importConfig.pathDir;
649649
cmd.push('-d', dataPath);
650650
log.debug(`Import data path: ${dataPath}`, this.config.cloneContext);
651651
}
@@ -675,7 +675,7 @@ export class CloneHandler {
675675
cmd: cmd.join(' '),
676676
targetStack: importConfig.apiKey || importConfig.target_stack,
677677
targetBranch: importConfig.targetStackBranch,
678-
dataPath: importConfig.contentDir || (importConfig.pathDir && importConfig.sourceStackBranch ? path.join(importConfig.pathDir, importConfig.sourceStackBranch) : undefined)
678+
dataPath: importConfig.contentDir || importConfig.pathDir || undefined
679679
});
680680
log.debug('Running import command', { ...this.config.cloneContext, cmd });
681681
const importData = importCmd.run(cmd);
@@ -804,9 +804,10 @@ export class CloneHandler {
804804
];
805805
let successMsg: string;
806806
let selectedValue: any = {};
807-
// Resolve path to package root - go up 3 levels from __dirname (core/util -> package root)
807+
// Export root only (single-branch layout: modules live directly under -d, not pathDir/<branch>)
808808
const cloneTypePackageRoot = path.resolve(__dirname, '../../..');
809-
this.config.contentDir = path.join(cloneTypePackageRoot, 'contents', this.config.sourceStackBranch || '');
809+
this.config.contentDir =
810+
this.config.pathDir || path.join(cloneTypePackageRoot, 'contents');
810811
log.debug(`Clone content directory: ${this.config.contentDir}`, this.config.cloneContext);
811812

812813
if (!this.config.cloneType) {

packages/contentstack-clone/src/types/clone-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export interface CloneConfig {
3131
forceStopMarketplaceAppsPrompt?: boolean;
3232

3333
// Data and modules
34-
/** Path to exported content for import (aligns with import plugin's contentDir) */
34+
/** Export root directory for import (same path as export `-d`; not a branch-named subdirectory) */
3535
contentDir?: string;
3636
modules?: string[];
3737
filteredModules?: string[];

packages/contentstack-clone/test/lib/util/clone-handler.commands.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ describe('CloneHandler - Commands', () => {
195195
expect(cmdArgs).to.include('dest-alias');
196196
});
197197

198-
it('should execute import command with sourceStackBranch data path (covers lines 637-641)', async () => {
198+
it('should execute import command with pathDir as export root when contentDir unset (single-branch layout)', async () => {
199199
const config: CloneConfig = {
200200
cloneContext: {
201201
command: 'test',
@@ -216,11 +216,10 @@ describe('CloneHandler - Commands', () => {
216216

217217
expect(fsStub.writeFileSync.calledTwice).to.be.true;
218218
expect(importCmdStub.run.calledOnce).to.be.true;
219-
// Verify -d flag with data path is added (line 639)
220219
const cmdArgs = importCmdStub.run.firstCall.args[0];
221220
expect(cmdArgs).to.include('-d');
222221
const dataPathIndex = cmdArgs.indexOf('-d');
223-
expect(cmdArgs[dataPathIndex + 1]).to.include('/test/path/main');
222+
expect(cmdArgs[dataPathIndex + 1]).to.equal('/test/path');
224223
});
225224

226225
it('should execute import command with data path instead of sourceStackBranch (covers line 637 condition)', async () => {

packages/contentstack-export/src/export/module-exporter.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as path from 'path';
21
import {
32
ContentstackClient,
43
handleAndLogError,
@@ -66,7 +65,6 @@ class ModuleExporter {
6665
try {
6766
this.exportConfig.branchName = targetBranch.uid;
6867
this.stackAPIClient.stackHeaders.branch = targetBranch.uid;
69-
this.exportConfig.branchDir = path.join(this.exportConfig.exportDir, targetBranch.uid);
7068

7169
// Initialize progress manager for the target branch
7270
CLIProgressManager.clearGlobalSummary();

packages/contentstack-export/src/export/modules/assets.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { PATH_CONSTANTS } from '../../constants';
2525
import config from '../../config';
2626
import { ModuleClassParams } from '../../types';
2727
import BaseClass, { CustomPromiseHandler, CustomPromiseHandlerInput } from './base-class';
28-
import { PROCESS_NAMES, MODULE_CONTEXTS, PROCESS_STATUS, MODULE_NAMES } from '../../utils';
28+
import { getExportBasePath, PROCESS_NAMES, MODULE_CONTEXTS, PROCESS_STATUS, MODULE_NAMES } from '../../utils';
2929

3030
export default class ExportAssets extends BaseClass {
3131
private assetsRootPath: string;
@@ -49,8 +49,7 @@ export default class ExportAssets extends BaseClass {
4949

5050
async start(): Promise<void> {
5151
this.assetsRootPath = pResolve(
52-
this.exportConfig.exportDir,
53-
this.exportConfig.branchName || '',
52+
getExportBasePath(this.exportConfig),
5453
this.assetConfig.dirName,
5554
);
5655
log.debug(`Assets root path resolved to: ${this.assetsRootPath}`, this.exportConfig.context);

packages/contentstack-export/src/export/modules/composable-studio.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
authenticationHandler,
1010
} from '@contentstack/cli-utilities';
1111

12-
import { fsUtil, getOrgUid } from '../../utils';
12+
import { fsUtil, getExportBasePath, getOrgUid } from '../../utils';
1313
import { ModuleClassParams, ComposableStudioConfig, ExportConfig, ComposableStudioProject } from '../../types';
1414

1515
export default class ExportComposableStudio {
@@ -41,8 +41,7 @@ export default class ExportComposableStudio {
4141
}
4242

4343
this.composableStudioPath = pResolve(
44-
this.exportConfig.exportDir,
45-
this.exportConfig.branchName || '',
44+
getExportBasePath(this.exportConfig),
4645
this.composableStudioConfig.dirName,
4746
);
4847
log.debug(`Studio folder path: ${this.composableStudioPath}`, this.exportConfig.context);

packages/contentstack-export/src/export/modules/content-types.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { PATH_CONSTANTS } from '../../constants';
44

55
import BaseClass from './base-class';
66
import { ExportConfig, ModuleClassParams } from '../../types';
7-
import { fsUtil, executeTask, MODULE_CONTEXTS, MODULE_NAMES } from '../../utils';
7+
import { fsUtil, executeTask, getExportBasePath, MODULE_CONTEXTS, MODULE_NAMES } from '../../utils';
88

99
export default class ContentTypesExport extends BaseClass {
1010
private stackAPIClient: ReturnType<ContentstackClient['stack']>;
@@ -48,8 +48,7 @@ export default class ContentTypesExport extends BaseClass {
4848
this.applyQueryFilters(this.qs, 'content-types');
4949

5050
this.contentTypesDirPath = path.resolve(
51-
sanitizePath(exportConfig.exportDir),
52-
sanitizePath(exportConfig.branchName || ''),
51+
sanitizePath(getExportBasePath(exportConfig)),
5352
sanitizePath(this.contentTypesConfig.dirName),
5453
);
5554
this.contentTypes = [];

packages/contentstack-export/src/export/modules/custom-roles.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { handleAndLogError, messageHandler, log } from '@contentstack/cli-utilit
88
import BaseClass from './base-class';
99
import {
1010
fsUtil,
11+
getExportBasePath,
1112
PROCESS_NAMES,
1213
MODULE_CONTEXTS,
1314
PROCESS_STATUS,
@@ -43,8 +44,7 @@ export default class ExportCustomRoles extends BaseClass {
4344
'CUSTOM-ROLES: Analyzing roles and locales...',
4445
async () => {
4546
this.rolesFolderPath = pResolve(
46-
this.exportConfig.exportDir,
47-
this.exportConfig.branchName || '',
47+
getExportBasePath(this.exportConfig),
4848
this.customRolesConfig.dirName,
4949
);
5050

packages/contentstack-export/src/export/modules/entries.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
} from '@contentstack/cli-utilities';
1111
import { PATH_CONSTANTS } from '../../constants';
1212
import { Export, ExportProjects } from '@contentstack/cli-variants';
13-
import { fsUtil, PROCESS_NAMES, MODULE_CONTEXTS, PROCESS_STATUS, MODULE_NAMES } from '../../utils';
13+
import { fsUtil, getExportBasePath, PROCESS_NAMES, MODULE_CONTEXTS, PROCESS_STATUS, MODULE_NAMES } from '../../utils';
1414
import BaseClass, { ApiOptions } from './base-class';
1515
import { ExportConfig, ModuleClassParams } from '../../types';
1616

@@ -41,20 +41,18 @@ export default class EntriesExport extends BaseClass {
4141
this.stackAPIClient = stackAPIClient;
4242
this.exportConfig = exportConfig;
4343
this.entriesConfig = exportConfig.modules.entries;
44+
const basePath = getExportBasePath(exportConfig);
4445
this.entriesDirPath = path.resolve(
45-
sanitizePath(exportConfig.exportDir),
46-
sanitizePath(exportConfig.branchName || ''),
46+
sanitizePath(basePath),
4747
sanitizePath(this.entriesConfig.dirName),
4848
);
4949
this.localesFilePath = path.resolve(
50-
sanitizePath(exportConfig.exportDir),
51-
sanitizePath(exportConfig.branchName || ''),
50+
sanitizePath(basePath),
5251
sanitizePath(exportConfig.modules.locales.dirName),
5352
sanitizePath(exportConfig.modules.locales.fileName),
5453
);
5554
this.contentTypesDirPath = path.resolve(
56-
sanitizePath(exportConfig.exportDir),
57-
sanitizePath(exportConfig.branchName || ''),
55+
sanitizePath(basePath),
5856
sanitizePath(exportConfig.modules.content_types.dirName),
5957
);
6058
this.projectInstance = new ExportProjects(this.exportConfig);

packages/contentstack-export/src/export/modules/environments.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { handleAndLogError, messageHandler, log } from '@contentstack/cli-utilit
55

66
import BaseClass from './base-class';
77
import { EnvironmentConfig, ModuleClassParams } from '../../types';
8-
import { fsUtil, MODULE_CONTEXTS, MODULE_NAMES } from '../../utils';
8+
import { fsUtil, getExportBasePath, MODULE_CONTEXTS, MODULE_NAMES } from '../../utils';
99

1010
export default class ExportEnvironments extends BaseClass {
1111
private environments: Record<string, unknown>;
@@ -32,8 +32,7 @@ export default class ExportEnvironments extends BaseClass {
3232
// Setup with loading spinner
3333
const [totalCount] = await this.withLoadingSpinner('ENVIRONMENTS: Analyzing environments...', async () => {
3434
this.environmentsFolderPath = pResolve(
35-
this.exportConfig.exportDir,
36-
this.exportConfig.branchName || '',
35+
getExportBasePath(this.exportConfig),
3736
this.environmentConfig.dirName,
3837
);
3938
await fsUtil.makeDirectory(this.environmentsFolderPath);

0 commit comments

Comments
 (0)