@@ -44,7 +44,7 @@ export function entryCreateScript(contentType) {
4444 function getValueByPath(obj, path) {
4545 return path.split('[').reduce((o, key) => o && o[key.replace(/\]$/, '')], obj);
4646 }
47-
47+
4848 function updateValueByPath(obj, path, newValue) {
4949 path.split('[').reduce((o, key, index, arr) => {
5050 if (index === arr.length - 1) {
@@ -54,10 +54,10 @@ export function entryCreateScript(contentType) {
5454 }
5555 }, obj);
5656 }
57-
57+
5858 const findReference = function (schema, path, flag) {
5959 let references = [];
60-
60+
6161 for (const i in schema) {
6262 const currentPath = path ? path + '[' + schema[i].uid : schema[i].uid;
6363 if (schema[i].data_type === 'group' || schema[i].data_type === 'global_field') {
@@ -77,7 +77,7 @@ export function entryCreateScript(contentType) {
7777 references.push(currentPath);
7878 }
7979 }
80-
80+
8181 return references;
8282 };
8383
@@ -169,7 +169,7 @@ export function entryCreateScript(contentType) {
169169 }
170170 parent.pop();
171171 }
172-
172+
173173 function findAssetIdsFromHtmlRte(entryObj, ctSchema) {
174174 const regex = /<img asset_uid=\\"([^"]+)\\"/g;
175175 let match;
@@ -179,7 +179,7 @@ export function entryCreateScript(contentType) {
179179 cAssetDetails.push({uid: match[1]});
180180 }
181181 }
182-
182+
183183 function findFileUrls(schema, _entry) {
184184 let markdownRegEx;
185185 let markdownMatch;
@@ -191,7 +191,7 @@ export function entryCreateScript(contentType) {
191191 text = JSON.stringify(_entry);
192192 }
193193 markdownRegEx = new RegExp(
194- '(https://(assets|(eu-|azure-na-|azure-eu-|gcp-na-)?images).contentstack.(io|com)/v3/assets/(.*?)/(.*?)/(.*?)/(.*?)(?="))',
194+ '(https://(assets|(eu-|azure-na-|azure-eu-|gcp-na-|gcp-eu- )?images).contentstack.(io|com)/v3/assets/(.*?)/(.*?)/(.*?)/(.*?)(?="))',
195195 'g',
196196 );
197197 while ((markdownMatch = markdownRegEx.exec(text)) !== null) {
@@ -207,7 +207,7 @@ export function entryCreateScript(contentType) {
207207 }
208208 }
209209 }
210-
210+
211211 function findAssetIdsFromJsonRte(entryObj, ctSchema) {
212212 if(ctSchema !== undefined){
213213 for (const element of ctSchema) {
@@ -253,7 +253,7 @@ export function entryCreateScript(contentType) {
253253 }
254254 }
255255 }
256-
256+
257257 function gatherJsonRteAssetIds(jsonRteData) {
258258 jsonRteData.children.forEach((element) => {
259259 if (element.type) {
@@ -297,7 +297,7 @@ export function entryCreateScript(contentType) {
297297 }
298298 });
299299 }
300-
300+
301301 const updateAssetDetailsInEntries = function (entry) {
302302 let updatedEntry = Object.assign({},entry);
303303 entry = updateFileFields(updatedEntry, entry, null)
@@ -310,7 +310,7 @@ export function entryCreateScript(contentType) {
310310 entry = entry.replace(assetUrl, mappedAssetUrl);
311311 }
312312 });
313-
313+
314314 assetUIDs.forEach(function (assetUid) {
315315 let uid = assetUIDMapper[assetUid];
316316 if (typeof uid !== 'undefined') {
@@ -335,11 +335,11 @@ export function entryCreateScript(contentType) {
335335 parent[pos] = '';
336336 }
337337 };
338-
338+
339339 if (parent.uid && assetUIDMapper[parent.uid]) {
340340 parent.uid = assetUIDMapper[parent.uid];
341341 }
342-
342+
343343 if (
344344 object &&
345345 isObject(parent[pos]) &&
@@ -356,7 +356,7 @@ export function entryCreateScript(contentType) {
356356 ) {
357357 parent = omit(parent, ['asset']);
358358 }
359-
359+
360360 if (object.uid && assetUIDMapper[object.uid]) {
361361 object.uid = assetUIDMapper[object.uid];
362362 }
@@ -373,12 +373,12 @@ export function entryCreateScript(contentType) {
373373 } else if (isArray(object) && object.length) {
374374 for (let i = 0; i <= object.length; i++){
375375 updateFileFields(object[i], object, i);
376- }
376+ }
377377 parent[pos] = compact(object);
378378 }
379379 return object;
380380 }
381-
381+
382382 const checkAndDownloadAsset = async function (cAsset) {
383383 const assetUID = cAsset?.uid;
384384 if (cAsset && assetUID) {
@@ -431,24 +431,24 @@ export function entryCreateScript(contentType) {
431431 }
432432 return cAsset;
433433 };
434-
434+
435435 const uploadAssets = async function () {
436436 const assetFolderMap = JSON.parse(fs.readFileSync(path.resolve(filePath, 'folder-mapper.json'), 'utf8'));
437437 const stackAPIClient = managementAPIClient.stack({ api_key: stackSDKInstance.api_key, branch_uid: branch });
438438 for (let i = 0; i < downloadedAssets?.length; i++) {
439439 const asset = downloadedAssets[i];
440440 let requestOption = {};
441-
441+
442442 requestOption.parent_uid = assetFolderMap[asset.parent_uid] || asset.parent_uid;
443-
443+
444444 if (asset.hasOwnProperty('description') && typeof asset.description === 'string') {
445445 requestOption.description = asset.description;
446446 }
447-
447+
448448 if (asset.hasOwnProperty('tags') && Array.isArray(asset.tags)) {
449449 requestOption.tags = asset.tags;
450450 }
451-
451+
452452 if (asset.hasOwnProperty('title') && typeof asset.title === 'string') {
453453 requestOption.title = asset.title;
454454 }
@@ -464,7 +464,7 @@ export function entryCreateScript(contentType) {
464464 assetUrlMapper[asset.url] = res && res.url;
465465 }
466466 };
467-
467+
468468 function handleErrorMsg(err) {
469469 if (err?.errorMessage) {
470470 console.log(err.errorMessage);
@@ -479,14 +479,14 @@ export function entryCreateScript(contentType) {
479479 limit,
480480 include_count: true,
481481 };
482-
482+
483483 const entriesSearchResponse = await managementAPIClient
484484 .stack({ api_key: stackSDKInstance.api_key, branch_uid: branchName })
485485 .contentType(contentType)
486486 .entry()
487487 .query(requestObject)
488488 .find();
489-
489+
490490 if (entriesSearchResponse?.items?.length > 0) {
491491 skip += limit || 100;
492492 entries = [...entries, ...entriesSearchResponse.items];
@@ -507,12 +507,12 @@ export function entryCreateScript(contentType) {
507507 task: async () => {
508508
509509 const compareBranchEntries = await getEntries(compareBranch, '${ contentType } ')
510-
510+
511511 const compareFilteredProperties = compareBranchEntries.map((entry) => {
512512 keysToRemove.map((key) => delete entry[key]);
513513 return entry;
514514 });
515-
515+
516516 let contentType = await managementAPIClient
517517 .stack({ api_key: stackSDKInstance.api_key, branch_uid: compareBranch })
518518 .contentType('${ contentType } ')
@@ -553,7 +553,7 @@ export function entryCreateScript(contentType) {
553553 for (let i in references) {
554554 let compareEntryRef = getValueByPath(entryDetails, references[i]);
555555 let baseEntryRef = getValueByPath(baseEntry, references[i]);
556-
556+
557557 if (compareEntryRef && compareEntryRef.length > 0 && baseEntryRef && baseEntryRef.length >= 0) {
558558 let compareRefEntry = await managementAPIClient
559559 .stack({ api_key: stackSDKInstance.api_key, branch_uid: compareBranch })
@@ -565,7 +565,7 @@ export function entryCreateScript(contentType) {
565565 .entry()
566566 .query({ query: { title: compareRefEntry.title } })
567567 .find();
568-
568+
569569 if(baseRefEntry?.items?.length > 0 && baseRefEntry.items[0]?.uid){
570570 updateValueByPath(entryDetails, references[i], baseRefEntry.items[0].uid);
571571 }
0 commit comments