Skip to content
Open
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
11 changes: 6 additions & 5 deletions packages/contentstack-clone/src/core/util/clone-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -644,8 +644,8 @@ export class CloneHandler {
importConfig.contentDir = importConfig.data;
}

if (!importConfig.contentDir && importConfig.sourceStackBranch && importConfig.pathDir) {
const dataPath = path.join(importConfig.pathDir, importConfig.sourceStackBranch);
if (!importConfig.contentDir && importConfig.pathDir) {
const dataPath = importConfig.pathDir;
cmd.push('-d', dataPath);
log.debug(`Import data path: ${dataPath}`, this.config.cloneContext);
}
Expand Down Expand Up @@ -675,7 +675,7 @@ export class CloneHandler {
cmd: cmd.join(' '),
targetStack: importConfig.apiKey || importConfig.target_stack,
targetBranch: importConfig.targetStackBranch,
dataPath: importConfig.contentDir || (importConfig.pathDir && importConfig.sourceStackBranch ? path.join(importConfig.pathDir, importConfig.sourceStackBranch) : undefined)
dataPath: importConfig.contentDir || importConfig.pathDir || undefined
});
log.debug('Running import command', { ...this.config.cloneContext, cmd });
const importData = importCmd.run(cmd);
Expand Down Expand Up @@ -804,9 +804,10 @@ export class CloneHandler {
];
let successMsg: string;
let selectedValue: any = {};
// Resolve path to package root - go up 3 levels from __dirname (core/util -> package root)
// Export root only (single-branch layout: modules live directly under -d, not pathDir/<branch>)
const cloneTypePackageRoot = path.resolve(__dirname, '../../..');
this.config.contentDir = path.join(cloneTypePackageRoot, 'contents', this.config.sourceStackBranch || '');
this.config.contentDir =
this.config.pathDir || path.join(cloneTypePackageRoot, 'contents');
log.debug(`Clone content directory: ${this.config.contentDir}`, this.config.cloneContext);

