Skip to content

Commit 46d9012

Browse files
authored
Merge pull request #2093 from contentstack/feat/DX-3302
refactor: ProgressManager to use centralized constants for process names and status messages in both export and import
2 parents d835006 + 83f9d96 commit 46d9012

Some content is hidden

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

56 files changed

+2013
-960
lines changed

.talismanrc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,17 @@ fileignoreconfig:
4444
- filename: packages/contentstack-variants/src/import/audiences.ts
4545
checksum: f24697ef86e928bb4d16f93c021b647639cc344a7f02463d79d69f9434ebed56
4646
- filename: packages/contentstack-variants/src/import/events.ts
47-
checksum: 6cb014b5518ffe204a9f894ad801c05e2ef91a1692049168f74dd12a224363c4
47+
checksum: 88256a99c8ff8d6904df2e3767b39f4761d35ce680b3cabd712c33889bd02fca
4848
- filename: packages/contentstack-import/src/import/modules/personalize.ts
4949
checksum: 1311a613177160637e21b3983b281b384c2cb15837d001a398b67afef30a393a
50+
- filename: packages/contentstack-export/src/export/modules/environments.ts
51+
checksum: fd33318628321583dbeedd70ba7ba97f1e167d364dd26847771d745db295b16f
52+
- filename: packages/contentstack-import/src/import/modules/environments.ts
53+
checksum: 25ec3da4b218c5bbabcfa1af59f26d62e99110bf361a77aab30bfa3ab402da05
54+
- filename: packages/contentstack-variants/src/utils/constants.ts
55+
checksum: 0ceef8ec8489a05d8ecf07cfa7e92575b0da7d5a6c0ed65b64f46d23aab7074d
56+
- filename: packages/contentstack-export/src/utils/marketplace-app-helper.ts
57+
checksum: fcd17c120a0359baeb61b7bd0f8d1ace2662f7f7293d355867f578312fe3a1a0
58+
- filename: packages/contentstack-variants/src/import/variant-entries.ts
59+
checksum: 6e645a3d95903058f32306d306912353272e86e60571919a34125a9cd7b69a59
5060
version: "1.0"

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

Lines changed: 62 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
import config from '../../config';
2525
import { ModuleClassParams } from '../../types';
2626
import BaseClass, { CustomPromiseHandler, CustomPromiseHandlerInput } from './base-class';
27+
import { PROCESS_NAMES, MODULE_CONTEXTS, PROCESS_STATUS, MODULE_NAMES } from '../../utils';
2728

