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
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {

import { ModuleExporter } from '../../../export';
import { Context, ExportConfig } from '../../../types';
import { setupExportConfig, writeExportMetaFile } from '../../../utils';
import { setupExportConfig } from '../../../utils';

export default class ExportCommand extends Command {
static description: string = messageHandler.parse('Export content from a stack');
Expand Down Expand Up @@ -134,10 +134,6 @@ export default class ExportCommand extends Command {
const managementAPIClient: ContentstackClient = await managementSDKClient(exportConfig);
const moduleExporter = new ModuleExporter(managementAPIClient, exportConfig);
await moduleExporter.start();

if (!exportConfig.branches?.length) {
writeExportMetaFile(exportConfig);
}
log.success(
`The content of the stack ${exportConfig.apiKey} has been exported successfully!`,
exportConfig.context,
Expand Down
2 changes: 0 additions & 2 deletions packages/contentstack-export/src/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { DefaultConfig } from '../types';

const config: DefaultConfig = {
contentVersion: 2,
versioning: false,
host: 'https://api.contentstack.io/v3',
developerHubUrls: {
Expand Down Expand Up @@ -489,7 +488,6 @@ const config: DefaultConfig = {
writeConcurrency: 5,
developerHubBaseUrl: '',
marketplaceAppEncryptionKey: 'nF2ejRQcTv',
onlyTSModules: ['taxonomies'],
};

export default config;
103 changes: 50 additions & 53 deletions packages/contentstack-export/src/export/module-exporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import {
getBranchFromAlias,
CLIProgressManager,
} from '@contentstack/cli-utilities';
import { setupBranches, setupExportDir, writeExportMetaFile } from '../utils';
import startModuleExport from './modules';
import startJSModuleExport from './modules-js';
import { ExportConfig, Modules } from '../types';
import { setupBranches, setupExportDir } from '../utils';

class ModuleExporter {
private managementAPIClient: ContentstackClient;
Expand Down Expand Up @@ -48,46 +47,55 @@ class ModuleExporter {
}

async exportByBranches(): Promise<void> {
// loop through the branches and export it parallel
for (const [index, branch] of this.exportConfig.branches.entries()) {
try {
this.exportConfig.branchName = branch.uid;
this.stackAPIClient.stackHeaders.branch = branch.uid;
this.exportConfig.branchDir = path.join(this.exportConfig.exportDir, branch.uid);

// Reset progress manager for each branch (except the first one which was initialized in export command)
if (index >= 0) {
CLIProgressManager.clearGlobalSummary();
CLIProgressManager.initializeGlobalSummary(
`EXPORT-${branch.uid}`,
branch.uid,
`Exporting "${branch.uid}" branch content...`,
);
}

log.info(`Exporting content from branch ${branch.uid}`, this.exportConfig.context);
writeExportMetaFile(this.exportConfig, this.exportConfig.branchDir);
await this.export();

// Print branch-specific summary
if (index <= this.exportConfig.branches.length - 1) {
CLIProgressManager.printGlobalSummary();
}

log.success(`The content of branch ${branch.uid} has been exported successfully!`, this.exportConfig.context);
} catch (error) {
handleAndLogError(
error,
{ ...this.exportConfig.context, branch: branch.uid },
messageHandler.parse('FAILED_EXPORT_CONTENT_BRANCH', { branch: branch.uid }),
);
throw new Error(messageHandler.parse('FAILED_EXPORT_CONTENT_BRANCH', { branch: branch.uid }));
let targetBranch;

if (this.exportConfig.branchName) {
// User specified a branch - export only that branch
targetBranch = this.exportConfig.branches.find((branch) => branch.uid === this.exportConfig.branchName);
if (!targetBranch) {
throw new Error(`Branch '${this.exportConfig.branchName}' not found in available branches`);
}
} else {
// No specific branch mentioned - export only the main branch
targetBranch = this.exportConfig.branches.find((branch) => branch.uid === 'main');
if (!targetBranch) {
throw new Error('No main branch or available branches found');
}
}

try {
this.exportConfig.branchName = targetBranch.uid;
this.stackAPIClient.stackHeaders.branch = targetBranch.uid;
this.exportConfig.branchDir = path.join(this.exportConfig.exportDir, targetBranch.uid);

// Initialize progress manager for the target branch
CLIProgressManager.clearGlobalSummary();
CLIProgressManager.initializeGlobalSummary(
`EXPORT-${targetBranch.uid}`,
targetBranch.uid,
`Exporting "${targetBranch.uid}" branch content...`,
);

log.info(`Exporting content from '${targetBranch.uid}' branch`, this.exportConfig.context);
await this.export();
CLIProgressManager.printGlobalSummary();

log.success(
`The content of branch ${targetBranch.uid} has been exported successfully!`,
this.exportConfig.context,
);
} catch (error) {
handleAndLogError(
error,
{ ...this.exportConfig.context, branch: targetBranch?.uid },
messageHandler.parse('FAILED_EXPORT_CONTENT_BRANCH', { branch: targetBranch?.uid }),
);
throw new Error(messageHandler.parse('FAILED_EXPORT_CONTENT_BRANCH', { branch: targetBranch?.uid }));
}
}

async export() {
log.info(`Started to export content, version is ${this.exportConfig.contentVersion}`, this.exportConfig.context);
log.info(`Started to export content`, this.exportConfig.context);
// checks for single module or all modules
if (this.exportConfig.singleModuleExport) {
return this.exportSingleModule(this.exportConfig.moduleName);
Expand All @@ -99,22 +107,11 @@ class ModuleExporter {
log.info(`Exporting module: ${moduleName}`, this.exportConfig.context);
// export the modules by name
// calls the module runner which inturn calls the module itself
if (this.exportConfig.contentVersion === 2) {
await startModuleExport({
stackAPIClient: this.stackAPIClient,
exportConfig: this.exportConfig,
moduleName,
});
} else {
//NOTE - new modules support only ts
if (this.exportConfig.onlyTSModules.indexOf(moduleName) === -1) {
await startJSModuleExport({
stackAPIClient: this.stackAPIClient,
exportConfig: this.exportConfig,
moduleName,
});
}
}
await startModuleExport({
stackAPIClient: this.stackAPIClient,
exportConfig: this.exportConfig,
moduleName,
});
}

async exportSingleModule(moduleName: Modules): Promise<void> {
Expand Down
Loading
Loading