if (!this.config.cloneType) {
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-clone/src/types/clone-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface CloneConfig {
forceStopMarketplaceAppsPrompt?: boolean;

// Data and modules
/** Path to exported content for import (aligns with import plugin's contentDir) */
/** Export root directory for import (same path as export `-d`; not a branch-named subdirectory) */
contentDir?: string;
modules?: string[];
filteredModules?: string[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ describe('CloneHandler - Commands', () => {
expect(cmdArgs).to.include('dest-alias');
});

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

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

it('should execute import command with data path instead of sourceStackBranch (covers line 637 condition)', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as path from 'path';
import {
ContentstackClient,
handleAndLogError,
Expand Down Expand Up @@ -66,7 +65,7 @@ class ModuleExporter {
try {
this.exportConfig.branchName = targetBranch.uid;
this.stackAPIClient.stackHeaders.branch = targetBranch.uid;
this.exportConfig.branchDir = path.join(this.exportConfig.exportDir, targetBranch.uid);
this.exportConfig.branchDir = this.exportConfig.exportDir;

// Initialize progress manager for the target branch
CLIProgressManager.clearGlobalSummary();
Expand Down
5 changes: 2 additions & 3 deletions packages/contentstack-export/src/export/modules/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { PATH_CONSTANTS } from '../../constants';
import config from '../../config';
import { ModuleClassParams } from '../../types';
import BaseClass, { CustomPromiseHandler, CustomPromiseHandlerInput } from './base-class';
import { PROCESS_NAMES, MODULE_CONTEXTS, PROCESS_STATUS, MODULE_NAMES } from '../../utils';
import { getExportBasePath, PROCESS_NAMES, MODULE_CONTEXTS, PROCESS_STATUS, MODULE_NAMES } from '../../utils';

export default class ExportAssets extends BaseClass {
private assetsRootPath: string;
Expand All @@ -49,8 +49,7 @@ export default class ExportAssets extends BaseClass {

async start(): Promise<void> {
this.assetsRootPath = pResolve(
this.exportConfig.exportDir,
this.exportConfig.branchName || '',
getExportBasePath(this.exportConfig),
this.assetConfig.dirName,
);
log.debug(`Assets root path resolved to: ${this.assetsRootPath}`, this.exportConfig.context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
authenticationHandler,
} from '@contentstack/cli-utilities';

import { fsUtil, getOrgUid } from '../../utils';
import { fsUtil, getExportBasePath, getOrgUid } from '../../utils';
import { ModuleClassParams, ComposableStudioConfig, ExportConfig, ComposableStudioProject } from '../../types';

export default class ExportComposableStudio {
Expand Down Expand Up @@ -41,8 +41,7 @@ export default class ExportComposableStudio {
}

this.composableStudioPath = pResolve(
this.exportConfig.exportDir,
this.exportConfig.branchName || '',
getExportBasePath(this.exportConfig),
this.composableStudioConfig.dirName,
);
log.debug(`Studio folder path: ${this.composableStudioPath}`, this.exportConfig.context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { PATH_CONSTANTS } from '../../constants';

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

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

this.contentTypesDirPath = path.resolve(
sanitizePath(exportConfig.exportDir),
sanitizePath(exportConfig.branchName || ''),
sanitizePath(getExportBasePath(exportConfig)),
sanitizePath(this.contentTypesConfig.dirName),
);
this.contentTypes = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { handleAndLogError, messageHandler, log } from '@contentstack/cli-utilit
import BaseClass from './base-class';
import {
fsUtil,
getExportBasePath,
PROCESS_NAMES,
MODULE_CONTEXTS,
PROCESS_STATUS,
Expand Down Expand Up @@ -43,8 +44,7 @@ export default class ExportCustomRoles extends BaseClass {
'CUSTOM-ROLES: Analyzing roles and locales...',
async () => {
this.rolesFolderPath = pResolve(
this.exportConfig.exportDir,
this.exportConfig.branchName || '',
getExportBasePath(this.exportConfig),
this.customRolesConfig.dirName,
);

Expand Down
12 changes: 5 additions & 7 deletions packages/contentstack-export/src/export/modules/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from '@contentstack/cli-utilities';
import { PATH_CONSTANTS } from '../../constants';
import { Export, ExportProjects } from '@contentstack/cli-variants';
import { fsUtil, PROCESS_NAMES, MODULE_CONTEXTS, PROCESS_STATUS, MODULE_NAMES } from '../../utils';
import { fsUtil, getExportBasePath, PROCESS_NAMES, MODULE_CONTEXTS, PROCESS_STATUS, MODULE_NAMES } from '../../utils';
import BaseClass, { ApiOptions } from './base-class';
import { ExportConfig, ModuleClassParams } from '../../types';

Expand Down Expand Up @@ -41,20 +41,18 @@ export default class EntriesExport extends BaseClass {
this.stackAPIClient = stackAPIClient;
this.exportConfig = exportConfig;
this.entriesConfig = exportConfig.modules.entries;
const basePath = getExportBasePath(exportConfig);
this.entriesDirPath = path.resolve(
sanitizePath(exportConfig.exportDir),
sanitizePath(exportConfig.branchName || ''),
sanitizePath(basePath),
sanitizePath(this.entriesConfig.dirName),
);
this.localesFilePath = path.resolve(
sanitizePath(exportConfig.exportDir),
sanitizePath(exportConfig.branchName || ''),
sanitizePath(basePath),
sanitizePath(exportConfig.modules.locales.dirName),
sanitizePath(exportConfig.modules.locales.fileName),
);
this.contentTypesDirPath = path.resolve(
sanitizePath(exportConfig.exportDir),
sanitizePath(exportConfig.branchName || ''),
sanitizePath(basePath),
sanitizePath(exportConfig.modules.content_types.dirName),
);
this.projectInstance = new ExportProjects(this.exportConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { handleAndLogError, messageHandler, log } from '@contentstack/cli-utilit

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

export default class ExportEnvironments extends BaseClass {
private environments: Record<string, unknown>;
Expand All @@ -32,8 +32,7 @@ export default class ExportEnvironments extends BaseClass {
// Setup with loading spinner
const [totalCount] = await this.withLoadingSpinner('ENVIRONMENTS: Analyzing environments...', async () => {
this.environmentsFolderPath = pResolve(
this.exportConfig.exportDir,
this.exportConfig.branchName || '',
getExportBasePath(this.exportConfig),
this.environmentConfig.dirName,
);
await fsUtil.makeDirectory(this.environmentsFolderPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { handleAndLogError, messageHandler, log } from '@contentstack/cli-utilit

import BaseClass from './base-class';
import { ExtensionsConfig, ModuleClassParams } from '../../types';
import { fsUtil, MODULE_CONTEXTS, MODULE_NAMES } from '../../utils';
import { fsUtil, getExportBasePath, MODULE_CONTEXTS, MODULE_NAMES } from '../../utils';

export default class ExportExtensions extends BaseClass {
private extensionsFolderPath: string;
Expand Down Expand Up @@ -33,8 +33,7 @@ export default class ExportExtensions extends BaseClass {
// Setup with loading spinner
const [totalCount] = await this.withLoadingSpinner('EXTENSIONS: Analyzing extensions...', async () => {
this.extensionsFolderPath = pResolve(
this.exportConfig.exportDir,
this.exportConfig.branchName || '',
getExportBasePath(this.exportConfig),
this.extensionConfig.dirName,
);
await fsUtil.makeDirectory(this.extensionsFolderPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ContentstackClient, handleAndLogError, messageHandler, log, sanitizePat

import BaseClass from './base-class';
import { ExportConfig, ModuleClassParams } from '../../types';
import { fsUtil, MODULE_CONTEXTS, MODULE_NAMES } from '../../utils';
import { fsUtil, getExportBasePath, MODULE_CONTEXTS, MODULE_NAMES } from '../../utils';

export default class GlobalFieldsExport extends BaseClass {
private stackAPIClient: ReturnType<ContentstackClient['stack']>;
Expand Down Expand Up @@ -38,8 +38,7 @@ export default class GlobalFieldsExport extends BaseClass {
include_global_field_schema: true,
};
this.globalFieldsDirPath = path.resolve(
sanitizePath(exportConfig.exportDir),
sanitizePath(exportConfig.branchName || ''),
sanitizePath(getExportBasePath(exportConfig)),
sanitizePath(this.globalFieldsConfig.dirName),
);
this.globalFields = [];
Expand Down
5 changes: 2 additions & 3 deletions packages/contentstack-export/src/export/modules/labels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { handleAndLogError, messageHandler, log } from '@contentstack/cli-utilit

import BaseClass from './base-class';
import { LabelConfig, ModuleClassParams } from '../../types';
import { fsUtil, MODULE_CONTEXTS, MODULE_NAMES } from '../../utils';
import { fsUtil, getExportBasePath, MODULE_CONTEXTS, MODULE_NAMES } from '../../utils';

export default class ExportLabels extends BaseClass {
private labels: Record<string, Record<string, string>>;
Expand All @@ -32,8 +32,7 @@ export default class ExportLabels extends BaseClass {
// Setup with loading spinner
const [totalCount] = await this.withLoadingSpinner('LABELS: Analyzing labels...', async () => {
this.labelsFolderPath = pResolve(
this.exportConfig.exportDir,
this.exportConfig.branchName || '',
getExportBasePath(this.exportConfig),
this.labelConfig.dirName,
);

Expand Down
5 changes: 2 additions & 3 deletions packages/contentstack-export/src/export/modules/locales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ContentstackClient, handleAndLogError, messageHandler, log, sanitizePat

import BaseClass from './base-class';
import { ExportConfig, ModuleClassParams } from '../../types';
import { fsUtil, MODULE_CONTEXTS, MODULE_NAMES } from '../../utils';
import { fsUtil, getExportBasePath, MODULE_CONTEXTS, MODULE_NAMES } from '../../utils';

export default class LocaleExport extends BaseClass {
private stackAPIClient: ReturnType<ContentstackClient['stack']>;
Expand Down Expand Up @@ -42,8 +42,7 @@ export default class LocaleExport extends BaseClass {
},
};
this.localesPath = path.resolve(
sanitizePath(exportConfig.exportDir),
sanitizePath(exportConfig.branchName || ''),
sanitizePath(getExportBasePath(exportConfig)),
sanitizePath(this.localeConfig.dirName),
);
this.locales = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
import BaseClass from './base-class';
import {
fsUtil,
getExportBasePath,
getOrgUid,
createNodeCryptoInstance,
getDeveloperHubUrl,
Expand Down Expand Up @@ -118,8 +119,7 @@ export default class ExportMarketplaceApps extends BaseClass {

async setupPaths(): Promise<void> {
this.marketplaceAppPath = pResolve(
this.exportConfig.exportDir,
this.exportConfig.branchName || '',
getExportBasePath(this.exportConfig),
this.marketplaceAppConfig.dirName,
);
log.debug(`Marketplace apps folder path: '${this.marketplaceAppPath}'`, this.exportConfig.context);
Expand Down
4 changes: 2 additions & 2 deletions packages/contentstack-export/src/export/modules/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { PATH_CONSTANTS } from '../../constants';
import BaseClass from './base-class';
import {
fsUtil,
getExportBasePath,
PROCESS_NAMES,
MODULE_CONTEXTS,
PROCESS_STATUS,
Expand All @@ -31,8 +32,7 @@ export default class ExportStack extends BaseClass {
this.stackConfig = exportConfig.modules.stack;
this.qs = { include_count: true };
this.stackFolderPath = pResolve(
this.exportConfig.exportDir,
this.exportConfig.branchName || '',
getExportBasePath(this.exportConfig),
this.stackConfig.dirName,
);
this.exportConfig.context.module = MODULE_CONTEXTS.STACK;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { handleAndLogError, messageHandler, log, sanitizePath } from '@contentst
import BaseClass from './base-class';
import {
fsUtil,
getExportBasePath,
PROCESS_NAMES,
MODULE_CONTEXTS,
PROCESS_STATUS,
Expand Down Expand Up @@ -43,8 +44,7 @@ export default class ExportTaxonomies extends BaseClass {
this.exportConfig.context.module = MODULE_CONTEXTS.TAXONOMIES;
this.currentModuleName = MODULE_NAMES[MODULE_CONTEXTS.TAXONOMIES];
this.localesFilePath = pResolve(
sanitizePath(exportConfig.exportDir),
sanitizePath(exportConfig.branchName || ''),
sanitizePath(getExportBasePath(exportConfig)),
sanitizePath(exportConfig.modules.locales.dirName),
sanitizePath(exportConfig.modules.locales.fileName),
);
Expand Down Expand Up @@ -98,8 +98,7 @@ export default class ExportTaxonomies extends BaseClass {
private async initializeExport(): Promise<number> {
return this.withLoadingSpinner('TAXONOMIES: Analyzing taxonomy structure...', async () => {
this.taxonomiesFolderPath = pResolve(
this.exportConfig.exportDir,
this.exportConfig.branchName || '',
getExportBasePath(this.exportConfig),
this.taxonomiesConfig.dirName,
);
log.debug(`Taxonomies folder path: '${this.taxonomiesFolderPath}'`, this.exportConfig.context);
Expand Down
5 changes: 2 additions & 3 deletions packages/contentstack-export/src/export/modules/webhooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { handleAndLogError, messageHandler, log } from '@contentstack/cli-utilit

import BaseClass from './base-class';
import { WebhookConfig, ModuleClassParams } from '../../types';
import { fsUtil, MODULE_CONTEXTS, MODULE_NAMES } from '../../utils';
import { fsUtil, getExportBasePath, MODULE_CONTEXTS, MODULE_NAMES } from '../../utils';

export default class ExportWebhooks extends BaseClass {
private webhooks: Record<string, Record<string, string>>;
Expand Down Expand Up @@ -33,8 +33,7 @@ export default class ExportWebhooks extends BaseClass {
// Setup with loading spinner
const [totalCount] = await this.withLoadingSpinner('WEBHOOKS: Analyzing webhooks...', async () => {
this.webhooksFolderPath = pResolve(
this.exportConfig.exportDir,
this.exportConfig.branchName || '',
getExportBasePath(this.exportConfig),
this.webhookConfig.dirName,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { handleAndLogError, messageHandler, log } from '@contentstack/cli-utilit

import BaseClass from './base-class';
import { WorkflowConfig, ModuleClassParams } from '../../types';
import { fsUtil, MODULE_CONTEXTS, MODULE_NAMES } from '../../utils';
import { fsUtil, getExportBasePath, MODULE_CONTEXTS, MODULE_NAMES } from '../../utils';

export default class ExportWorkFlows extends BaseClass {
private workflows: Record<string, Record<string, string>>;
Expand All @@ -32,8 +32,7 @@ export default class ExportWorkFlows extends BaseClass {
// Setup with loading spinner
const [totalCount] = await this.withLoadingSpinner('WORKFLOWS: Analyzing workflows...', async () => {
this.webhooksFolderPath = pResolve(
this.exportConfig.exportDir,
this.exportConfig.branchName || '',
getExportBasePath(this.exportConfig),
this.workflowConfig.dirName,
);

Expand Down
Loading
Loading