Skip to content

Commit dccdd17

Browse files
committed
Conflict resolved in Destination stack css
2 parents 776fea5 + 177f4d3 commit dccdd17

File tree

39 files changed

+1243
-245
lines changed

39 files changed

+1243
-245
lines changed

.github/workflows/repo-sync.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,27 @@ jobs:
8989
cd migration-tool-sitecore
9090
git checkout -b sync-from-migration-v2-${{ github.event.pull_request.number }}
9191
git pull origin ${{ env.BRANCH }}
92+
93+
# Cleanup step to remove unused or deleted file references
94+
echo "Cleaning up unused or deleted file references..."
95+
git fetch --all
96+
git reset --hard origin/${{ env.BRANCH }}
97+
git clean -fdX # Remove untracked files and directories
98+
git gc --prune=now # Garbage collect and prune unreachable objects
99+
100+
# Remove unused imports and missing file references
101+
echo "Running ESLint to remove unused imports..."
102+
npm install eslint -g
103+
eslint . --fix
104+
105+
echo "Running autoflake to remove unused imports..."
106+
pip install autoflake
107+
autoflake --remove-all-unused-imports --recursive --in-place .
108+
109+
echo "Running ts-prune to remove unused file references..."
110+
npm install -g ts-prune
111+
ts-prune | awk '{print $1}' | xargs rm -f
112+
92113
rsync -av --delete ${{ env.RSYNC_SITECORE_API_SRC_SERVICES_EXCLUDES }} ../api/ ./api/
93114
rsync -av --delete ../cli/ ./cli/
94115
rsync -av --delete ../ui/ ./ui/
@@ -134,6 +155,27 @@ jobs:
134155
cd migration-tool-contentful
135156
git checkout -b sync-from-migration-v2-${{ github.event.pull_request.number }}
136157
git pull origin ${{ env.BRANCH }}
158+
159+
# Cleanup step to remove unused or deleted file references
160+
echo "Cleaning up unused or deleted file references..."
161+
git fetch --all
162+
git reset --hard origin/${{ env.BRANCH }}
163+
git clean -fdX # Remove untracked files and directories
164+
git gc --prune=now # Garbage collect and prune unreachable objects
165+
166+
# Remove unused imports and missing file references
167+
echo "Running ESLint to remove unused imports..."
168+
npm install eslint -g
169+
eslint . --fix
170+
171+
echo "Running autoflake to remove unused imports..."
172+
pip install autoflake
173+
autoflake --remove-all-unused-imports --recursive --in-place .
174+
175+
echo "Running ts-prune to remove unused file references..."
176+
npm install -g ts-prune
177+
ts-prune | awk '{print $1}' | xargs rm -f
178+
137179
rsync -av --delete ${{ env.RSYNC_CONTENTFUL_API_SRC_SERVICES_EXCLUDES }} ../api/ ./api/
138180
rsync -av --delete ../cli/ ./cli/
139181
rsync -av --delete ../ui/ ./ui/
@@ -179,6 +221,27 @@ jobs:
179221
cd migration-tool-wordpress
180222
git checkout -b sync-from-migration-v2-${{ github.event.pull_request.number }}
181223
git pull origin ${{ env.BRANCH }}
224+
225+
# Cleanup step to remove unused or deleted file references
226+
echo "Cleaning up unused or deleted file references..."
227+
git fetch --all
228+
git reset --hard origin/${{ env.BRANCH }}
229+
git clean -fdX # Remove untracked files and directories
230+
git gc --prune=now # Garbage collect and prune unreachable objects
231+
232+
# Remove unused imports and missing file references
233+
echo "Running ESLint to remove unused imports..."
234+
npm install eslint -g
235+
eslint . --fix
236+
237+
echo "Running autoflake to remove unused imports..."
238+
pip install autoflake
239+
autoflake --remove-all-unused-imports --recursive --in-place .
240+
241+
echo "Running ts-prune to remove unused file references..."
242+
npm install -g ts-prune
243+
ts-prune | awk '{print $1}' | xargs rm -f
244+
182245
rsync -av --delete ${{ env.RSYNC_WORDPRESS_API_SRC_SERVICES_EXCLUDES }} ../api/ ./api/
183246
rsync -av --delete ../cli/ ./cli/
184247
rsync -av --delete ../ui/ ./ui/

api/package-lock.json

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"@contentstack/cli-utilities": "^1.7.1",
3030
"@contentstack/json-rte-serializer": "^2.0.7",
3131
"@contentstack/marketplace-sdk": "^1.2.4",
32-
"axios": "^1.7.8",
32+
"axios": "^1.8.2",
3333
"chokidar": "^3.6.0",
3434
"cors": "^2.8.5",
3535
"dotenv": "^16.3.1",

