Skip to content

Commit b4375cb

Browse files
exported createLocale func/removed unnecessary code
1 parent d32ead1 commit b4375cb

File tree

1 file changed

+6
-103
lines changed

1 file changed

+6
-103
lines changed

api/src/services/wordpress.service.ts

Lines changed: 6 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ import fs from "fs";
22
import path from "path";
33
import { fileURLToPath } from "url";
44
import axios from "axios";
5-
//import _ from "lodash";
6-
import { MIGRATION_DATA_CONFIG } from "../constants/index.js";
5+
import { MIGRATION_DATA_CONFIG, LOCALE_MAPPER } from "../constants/index.js";
76
import jsdom from "jsdom";
87
import { htmlToJson, jsonToHtml } from "@contentstack/json-rte-serializer";
98
import customLogger from "../utils/custom-logger.utils.js";
109
import { getLogMessage } from "../utils/index.js";
11-
import { Advanced } from "../models/FieldMapper.js";
1210
import { v4 as uuidv4 } from "uuid";
1311
import { orgService } from "./org.service.js";
1412

@@ -22,7 +20,6 @@ const __dirname = path.dirname(__filename);
2220

2321
const { DATA, EXPORT_INFO_FILE } = MIGRATION_DATA_CONFIG
2422

25-
//const slugRegExp = /[^a-z0-9_-]+/g;
2623
let assetsSave = path.join(
2724
MIGRATION_DATA_CONFIG.DATA,
2825
MIGRATION_DATA_CONFIG.ASSETS_DIR_NAME
@@ -70,27 +67,12 @@ let assetMasterFolderPath = path.join(
7067
"logs",
7168
MIGRATION_DATA_CONFIG.ASSETS_DIR_NAME
7269
);
73-
// let globalPrefix = "";
7470

7571
interface Asset {
7672
"wp:post_type": string;
7773
[key: string]: any;
7874
}
7975

80-
interface FieldMapping {
81-
id: string;
82-
projectId: string;
83-
uid: string;
84-
otherCmsField: string;
85-
otherCmsType: string;
86-
contentstackField: string;
87-
contentstackFieldUid: string;
88-
contentstackFieldType: string;
89-
isDeleted: boolean;
90-
backupFieldType: string;
91-
refrenceTo: { uid: string; title: string };
92-
advanced: Advanced;
93-
}
9476

9577
const idCorrector = (id: any) => {
9678
const newId = id?.replace(/[-{}]/g, (match: any) => match === '-' ? '' : '')
@@ -369,13 +351,7 @@ async function saveAsset(assets: any, retryCount: number, affix: string, destina
369351
console.error(`Asset already present: ${customId}`);
370352
return assets["wp:post_id"];
371353
}
372-
// else{
373-
// fs.mkdirSync(
374-
// path.resolve(
375-
// assetPath
376-
// )
377-
// );
378-
// }
354+
379355

380356
try {
381357
const response = await axios.get(url, { responseType: "arraybuffer" });
@@ -412,11 +388,7 @@ async function saveAsset(assets: any, retryCount: number, affix: string, destina
412388
await writeFileAsync(failedJSONFilePath, failedJSON, 4);
413389
}
414390
assetData[key] = acc[key];
415-
// await writeFileAsync(
416-
// path.join(assetsSave, MIGRATION_DATA_CONFIG.ASSETS_FILE_NAME),
417-
// assetData,
418-
// 4
419-
// );
391+
420392

421393
await writeFileAsync(
422394
path.join(assetsSave, MIGRATION_DATA_CONFIG.ASSETS_SCHEMA_FILE),
@@ -430,13 +402,6 @@ async function saveAsset(assets: any, retryCount: number, affix: string, destina
430402
)
431403
await customLogger(projectId, destinationStackId, 'info', message);
432404

433-
// console.log(
434-
// "An asset with id",
435-
// `assets_${assets["wp:post_id"]}`,
436-
// "and name",
437-
// `${name}`,
438-
// "downloaded successfully."
439-
// );
440405

441406
return assets["wp:post_id"];
442407
} catch (err: any) {
@@ -512,15 +477,13 @@ async function getAllAssets(
512477
alldataParsed?.channel?.["wp:base_site_url"];
513478
const assets: Asset[] =
514479
alldataParsed?.rss?.channel?.item ?? alldataParsed?.channel?.item;
515-
// await writeFileAsync(path.join(assetsSave, MIGRATION_DATA_CONFIG.ASSETS_FILE_NAME), assets, 4);
516480
if (!assets || assets?.length === 0) {
517481
const message = getLogMessage(
518482
"createAssetFolderFile",
519483
`No assets found.`,
520484
{}
521485
)
522486
await customLogger(projectId, destinationStackId, 'info', message);
523-
// console.log("No assets found", projectId);
524487
return;
525488
}
526489

@@ -565,7 +528,6 @@ const createAssetFolderFile = async (affix: string, destinationStackId:string, p
565528
{}
566529
)
567530
await customLogger(projectId, destinationStackId, 'info', message);
568-
// console.log("Folder JSON created successfully.");
569531
return;
570532
} catch (error) {
571533
return {
@@ -618,7 +580,7 @@ async function saveReference(referenceDetails: any[], destinationStackId:string,
618580
{}
619581
)
620582
await customLogger(projectId, destinationStackId, 'info', message);
621-
// console.log("Reference data saved successfully.");
583+
622584
} catch (error) {
623585
return {
624586
err: "error in saving references",
@@ -703,7 +665,6 @@ async function getAllreference(affix: string, packagePath: string, destinationSt
703665
)
704666
await customLogger(projectId, destinationStackId, 'info', message);
705667

706-
// console.log("All references processed successfully.");
707668
} catch (error) {
708669
return {
709670
err: "error in processing references",
@@ -803,15 +764,13 @@ async function extractChunks(affix: string, packagePath: string, destinationStac
803764
{}
804765
)
805766
await customLogger(projectId, destinationStackId, 'info', message);
806-
// console.log("Post chunks creation completed.");
807767
} else {
808768
const message = getLogMessage(
809769
srcFunc,
810770
`No posts found.`,
811771
{},
812772
)
813773
await customLogger(projectId, destinationStackId, 'info', message);
814-
// console.error("No posts found.");
815774
}
816775
} catch (error) {
817776
const message = getLogMessage(
@@ -821,7 +780,6 @@ async function extractChunks(affix: string, packagePath: string, destinationStac
821780
error
822781
)
823782
await customLogger(projectId, destinationStackId, 'error', message);
824-
// console.error(error);
825783
return;
826784
}
827785
}
@@ -995,7 +953,6 @@ async function getAllAuthors(affix: string, packagePath: string,destinationStack
995953
{}
996954
)
997955
await customLogger(projectId, destinationStackId, 'info', message);
998-
// console.log("\nNo authors UID found");
999956
}
1000957
} else {
1001958
const message = getLogMessage(
@@ -1004,7 +961,6 @@ async function getAllAuthors(affix: string, packagePath: string,destinationStack
1004961
{}
1005962
)
1006963
await customLogger(projectId, destinationStackId, 'info', message);
1007-
// console.log("\nNo authors found");
1008964
}
1009965
} catch (error) {
1010966
const message = getLogMessage(
@@ -1014,7 +970,6 @@ async function getAllAuthors(affix: string, packagePath: string,destinationStack
1014970
error
1015971
)
1016972
await customLogger(projectId, destinationStackId, 'error', message);
1017-
// console.log("error while getting authors", error);
1018973
}
1019974
}
1020975
/************ end of authors module functions *********/
@@ -1031,13 +986,6 @@ async function startingDirContentTypes(destinationStackId: string) {
1031986
} catch {
1032987
// Directory doesn't exist, create it
1033988
await fs.promises.mkdir(contentTypeFolderPath, { recursive: true });
1034-
// await fs.promises.writeFile(
1035-
// path.join(
1036-
// contentTypeFolderPath,
1037-
// MIGRATION_DATA_CONFIG.CONTENT_TYPES_FILE_NAME
1038-
// ),
1039-
// "{}"
1040-
// );
1041989
await fs.promises.writeFile(
1042990
path.join(
1043991
contentTypeFolderPath,
@@ -1048,18 +996,6 @@ async function startingDirContentTypes(destinationStackId: string) {
1048996
}
1049997
}
1050998

1051-
// const generateUid = (suffix: string) =>
1052-
// globalPrefix
1053-
// ? `${globalPrefix
1054-
// .replace(/^\d+/, "")
1055-
// .replace(/[^a-zA-Z0-9]+/g, "_")
1056-
// .replace(/(^_+)|(_+$)/g, "")
1057-
// .toLowerCase()}_${suffix}`
1058-
// : suffix;
1059-
1060-
// const generateTitle = (title: string) =>
1061-
// globalPrefix ? `${globalPrefix} - ${title}` : title;
1062-
1063999
const generateSchema = (
10641000
title: string,
10651001
uid: string,
@@ -1543,14 +1479,6 @@ async function extractContentTypes(projectId: string,destinationStackId: string)
15431479
}
15441480

15451481
);
1546-
// await writeFileAsync(
1547-
// path.join(
1548-
// contentTypeFolderPath,
1549-
// MIGRATION_DATA_CONFIG.CONTENT_TYPES_FILE_NAME
1550-
// ),
1551-
// schemaJson,
1552-
// 4
1553-
// );
15541482
await writeFileAsync(
15551483
path.join(
15561484
contentTypeFolderPath,
@@ -1639,8 +1567,6 @@ async function saveTerms(termsDetails: any[], destinationStackId: string, projec
16391567
const { id } = data;
16401568
const uid = `terms_${id}`;
16411569
const customId = uid;
1642-
// const title = name ?? `Terms - ${id}`;
1643-
//const url = `/${title.toLowerCase().replace(/ /g, "_")}`;
16441570

16451571

16461572
termsdata[customId] = {
@@ -1677,7 +1603,6 @@ async function saveTerms(termsDetails: any[], destinationStackId: string, projec
16771603
{}
16781604
)
16791605
await customLogger(projectId, destinationStackId, 'info', message);
1680-
// console.log(`${termsDetails.length} Terms exported successfully`);
16811606
} catch (error) {
16821607
const message = getLogMessage(
16831608
srcFunc,
@@ -1686,7 +1611,6 @@ async function saveTerms(termsDetails: any[], destinationStackId: string, projec
16861611
error
16871612
)
16881613
await customLogger(projectId, destinationStackId, 'error', message);
1689-
// console.error("Error saving terms:", error);
16901614
throw error;
16911615
}
16921616
}
@@ -1711,7 +1635,6 @@ async function getAllTerms(affix: string, packagePath: string, destinationStackI
17111635
{}
17121636
)
17131637
await customLogger(projectId, destinationStackId, 'info', message);
1714-
// console.log("\nNo terms found");
17151638
return;
17161639
}
17171640

@@ -1742,7 +1665,6 @@ async function getAllTerms(affix: string, packagePath: string, destinationStackI
17421665
error
17431666
)
17441667
await customLogger(projectId, destinationStackId, 'error', message);
1745-
// console.error("Error retrieving terms:", error);
17461668
}
17471669
}
17481670

@@ -1808,9 +1730,6 @@ async function saveTags(tagDetails: any[], destinationStackId: string, projectId
18081730
for(const data of tagDetails) {
18091731
const { id } = data;
18101732
const uid = `tags_${id}`;
1811-
//const title = `Tags - ${id}`;
1812-
// const url = `/tags/${uid}`;
1813-
//const url = `/${title.toLowerCase().replace(/ /g, "_")}`;
18141733
const customId = idCorrector(uid);
18151734

18161735
tagsdata[customId]={
@@ -1844,7 +1763,6 @@ async function saveTags(tagDetails: any[], destinationStackId: string, projectId
18441763
)
18451764
await customLogger(projectId, destinationStackId, 'info', message);
18461765

1847-
// console.log(`${tagDetails.length}`, " Tags exported successfully");
18481766
} catch (error) {
18491767
const message = getLogMessage(
18501768
srcFunc,
@@ -1877,7 +1795,6 @@ async function getAllTags(affix: string, packagePath: string, destinationStackId
18771795
{}
18781796
)
18791797
await customLogger(projectId, destinationStackId, 'info', message);
1880-
// console.log("\nNo tags found");
18811798
return;
18821799
}
18831800
const tagsArray = Array.isArray(tags) ? tags.map((taginfo) => ({
@@ -1906,7 +1823,6 @@ async function getAllTags(affix: string, packagePath: string, destinationStackId
19061823
error
19071824
)
19081825
await customLogger(projectId, destinationStackId, 'error', message);
1909-
// console.error("Error retrieving tags:", error);
19101826
throw error;
19111827
}
19121828
}
@@ -2025,7 +1941,6 @@ async function saveCategories(categoryDetails: any[], destinationStackId:string,
20251941
4
20261942
);
20271943
await writeFileAsync(path.join(categoriesFolderPath, "index.json"), {"1": `${master_locale}.json`}, 4);
2028-
// Create index.json for other locales and write data for those locales
20291944
for (const loc of localeKeys) {
20301945
if (loc === master_locale) continue;
20311946

@@ -2048,10 +1963,6 @@ async function saveCategories(categoryDetails: any[], destinationStackId:string,
20481963
{}
20491964
)
20501965
await customLogger(projectId, destinationStackId, 'info', message);
2051-
// console.log(
2052-
// `${categoryDetails.length}`,
2053-
// " Categories exported successfully"
2054-
// );
20551966
} catch (err) {
20561967
const message = getLogMessage(
20571968
srcFunc,
@@ -2060,7 +1971,6 @@ async function saveCategories(categoryDetails: any[], destinationStackId:string,
20601971
err
20611972
)
20621973
await customLogger(projectId, destinationStackId, 'error', message);
2063-
// console.error("Error in saving categories:", err);
20641974
}
20651975
}
20661976
async function getAllCategories(affix: string, packagePath: string, destinationStackId:string, projectId: string,contentTypes:any, keyMapper:any, master_locale: string, project:any) {
@@ -2084,7 +1994,6 @@ async function getAllCategories(affix: string, packagePath: string, destinationS
20841994
{}
20851995
)
20861996
await customLogger(projectId, destinationStackId, 'info', message);
2087-
// console.log("\nNo categories found");
20881997
return;
20891998
}
20901999

@@ -2333,7 +2242,6 @@ async function processChunkData(
23332242
const base = blog_base_url?.split("/")?.filter(Boolean);
23342243
const blogname = base[base?.length - 1];
23352244
const url = data["link"]?.split(blogname)[1];
2336-
//const title = data["title"] ?? `Posts - ${data["wp:post_id"]}`;
23372245
const uid = `posts_${data["wp:post_id"]}`
23382246
const customId = idCorrector(uid)
23392247
postdata[customId] = {
@@ -2370,11 +2278,6 @@ async function processChunkData(
23702278
);
23712279
postdataCombined = { ...postdataCombined, ...formatted_posts };
23722280

2373-
// await writeFileAsync(
2374-
// path.join(postFolderPath, filename),
2375-
// postdata,
2376-
// 4
2377-
// );
23782281
})
23792282
);
23802283
}
@@ -2507,7 +2410,7 @@ async function copyFolder(src: string, dest: string) {
25072410
err
25082411
)
25092412
await customLogger("projectId", dest, 'error', message);
2510-
// console.error(`Error copying folder from ${src} to ${dest}:`, err);
2413+
25112414
}
25122415
}
25132416
async function extractGlobalFields(destinationStackId: string, projectId: string) {
@@ -2544,7 +2447,6 @@ async function extractGlobalFields(destinationStackId: string, projectId: string
25442447
err
25452448
)
25462449
await customLogger(projectId, destinationStackId, 'error', message);
2547-
// console.error(`Error copying ${folder}:`, err);
25482450
}
25492451
}
25502452
}
@@ -2576,6 +2478,7 @@ const createVersionFile = async (destinationStackId: string, projectId: string)
25762478

25772479
export const wordpressService = {
25782480
getAllAssets,
2481+
createLocale,
25792482
createAssetFolderFile,
25802483
getAllreference,
25812484
extractChunks,

0 commit comments

Comments
 (0)