2829
export default class ExportAssets extends BaseClass {
2930
private assetsRootPath: string;
@@ -33,8 +34,8 @@ export default class ExportAssets extends BaseClass {
3334

3435
constructor({ exportConfig, stackAPIClient }: ModuleClassParams) {
3536
super({ exportConfig, stackAPIClient });
36-
this.exportConfig.context.module = 'assets';
37-
this.currentModuleName = 'Assets';
37+
this.exportConfig.context.module = MODULE_CONTEXTS.ASSETS;
38+
this.currentModuleName = MODULE_NAMES[MODULE_CONTEXTS.ASSETS];
3839
}
3940

4041
get commonQueryParam(): Record<string, unknown> {
@@ -64,41 +65,59 @@ export default class ExportAssets extends BaseClass {
6465

6566
// Add sub-processes
6667
if (typeof assetsFolderCount === 'number' && assetsFolderCount > 0) {
67-
progress.addProcess('Folders', assetsFolderCount);
68+
progress.addProcess(PROCESS_NAMES.ASSET_FOLDERS, assetsFolderCount);
6869
}
6970
if (typeof assetsCount === 'number' && assetsCount > 0) {
70-
progress.addProcess('Metadata', assetsCount);
71-
progress.addProcess('Downloads', assetsCount);
71+
progress.addProcess(PROCESS_NAMES.ASSET_METADATA, assetsCount);
72+
progress.addProcess(PROCESS_NAMES.ASSET_DOWNLOADS, assetsCount);
7273
}
7374

7475
try {
7576
// Process asset folders
7677
if (typeof assetsFolderCount === 'number' && assetsFolderCount > 0) {
77-
progress.startProcess('Folders').updateStatus('Fetching folder structure...', 'Folders');
78+
progress
79+
.startProcess(PROCESS_NAMES.ASSET_FOLDERS)
80+
.updateStatus(
81+
PROCESS_STATUS[PROCESS_NAMES.ASSET_FOLDERS].FETCHING,
82+
PROCESS_NAMES.ASSET_FOLDERS,
83+
);
7884
await this.getAssetsFolders(assetsFolderCount);
79-
progress.completeProcess('Folders', true);
85+
progress.completeProcess(PROCESS_NAMES.ASSET_FOLDERS, true);
8086
}
8187

8288
// Process asset metadata
8389
if (typeof assetsCount === 'number' && assetsCount > 0) {
84-
progress.startProcess('Metadata').updateStatus('Fetching asset information...', 'Metadata');
90+
progress
91+
.startProcess(PROCESS_NAMES.ASSET_METADATA)
92+
.updateStatus(
93+
PROCESS_STATUS[PROCESS_NAMES.ASSET_METADATA].FETCHING,
94+
PROCESS_NAMES.ASSET_METADATA,
95+
);
8596
await this.getAssets(assetsCount);
86-
progress.completeProcess('Metadata', true);
97+
progress.completeProcess(PROCESS_NAMES.ASSET_METADATA, true);
8798
}
8899

89100
// Get versioned assets
90101
if (!isEmpty(this.versionedAssets) && this.assetConfig.includeVersionedAssets) {
91102
log.debug('Fetching versioned assets metadata...', this.exportConfig.context);
92-
progress.updateStatus('Processing versioned assets...', 'Metadata');
103+
progress.updateStatus(
104+
PROCESS_STATUS[PROCESS_NAMES.ASSET_METADATA].FETCHING_VERSION,
105+
PROCESS_NAMES.ASSET_METADATA,
106+
);
93107
await this.getVersionedAssets();
94108
}
95109

96110
// Download all assets
97111
if (typeof assetsCount === 'number' && assetsCount > 0) {
98-
progress.startProcess('Downloads').updateStatus('Downloading asset files...', 'Downloads');
112+
progress
113+
.startProcess(PROCESS_NAMES.ASSET_DOWNLOADS)
114+
.updateStatus(
115+
PROCESS_STATUS[PROCESS_NAMES.ASSET_DOWNLOADS].DOWNLOADING,
116+
PROCESS_NAMES.ASSET_DOWNLOADS,
117+
);
99118
log.debug('Starting download of all assets...', this.exportConfig.context);
100119
await this.downloadAssets();
101-
progress.completeProcess('Downloads', true);
120+
progress.completeProcess(PROCESS_NAMES.ASSET_DOWNLOADS, true);
102121
}
103122

104123
this.completeProgress(true);
@@ -128,13 +147,23 @@ export default class ExportAssets extends BaseClass {
128147
if (!isEmpty(items)) {
129148
this.assetsFolder.push(...items);
130149
items.forEach((folder: any) => {
131-
this.progressManager?.tick(true, `folder: ${folder.name || folder.uid}`, null, 'Folders');
150+
this.progressManager?.tick(
151+
true,
152+
`folder: ${folder.name || folder.uid}`,
153+
null,
154+
PROCESS_NAMES.ASSET_FOLDERS,
155+
);
132156
});
133157
}
134158
};
135159

136160
const onReject = ({ error }: any) => {
137-
this.progressManager?.tick(false, 'asset folder', error?.message || 'Failed to fetch folder', 'Folders');
161+
this.progressManager?.tick(
162+
false,
163+
'asset folder',
164+
error?.message || PROCESS_STATUS[PROCESS_NAMES.ASSET_FOLDERS].FAILED,
165+
PROCESS_NAMES.ASSET_FOLDERS,
166+
);
138167
handleAndLogError(error, { ...this.exportConfig.context });
139168
};
140169

@@ -197,7 +226,12 @@ export default class ExportAssets extends BaseClass {
197226
}
198227

199228
const onReject = ({ error }: any) => {
200-
this.progressManager?.tick(false, 'asset', error?.message || 'Failed to fetch asset', 'Metadata');
229+
this.progressManager?.tick(
230+
false,
231+
'asset',
232+
error?.message || PROCESS_STATUS[PROCESS_NAMES.ASSET_METADATA].FAILED,
233+
PROCESS_NAMES.ASSET_METADATA,
234+
);
201235
handleAndLogError(error, { ...this.exportConfig.context }, messageHandler.parse('ASSET_QUERY_FAILED'));
202236
};
203237

@@ -219,7 +253,12 @@ export default class ExportAssets extends BaseClass {
219253
fs?.writeIntoFile(items, { mapKeyVal: true });
220254
// Track progress for each asset with process name
221255
items.forEach((asset: any) => {
222-
this.progressManager?.tick(true, `asset: ${asset.filename || asset.uid}`, null, 'Metadata');
256+
this.progressManager?.tick(
257+
true,
258+
`asset: ${asset.filename || asset.uid}`,
259+
null,
260+
PROCESS_NAMES.ASSET_METADATA,
261+
);
223262
});
224263
}
225264
};
@@ -418,7 +457,12 @@ export default class ExportAssets extends BaseClass {
418457
} else {
419458
data.pipe(assetWriterStream);
420459
}
421-
this.progressManager?.tick(true, `Downloaded asset: ${asset.filename || asset.uid}`, null, 'Downloads');
460+
this.progressManager?.tick(
461+
true,
462+
`Downloaded asset: ${asset.filename || asset.uid}`,
463+
null,
464+
PROCESS_NAMES.ASSET_DOWNLOADS,
465+
);
422466
log.success(messageHandler.parse('ASSET_DOWNLOAD_SUCCESS', asset.filename, asset.uid), this.exportConfig.context);
423467
};
424468

@@ -428,7 +472,7 @@ export default class ExportAssets extends BaseClass {
428472
false,
429473
`Failed to download asset: ${asset.filename || asset.uid}`,
430474
null,
431-
'Downloads',
475+
PROCESS_NAMES.ASSET_DOWNLOADS,
432476
);
433477
handleAndLogError(
434478
error,

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import * as path from 'path';
22
import { ContentstackClient, handleAndLogError, messageHandler, log, sanitizePath } from '@contentstack/cli-utilities';
33

44
import BaseClass from './base-class';
5-
import { fsUtil, executeTask } from '../../utils';
65
import { ExportConfig, ModuleClassParams } from '../../types';
6+
import { fsUtil, executeTask, MODULE_CONTEXTS, MODULE_NAMES } from '../../utils';
77

88
export default class ContentTypesExport extends BaseClass {
99
private stackAPIClient: ReturnType<ContentstackClient['stack']>;
@@ -52,8 +52,8 @@ export default class ContentTypesExport extends BaseClass {
5252
sanitizePath(this.contentTypesConfig.dirName),
5353
);
5454
this.contentTypes = [];
55-
this.exportConfig.context.module = 'content-types';
56-
this.currentModuleName = 'Content Types';
55+
this.exportConfig.context.module = MODULE_CONTEXTS.CONTENT_TYPES;
56+
this.currentModuleName = MODULE_NAMES[MODULE_CONTEXTS.CONTENT_TYPES];
5757
}
5858

5959
async start() {

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

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ import { resolve as pResolve } from 'node:path';
66
import { handleAndLogError, messageHandler, log } from '@contentstack/cli-utilities';
77

88
import BaseClass from './base-class';
9-
import { fsUtil } from '../../utils';
9+
import {
10+
fsUtil,
11+
PROCESS_NAMES,
12+
MODULE_CONTEXTS,
13+
PROCESS_STATUS,
14+
MODULE_NAMES,
15+
} from '../../utils';
1016
import { CustomRoleConfig, ModuleClassParams } from '../../types';
1117

1218
export default class ExportCustomRoles extends BaseClass {
@@ -25,8 +31,8 @@ export default class ExportCustomRoles extends BaseClass {
2531
this.existingRoles = { Admin: 1, Developer: 1, 'Content Manager': 1 };
2632
this.localesMap = {};
2733
this.sourceLocalesMap = {};
28-
this.exportConfig.context.module = 'custom-roles';
29-
this.currentModuleName = 'Custom Roles';
34+
this.exportConfig.context.module = MODULE_CONTEXTS.CUSTOM_ROLES;
35+
this.currentModuleName = MODULE_NAMES[MODULE_CONTEXTS.CUSTOM_ROLES];
3036
}
3137

3238
async start(): Promise<void> {
@@ -66,21 +72,36 @@ export default class ExportCustomRoles extends BaseClass {
6672

6773
// Create nested progress manager
6874
const progress = this.createNestedProgress(this.currentModuleName)
69-
.addProcess('Fetch Roles', totalRoles)
70-
.addProcess('Fetch Locales', totalLocales)
71-
.addProcess('Process Mappings', 1);
72-
73-
progress.startProcess('Fetch Roles').updateStatus('Fetching custom roles...', 'Fetch Roles');
75+
.addProcess(PROCESS_NAMES.FETCH_ROLES, totalRoles)
76+
.addProcess(PROCESS_NAMES.FETCH_LOCALES, totalLocales)
77+
.addProcess(PROCESS_NAMES.PROCESS_MAPPINGS, 1);
78+
79+
progress
80+
.startProcess(PROCESS_NAMES.FETCH_ROLES)
81+
.updateStatus(
82+
PROCESS_STATUS[PROCESS_NAMES.FETCH_ROLES].FETCHING,
83+
PROCESS_NAMES.FETCH_ROLES,
84+
);
7485
await this.getCustomRoles();
75-
progress.completeProcess('Fetch Roles', true);
86+
progress.completeProcess(PROCESS_NAMES.FETCH_ROLES, true);
7687

77-
progress.startProcess('Fetch Locales').updateStatus('Fetching locales...', 'Fetch Locales');
88+
progress
89+
.startProcess(PROCESS_NAMES.FETCH_LOCALES)
90+
.updateStatus(
91+
PROCESS_STATUS[PROCESS_NAMES.FETCH_LOCALES].FETCHING,
92+
PROCESS_NAMES.FETCH_LOCALES,
93+
);
7894
await this.getLocales();
79-
progress.completeProcess('Fetch Locales', true);
95+
progress.completeProcess(PROCESS_NAMES.FETCH_LOCALES, true);
8096

81-
progress.startProcess('Process Mappings').updateStatus('Processing role-locale mappings...', 'Process Mappings');
97+
progress
98+
.startProcess(PROCESS_NAMES.PROCESS_MAPPINGS)
99+
.updateStatus(
100+
PROCESS_STATUS[PROCESS_NAMES.PROCESS_MAPPINGS].PROCESSING,
101+
PROCESS_NAMES.PROCESS_MAPPINGS,
102+
);
82103
await this.getCustomRolesLocales();
83-
progress.completeProcess('Process Mappings', true);
104+
progress.completeProcess(PROCESS_NAMES.PROCESS_MAPPINGS, true);
84105

85106
log.debug(
86107
`Custom roles export completed. Total custom roles: ${Object.keys(this.customRoles).length}`,
@@ -124,7 +145,7 @@ export default class ExportCustomRoles extends BaseClass {
124145
log.info(messageHandler.parse('ROLES_EXPORTING_ROLE', role.name), this.exportConfig.context);
125146
this.customRoles[role.uid] = role;
126147

127-
this.progressManager?.tick(true, `role: ${role.name}`, null, 'Fetch Roles');
148+
this.progressManager?.tick(true, `role: ${role.name}`, null, PROCESS_NAMES.FETCH_ROLES);
128149
});
129150

130151
const customRolesFilePath = pResolve(this.rolesFolderPath, this.customRolesConfig.fileName);
@@ -153,7 +174,7 @@ export default class ExportCustomRoles extends BaseClass {
153174
this.sourceLocalesMap[locale.uid] = locale;
154175

155176
// Track progress for each locale
156-
this.progressManager?.tick(true, `locale: ${locale.name}`, null, 'Fetch Locales');
177+
this.progressManager?.tick(true, `locale: ${locale.name}`, null, PROCESS_NAMES.FETCH_LOCALES);
157178
}
158179

159180
log.debug(`Mapped ${Object.keys(this.sourceLocalesMap).length} locales`, this.exportConfig.context);
@@ -198,6 +219,6 @@ export default class ExportCustomRoles extends BaseClass {
198219
}
199220

200221
// Track progress for mapping completion
201-
this.progressManager?.tick(true, 'role-locale mappings', null, 'Process Mappings');
222+
this.progressManager?.tick(true, 'role-locale mappings', null, PROCESS_NAMES.PROCESS_MAPPINGS);
202223
}
203224
}

0 commit comments

Comments
 (0)