api/src/services/auth.service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import logger from "../utils/logger.js";
2121
* @returns A promise that resolves to a LoginServiceType object.
2222
* @throws ExceptionFunction if an error occurs during the login process.
2323
*/
24+
2425
const login = async (req: Request): Promise<LoginServiceType> => {
2526
const srcFun = "Login";
2627
/*

api/src/services/contentful.service.ts

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import pLimit from 'p-limit';
99
import { JSDOM } from "jsdom";
1010
import { jsonToHtml, jsonToMarkdown, htmlToJson } from '@contentstack/json-rte-serializer';
1111

12-
13-
import { CHUNK_SIZE, MIGRATION_DATA_CONFIG, LOCALE_MAPPER } from "../constants/index.js";
12+
import { CHUNK_SIZE, LOCALE_MAPPER, MIGRATION_DATA_CONFIG } from "../constants/index.js";
1413
import { Locale } from "../models/types.js";
1514
import jsonRTE from "./contentful/jsonRTE.js";
1615
import { getAllLocales, getLogMessage } from "../utils/index.js";
@@ -86,6 +85,18 @@ function makeChunks(assetData: any) {
8685
return chunks;
8786
}
8887

88+
const mapLocales = ({ masterLocale, locale, locales }: any) => {
89+
if (locales?.masterLocale?.[masterLocale ?? ''] === locale) {
90+
return Object?.keys(locales?.masterLocale)?.[0]
91+
}
92+
for (const [key, value] of Object?.entries?.(locales) ?? {}) {
93+
if (typeof value !== 'object' && value === locale) {
94+
return key;
95+
}
96+
}
97+
return locale.toLowerCase();
98+
}
99+
89100
const transformCloudinaryObject = (input: any) => {
90101
const result: any = [];
91102
if (!Array.isArray(input)) {
@@ -122,7 +133,7 @@ const transformCloudinaryObject = (input: any) => {
122133
id: uuidv4(),
123134
folder: "",
124135
cs_metadata: {
125-
config_label: "config"
136+
config_label: "default_multi_config_key"
126137
}
127138
});
128139
}
@@ -702,17 +713,6 @@ const createEnvironment = async (packagePath: any, destination_stack_id: string,
702713
}
703714
};
704715

705-
const mapLocales = ({ masterLocale, locale, locales }: any) => {
706-
if (locales?.masterLocale?.[masterLocale ?? ''] === locale) {
707-
return Object?.keys(locales?.masterLocale)?.[0]
708-
}
709-
for (const [key, value] of Object?.entries?.(locales) ?? {}) {
710-
if (typeof value !== 'object' && value === locale) {
711-
return key;
712-
}
713-
}
714-
return locale.toLowerCase();
715-
}
716716

717717
/**
718718
* Creates and processes entries from a given package file and saves them to the destination stack directory.
@@ -740,7 +740,7 @@ const mapLocales = ({ masterLocale, locale, locales }: any) => {
740740
*
741741
* @throws Will log errors encountered during file reading, processing, or writing of entries.
742742
*/
743-
const createEntry = async (packagePath: any, destination_stack_id: string, projectId: string, contentTypes: any, mapperKeys: any, master_locale: string): Promise<void> => {
743+
const createEntry = async (packagePath: any, destination_stack_id: string, projectId: string, contentTypes: any, mapperKeys: any, master_locale: string, project: any): Promise<void> => {
744744
const srcFunc = 'createEntry';
745745
try {
746746
const entriesSave = path.join(DATA, destination_stack_id, ENTRIES_DIR_NAME);
@@ -749,7 +749,7 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje
749749
const data = await fs.promises.readFile(packagePath, "utf8");
750750
const entries = JSON.parse(data)?.entries;
751751
const content = JSON.parse(data)?.contentTypes;
752-
752+
const LocaleMapper = { masterLocale: project?.master_locale ?? LOCALE_MAPPER?.masterLocale, ...project?.locales ?? {} };
753753
if (entries && entries.length > 0) {
754754
const assetId = await readFile(assetsSave, ASSETS_SCHEMA_FILE) ?? [];
755755
const entryId = await readFile(path.join(DATA, destination_stack_id, REFERENCES_DIR_NAME), REFERENCES_FILE_NAME);
@@ -799,13 +799,13 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje
799799
});
800800
const pathName = getDisplayName(name, displayField);
801801
locales.forEach((locale) => {
802-
const localeCode = mapLocales({ masterLocale: master_locale, locale, locales: LOCALE_MAPPER });
802+
const localeCode = mapLocales({ masterLocale: master_locale, locale, locales: LocaleMapper });
803803
const publishDetails = Object?.values?.(environmentsId)?.length ? Object?.values?.(environmentsId)
804804
.filter((env: any) => env?.name === environment_id)
805805
?.map((env: any) => ({
806806
environment: env?.uid,
807807
version: 1,
808-
locale: locale?.toLowerCase?.(),
808+
locale: localeCode,
809809
})) : [];
810810
const title = fields?.[pathName]?.[locale] || "";
811811
const urlTitle = title
@@ -816,7 +816,7 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje
816816
title: title?.trim?.() === "" ? (urlTitle || id) : title,
817817
uid: id,
818818
url: `/${name?.toLowerCase?.()}/${urlTitle}`,
819-
locale: locale?.toLowerCase?.(),
819+
locale: localeCode,
820820
publish_details: publishDetails,
821821
};
822822
// Format object keys to snake_case
@@ -843,11 +843,12 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje
843843
for await (const [localeKey, localeValues] of Object.entries(
844844
values as { [key: string]: any }
845845
)) {
846+
const localeCode = mapLocales({ masterLocale: master_locale, locale: localeKey, locales: LocaleMapper });
846847
const chunks = makeChunks(localeValues);
847848
for (const [entryKey, entryValue] of Object.entries(localeValues)) {
848849
const message = getLogMessage(
849850
srcFunc,
850-
`Entry title "${(entryValue as { title: string })?.title}"(${ctName}) in the ${localeKey} locale has been successfully transformed.`,
851+
`Entry title "${(entryValue as { title: string })?.title}"(${ctName}) in the ${localeCode} locale has been successfully transformed.`,
851852
{}
852853
);
853854
await customLogger(projectId, destination_stack_id, "info", message);
@@ -856,7 +857,7 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje
856857
let chunkIndex = 1;
857858
const filePath = path.join(
858859
entriesSave,
859-
ctName, localeKey.toLowerCase()
860+
ctName, localeCode
860861
);
861862
for await (const [chunkId, chunkData] of Object.entries(chunks)) {
862863
refs[chunkIndex++] = `${chunkId}-entries.json`;
@@ -874,7 +875,7 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje
874875
await customLogger(projectId, destination_stack_id, 'info', message);
875876
}
876877
} catch (err) {
877-
console.info("🚀 ~ createEntry ~ err:", err)
878+
console.error("🚀 ~ createEntry ~ err:", err)
878879
const message = getLogMessage(
879880
srcFunc,
880881
`Error encountered while creating entries.`,
@@ -885,6 +886,10 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje
885886
}
886887
};
887888

889+
function getKeyByValue(obj: Record<string, string>, targetValue: string): string | undefined {
890+
return Object.entries(obj).find(([_, value]) => value === targetValue)?.[0];
891+
}
892+
888893
/**
889894
* Processes and creates locale configurations from a given package file and saves them to the destination stack directory.
890895
*
@@ -909,7 +914,7 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje
909914
*
910915
* @throws Will log errors encountered during file reading, processing, or writing of locale configurations.
911916
*/
912-
const createLocale = async (packagePath: string, destination_stack_id: string, projectId: string) => {
917+
const createLocale = async (packagePath: string, destination_stack_id: string, projectId: string, project: any) => {
913918
const srcFunc = 'createLocale';
914919
const localeSave = path.join(DATA, destination_stack_id, LOCALE_DIR_NAME);
915920
const globalFieldSave = path.join(DATA, destination_stack_id, GLOBAL_FIELDS_DIR_NAME);
@@ -933,30 +938,30 @@ const createLocale = async (packagePath: string, destination_stack_id: string, p
933938
)
934939
await customLogger(projectId, destination_stack_id, 'error', message);
935940
}
936-
937-
await Promise.all(locales.map(async (localeData: any) => {
938-
const title = localeData.sys.id;
941+
const fallbackMapLocales: any = { ...project?.master_locale ?? {}, ...project?.locales ?? {} }
942+
await Promise?.all(locales?.map?.(async (localeData: any) => {
943+
const currentMapLocale = getKeyByValue?.(fallbackMapLocales, localeData?.code) ?? `${localeData.code.toLowerCase()}`;
944+
const title = localeData?.sys?.id;
939945
const newLocale: Locale = {
940-
code: `${localeData.code.toLowerCase()}`,
941-
name: localeCodes?.[localeData.code.toLowerCase()] || "English - United States",
942-
fallback_locale: "",
946+
code: currentMapLocale,
947+
name: localeCodes?.[currentMapLocale] || "English - United States",
948+
fallback_locale: getKeyByValue(fallbackMapLocales, localeData?.fallbackCode) ?? '',
943949
uid: `${title}`,
944950
};
945951

946952
if (localeData.default === true) {
947953
msLocale[title] = newLocale;
948954
const message = getLogMessage(
949955
srcFunc,
950-
`Master Locale ${newLocale.code} has been successfully transformed.`,
956+
`Master Locale ${newLocale?.code} has been successfully transformed.`,
951957
{}
952958
)
953959
await customLogger(projectId, destination_stack_id, 'info', message);
954960
} else {
955-
newLocale.name = `${localeData.name}`;
956961
allLocales[title] = newLocale;
957962
const message = getLogMessage(
958963
srcFunc,
959-
`Locale ${newLocale.code} has been successfully transformed.`,
964+
`Locale ${newLocale?.code} has been successfully transformed.`,
960965
{}
961966
)
962967
await customLogger(projectId, destination_stack_id, 'info', message);

api/src/services/migration.service.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -254,12 +254,12 @@ const startTestMigration = async (req: Request): Promise<any> => {
254254
break;
255255
}
256256
case CMS.CONTENTFUL: {
257-
await contentfulService?.createLocale(file_path, project?.current_test_stack_id, projectId);
257+
await contentfulService?.createLocale(file_path, project?.current_test_stack_id, projectId, project);
258258
await contentfulService?.createRefrence(file_path, project?.current_test_stack_id, projectId);
259259
await contentfulService?.createWebhooks(file_path, project?.current_test_stack_id, projectId);
260260
await contentfulService?.createEnvironment(file_path, project?.current_test_stack_id, projectId);
261261
await contentfulService?.createAssets(file_path, project?.current_test_stack_id, projectId, true);
262-
await contentfulService?.createEntry(file_path, project?.current_test_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale);
262+
await contentfulService?.createEntry(file_path, project?.current_test_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale, project);
263263
await contentfulService?.createVersionFile(project?.current_test_stack_id, projectId);
264264
break;
265265
}
@@ -326,18 +326,16 @@ const startMigration = async (req: Request): Promise<any> => {
326326
await wordpressService?.extractPosts(packagePath, project?.destination_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale)
327327
await wordpressService?.extractGlobalFields(project?.destination_stack_id, projectId)
328328
await wordpressService?.createVersionFile(project?.destination_stack_id, projectId);
329-
330-
331329
}
332330
break;
333331
}
334332
case CMS.CONTENTFUL: {
335-
await contentfulService?.createLocale(file_path, project?.destination_stack_id, projectId);
333+
await contentfulService?.createLocale(file_path, project?.destination_stack_id, projectId, project);
336334
await contentfulService?.createRefrence(file_path, project?.destination_stack_id, projectId);
337335
await contentfulService?.createWebhooks(file_path, project?.destination_stack_id, projectId);
338336
await contentfulService?.createEnvironment(file_path, project?.destination_stack_id, projectId);
339337
await contentfulService?.createAssets(file_path, project?.destination_stack_id, projectId);
340-
await contentfulService?.createEntry(file_path, project?.destination_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale);
338+
await contentfulService?.createEntry(file_path, project?.destination_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale, project);
341339
await contentfulService?.createVersionFile(project?.destination_stack_id, projectId);
342340
break;
343341
}
@@ -478,8 +476,8 @@ export const updateLocaleMapper = async (req: Request) => {
478476
console.error(`project.json not found at ${projectFilePath}`);
479477
throw new Error(`project.json not found.`);
480478
}
481-
482479
// Find the project with the specified projectId
480+
await ProjectModelLowdb.read();
483481
const project: any = ProjectModelLowdb?.chain?.get?.("projects")?.find?.({ id: projectId })?.value();
484482
if (project) {
485483
const index = ProjectModelLowdb?.chain?.get("projects")?.findIndex?.({ id: projectId })?.value();

api/src/services/sitecore.service.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import customLogger from '../utils/custom-logger.utils.js';
1212

1313
const append = "a";
1414

15-
1615
const baseDirName = MIGRATION_DATA_CONFIG.DATA
1716
const {
1817
ENTRIES_DIR_NAME,

0 commit comments

Comments
 (0)