Skip to content

Commit 548cccc

Browse files
authored
Merge pull request #2145 from contentstack/chore/DX-3564-cleanup-deprecated-js-and-default-ts-modules
chore: remove deprecated JS & ContentVersion support, default to TypeScript modules, update export command to main only
2 parents c9beb80 + ce7dc68 commit 548cccc

Some content is hidden

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

60 files changed

+116
-5878
lines changed

packages/contentstack-export/src/commands/cm/stacks/export.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919

2020
import { ModuleExporter } from '../../../export';
2121
import { Context, ExportConfig } from '../../../types';
22-
import { setupExportConfig, writeExportMetaFile } from '../../../utils';
22+
import { setupExportConfig } from '../../../utils';
2323

2424
export default class ExportCommand extends Command {
2525
static description: string = messageHandler.parse('Export content from a stack');
@@ -134,10 +134,6 @@ export default class ExportCommand extends Command {
134134
const managementAPIClient: ContentstackClient = await managementSDKClient(exportConfig);
135135
const moduleExporter = new ModuleExporter(managementAPIClient, exportConfig);
136136
await moduleExporter.start();
137-
138-
if (!exportConfig.branches?.length) {
139-
writeExportMetaFile(exportConfig);
140-
}
141137
log.success(
142138
`The content of the stack ${exportConfig.apiKey} has been exported successfully!`,
143139
exportConfig.context,

packages/contentstack-export/src/config/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { DefaultConfig } from '../types';
22

33
const config: DefaultConfig = {
4-
contentVersion: 2,
54
versioning: false,
65
host: 'https://api.contentstack.io/v3',
76
developerHubUrls: {
@@ -489,7 +488,6 @@ const config: DefaultConfig = {
489488
writeConcurrency: 5,
490489
developerHubBaseUrl: '',
491490
marketplaceAppEncryptionKey: 'nF2ejRQcTv',
492-
onlyTSModules: ['taxonomies'],
493491
};
494492

495493
export default config;

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

Lines changed: 50 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ import {
77
getBranchFromAlias,
88
CLIProgressManager,
99
} from '@contentstack/cli-utilities';
10-
import { setupBranches, setupExportDir, writeExportMetaFile } from '../utils';
1110
import startModuleExport from './modules';
12-
import startJSModuleExport from './modules-js';
1311
import { ExportConfig, Modules } from '../types';
12+
import { setupBranches, setupExportDir } from '../utils';
1413

1514
class ModuleExporter {
1615
private managementAPIClient: ContentstackClient;
@@ -48,46 +47,55 @@ class ModuleExporter {
4847
}
4948

5049
async exportByBranches(): Promise<void> {
51-
// loop through the branches and export it parallel
52-
for (const [index, branch] of this.exportConfig.branches.entries()) {
53-
try {
54-
this.exportConfig.branchName = branch.uid;
55-
this.stackAPIClient.stackHeaders.branch = branch.uid;
56-
this.exportConfig.branchDir = path.join(this.exportConfig.exportDir, branch.uid);
57-
58-
// Reset progress manager for each branch (except the first one which was initialized in export command)
59-
if (index >= 0) {
60-
CLIProgressManager.clearGlobalSummary();
61-
CLIProgressManager.initializeGlobalSummary(
62-
`EXPORT-${branch.uid}`,
63-
branch.uid,
64-
`Exporting "${branch.uid}" branch content...`,
65-
);
66-
}
67-
68-
log.info(`Exporting content from branch ${branch.uid}`, this.exportConfig.context);
69-
writeExportMetaFile(this.exportConfig, this.exportConfig.branchDir);
70-
await this.export();
71-
72-
// Print branch-specific summary
73-
if (index <= this.exportConfig.branches.length - 1) {
74-
CLIProgressManager.printGlobalSummary();
75-
}
76-
77-
log.success(`The content of branch ${branch.uid} has been exported successfully!`, this.exportConfig.context);
78-
} catch (error) {
79-
handleAndLogError(
80-
error,
81-
{ ...this.exportConfig.context, branch: branch.uid },
82-
messageHandler.parse('FAILED_EXPORT_CONTENT_BRANCH', { branch: branch.uid }),
83-
);
84-
throw new Error(messageHandler.parse('FAILED_EXPORT_CONTENT_BRANCH', { branch: branch.uid }));
50+
let targetBranch;
51+
52+
if (this.exportConfig.branchName) {
53+
// User specified a branch - export only that branch
54+
targetBranch = this.exportConfig.branches.find((branch) => branch.uid === this.exportConfig.branchName);
55+
if (!targetBranch) {
56+
throw new Error(`Branch '${this.exportConfig.branchName}' not found in available branches`);
57+
}
58+
} else {
59+
// No specific branch mentioned - export only the main branch
60+
targetBranch = this.exportConfig.branches.find((branch) => branch.uid === 'main');
61+
if (!targetBranch) {
62+
throw new Error('No main branch or available branches found');
8563
}
8664
}
65+
66+
try {
67+
this.exportConfig.branchName = targetBranch.uid;
68+
this.stackAPIClient.stackHeaders.branch = targetBranch.uid;
69+
this.exportConfig.branchDir = path.join(this.exportConfig.exportDir, targetBranch.uid);
70+
71+
// Initialize progress manager for the target branch
72+
CLIProgressManager.clearGlobalSummary();
73+
CLIProgressManager.initializeGlobalSummary(
74+
`EXPORT-${targetBranch.uid}`,
75+
targetBranch.uid,
76+
`Exporting "${targetBranch.uid}" branch content...`,
77+
);
78+
79+
log.info(`Exporting content from '${targetBranch.uid}' branch`, this.exportConfig.context);
80+
await this.export();
81+
CLIProgressManager.printGlobalSummary();
82+
83+
log.success(
84+
`The content of branch ${targetBranch.uid} has been exported successfully!`,
85+
this.exportConfig.context,
86+
);
87+
} catch (error) {
88+
handleAndLogError(
89+
error,
90+
{ ...this.exportConfig.context, branch: targetBranch?.uid },
91+
messageHandler.parse('FAILED_EXPORT_CONTENT_BRANCH', { branch: targetBranch?.uid }),
92+
);
93+
throw new Error(messageHandler.parse('FAILED_EXPORT_CONTENT_BRANCH', { branch: targetBranch?.uid }));
94+
}
8795
}
8896

8997
async export() {
90-
log.info(`Started to export content, version is ${this.exportConfig.contentVersion}`, this.exportConfig.context);
98+
log.info(`Started to export content`, this.exportConfig.context);
9199
// checks for single module or all modules
92100
if (this.exportConfig.singleModuleExport) {
93101
return this.exportSingleModule(this.exportConfig.moduleName);
@@ -99,22 +107,11 @@ class ModuleExporter {
99107
log.info(`Exporting module: ${moduleName}`, this.exportConfig.context);
100108
// export the modules by name
101109
// calls the module runner which inturn calls the module itself
102-
if (this.exportConfig.contentVersion === 2) {
103-
await startModuleExport({
104-
stackAPIClient: this.stackAPIClient,
105-
exportConfig: this.exportConfig,
106-
moduleName,
107-
});
108-
} else {
109-
//NOTE - new modules support only ts
110-
if (this.exportConfig.onlyTSModules.indexOf(moduleName) === -1) {
111-
await startJSModuleExport({
112-
stackAPIClient: this.stackAPIClient,
113-
exportConfig: this.exportConfig,
114-
moduleName,
115-
});
116-
}
117-
}
110+
await startModuleExport({
111+
stackAPIClient: this.stackAPIClient,
112+
exportConfig: this.exportConfig,
113+
moduleName,
114+
});
118115
}
119116

120117
async exportSingleModule(moduleName: Modules): Promise<void> {

0 commit comments

Comments
 (0)