Skip to content

Commit 2c8b9bc

Browse files
committed
fix: locale reading issue in entries module
1 parent 11fc019 commit 2c8b9bc

File tree

1 file changed

+51
-34
lines changed
  • packages/contentstack-export/src/export/modules

1 file changed

+51
-34
lines changed

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

Lines changed: 51 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
import * as path from 'path';
2-
import {
3-
ContentstackClient,
4-
FsUtility,
5-
handleAndLogError,
6-
messageHandler,
7-
log,
8-
} from '@contentstack/cli-utilities';
2+
import { ContentstackClient, FsUtility, handleAndLogError, messageHandler, log } from '@contentstack/cli-utilities';
93
import { Export, ExportProjects } from '@contentstack/cli-variants';
104
import { sanitizePath } from '@contentstack/cli-utilities';
115

@@ -65,12 +59,15 @@ export default class EntriesExport extends BaseClass {
6559
try {
6660
log.debug('Starting entries export process...', this.exportConfig.context);
6761
const locales = fsUtil.readFile(this.localesFilePath) as Array<Record<string, unknown>>;
62+
if (!locales || locales.length === 0) {
63+
log.debug(`No locales found in ${this.localesFilePath}`, this.exportConfig.context);
64+
}
6865
log.debug(`Loaded ${locales?.length} locales from ${this.localesFilePath}`, this.exportConfig.context);
69-
66+
7067
const contentTypes = fsUtil.readFile(this.schemaFilePath) as Array<Record<string, unknown>>;
7168
log.debug(`Loaded ${contentTypes?.length} content types from ${this.schemaFilePath}`, this.exportConfig.context);
72-
73-
if (contentTypes.length === 0) {
69+
70+
if (!contentTypes || contentTypes?.length === 0) {
7471
log.info(messageHandler.parse('CONTENT_TYPE_NO_TYPES'), this.exportConfig.context);
7572
return;
7673
}
@@ -95,18 +92,20 @@ export default class EntriesExport extends BaseClass {
9592
}
9693

9794
const entryRequestOptions = this.createRequestObjects(locales, contentTypes);
98-
log.debug(`Created ${entryRequestOptions.length} entry request objects for processing`, this.exportConfig.context);
99-
95+
log.debug(
96+
`Created ${entryRequestOptions.length} entry request objects for processing`,
97+
this.exportConfig.context,
98+
);
99+
100100
for (let entryRequestOption of entryRequestOptions) {
101-
log.debug(`Processing entries for content type: ${entryRequestOption.contentType}, locale: ${entryRequestOption.locale}`, this.exportConfig.context);
101+
log.debug(
102+
`Processing entries for content type: ${entryRequestOption.contentType}, locale: ${entryRequestOption.locale}`,
103+
this.exportConfig.context,
104+
);
102105
await this.getEntries(entryRequestOption);
103106
this.entriesFileHelper?.completeFile(true);
104107
log.success(
105-
messageHandler.parse(
106-
'ENTRIES_EXPORT_COMPLETE',
107-
entryRequestOption.contentType,
108-
entryRequestOption.locale,
109-
),
108+
messageHandler.parse('ENTRIES_EXPORT_COMPLETE', entryRequestOption.contentType, entryRequestOption.locale),
110109
this.exportConfig.context,
111110
);
112111
}
@@ -120,8 +119,11 @@ export default class EntriesExport extends BaseClass {
120119
locales: Array<Record<string, unknown>>,
121120
contentTypes: Array<Record<string, unknown>>,
122121
): Array<Record<string, any>> {
123-
log.debug(`Creating request objects for ${contentTypes.length} content types and ${locales.length} locales`, this.exportConfig.context);
124-
122+
log.debug(
123+
`Creating request objects for ${contentTypes.length} content types and ${locales.length} locales`,
124+
this.exportConfig.context,
125+
);
126+
125127
let requestObjects: Array<Record<string, any>> = [];
126128
contentTypes.forEach((contentType) => {
127129
if (Object.keys(locales).length !== 0) {
@@ -165,8 +167,11 @@ export default class EntriesExport extends BaseClass {
165167
.entry()
166168
.query(requestObject)
167169
.find();
168-
169-
log.debug(`Fetched ${entriesSearchResponse.items?.length || 0} entries out of total ${entriesSearchResponse.count}`, this.exportConfig.context);
170+
171+
log.debug(
172+
`Fetched ${entriesSearchResponse.items?.length || 0} entries out of total ${entriesSearchResponse.count}`,
173+
this.exportConfig.context,
174+
);
170175
} catch (error) {
171176
handleAndLogError(error, {
172177
...this.exportConfig.context,
@@ -194,10 +199,10 @@ export default class EntriesExport extends BaseClass {
194199
});
195200
log.debug('Initialized FsUtility for writing entries', this.exportConfig.context);
196201
}
197-
202+
198203
log.debug(`Writing ${entriesSearchResponse.items.length} entries to file`, this.exportConfig.context);
199204
this.entriesFileHelper.writeIntoFile(entriesSearchResponse.items, { mapKeyVal: true });
200-
205+
201206
if (this.entriesConfig.exportVersions) {
202207
log.debug('Exporting entry versions is enabled', this.exportConfig.context);
203208
let versionedEntryPath = path.join(
@@ -227,7 +232,10 @@ export default class EntriesExport extends BaseClass {
227232

228233
options.skip += this.entriesConfig.limit || 100;
229234
if (options.skip >= entriesSearchResponse.count) {
230-
log.debug(`Completed fetching all entries for content type: ${options.contentType}, locale: ${options.locale}`, this.exportConfig.context);
235+
log.debug(
236+
`Completed fetching all entries for content type: ${options.contentType}, locale: ${options.locale}`,
237+
this.exportConfig.context,
238+
);
231239
return Promise.resolve(true);
232240
}
233241
log.debug(`Continuing to fetch entries with skip: ${options.skip}`, this.exportConfig.context);
@@ -240,7 +248,7 @@ export default class EntriesExport extends BaseClass {
240248
options: { locale: string; contentType: string; versionedEntryPath: string },
241249
): Promise<void> {
242250
log.debug(`Fetching versions for ${entries.length} entries`, this.exportConfig.context);
243-
251+
244252
const onSuccess = ({ response, apiData: entry }: any) => {
245253
const versionFilePath = path.join(sanitizePath(options.versionedEntryPath), sanitizePath(`${entry.uid}.json`));
246254
log.debug(`Writing versioned entry to: ${versionFilePath}`, this.exportConfig.context);
@@ -262,7 +270,10 @@ export default class EntriesExport extends BaseClass {
262270
);
263271
};
264272

265-
log.debug(`Starting concurrent calls for versioned entries with batch limit: ${this.entriesConfig.batchLimit}`, this.exportConfig.context);
273+
log.debug(
274+
`Starting concurrent calls for versioned entries with batch limit: ${this.entriesConfig.batchLimit}`,
275+
this.exportConfig.context,
276+
);
266277
return await this.makeConcurrentCall(
267278
{
268279
apiBatches: [entries],
@@ -289,7 +300,7 @@ export default class EntriesExport extends BaseClass {
289300
isLastRequest: boolean;
290301
}) {
291302
log.debug(`Processing versioned entry: ${entry.uid}`, this.exportConfig.context);
292-
303+
293304
return new Promise(async (resolve, reject) => {
294305
return await this.getEntryByVersion(apiParams.queryParam, entry)
295306
.then((response) => {
@@ -323,21 +334,27 @@ export default class EntriesExport extends BaseClass {
323334
},
324335
version: entry._version,
325336
};
326-
337+
327338
log.debug(`Fetching entry version ${entry._version} for uid: ${entry.uid}`, this.exportConfig.context);
328-
339+
329340
const entryResponse = await this.stackAPIClient
330341
.contentType(options.contentType)
331342
.entry(entry.uid)
332343
.fetch(queryRequestObject);
333344
entries.push(entryResponse);
334-
345+
335346
if (--entry._version > 0) {
336-
log.debug(`Continuing to fetch previous version ${entry._version} for entry: ${entry.uid}`, this.exportConfig.context);
347+
log.debug(
348+
`Continuing to fetch previous version ${entry._version} for entry: ${entry.uid}`,
349+
this.exportConfig.context,
350+
);
337351
return await this.getEntryByVersion(options, entry, entries);
338352
}
339-
340-
log.debug(`Completed fetching all versions for entry: ${entry.uid}, total versions: ${entries.length}`, this.exportConfig.context);
353+
354+
log.debug(
355+
`Completed fetching all versions for entry: ${entry.uid}, total versions: ${entries.length}`,
356+
this.exportConfig.context,
357+
);
341358
return entries;
342359
}
343360
}

0 commit comments

Comments
 (0)