Skip to content

Commit dcef9e8

Browse files
Merge pull request #557 from contentstack/dev
Dev
2 parents 3422fff + ece10b6 commit dcef9e8

File tree

49 files changed

+1526
-997
lines changed

Some content is hidden

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

49 files changed

+1526
-997
lines changed

.github/workflows/repo-sync.yml

Lines changed: 127 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -97,24 +97,84 @@ jobs:
9797
git clean -fdX # Remove untracked files and directories
9898
git gc --prune=now # Garbage collect and prune unreachable objects
9999
100-
# Remove unused imports and missing file references
100+
# echo "Installing ESLint dependencies..."
101+
npm install --save-dev eslint @eslint/js globals
102+
103+
104+
# if [ ! -f "eslint.config.cjs" ]; then
105+
# echo "Creating default ESLint config..."
106+
# cat <<EOL > eslint.config.cjs
107+
# const js = require("@eslint/js");
108+
# const globals = require("globals");
109+
110+
# module.exports = [
111+
# js.configs.recommended,
112+
# {
113+
# languageOptions: {
114+
# ecmaVersion: "latest",
115+
# sourceType: "module",
116+
# globals: globals.node,
117+
# },
118+
# rules: {
119+
# "no-unused-vars": "warn",
120+
# "no-console": "off"
121+
# }
122+
# }
123+
# ];
124+
# EOL
125+
# fi
126+
127+
# # Remove unused imports and missing file references
101128
# echo "Running ESLint to remove unused imports..."
102129
# npm install eslint -g
103130
# eslint . --fix
104131
105-
echo "Running autoflake to remove unused imports..."
106-
pip install autoflake
107-
autoflake --remove-all-unused-imports --recursive --in-place .
132+
# echo "Running autoflake to remove unused imports..."
133+
# pip install autoflake
134+
# autoflake --remove-all-unused-imports --recursive --in-place .
108135
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
136+
# echo "Running ts-prune to remove unused file references..."
137+
# npm install -g ts-prune
138+
# ts-prune | awk '{print $1}' | xargs rm -f
112139
113140
rsync -av --delete ${{ env.RSYNC_SITECORE_API_SRC_SERVICES_EXCLUDES }} ../api/ ./api/
114141
rsync -av --delete ../cli/ ./cli/
115142
rsync -av --delete ../ui/ ./ui/
116143
rsync -av --delete ${{ env.RSYNC_SITECORE_UPLOAD_API_SRC_EXCLUDES }} ../upload-api/src/ ./upload-api/src/
117144
rsync -av --delete ../upload-api/migration-sitecore/ ./upload-api/migration-sitecore/
145+
146+
# Ensure tsconfig.json exists, create a default one if missing
147+
# if [ ! -f "tsconfig.json" ]; then
148+
# echo "Creating default tsconfig.json..."
149+
# cat <<EOL > tsconfig.json
150+
# {
151+
# "compilerOptions": {
152+
# "target": "ES6",
153+
# "module": "CommonJS",
154+
# "strict": true,
155+
# "esModuleInterop": true,
156+
# "skipLibCheck": true,
157+
# "forceConsistentCasingInFileNames": true
158+
# },
159+
# "include": ["src/**/*"],
160+
# "exclude": ["node_modules", "dist"]
161+
# }
162+
# EOL
163+
# fi
164+
165+
# Remove unused imports
166+
# npx ts-remove-unused-imports api/
167+
# npx ts-remove-unused-imports ui/
168+
# npx ts-remove-unused-imports upload-api/
169+
170+
# Remove missing imports
171+
# npx ts-prune | grep -E '^(api/|ui/|upload-api/)/' | awk '{print $1}' | xargs -I {} sed -i '/import/d' {}
172+
173+
# # Format code
174+
# npx prettier --write .
175+
176+
# eslint api/ ui/ upload-api/ --rule 'import/no-unresolved: error' --format compact | awk -F ':' '{print $1}' | sort -u | xargs -I {} sed -i '/import/d' {}
177+
118178
git add .
119179
git commit -m "Sync changes from migration-v2 PR #${{ github.event.pull_request.number }}"
120180
git push origin sync-from-migration-v2-${{ github.event.pull_request.number }}
@@ -163,10 +223,37 @@ jobs:
163223
git clean -fdX # Remove untracked files and directories
164224
git gc --prune=now # Garbage collect and prune unreachable objects
165225
226+
echo "Installing ESLint dependencies..."
227+
npm install --save-dev eslint @eslint/js globals
228+
229+
if [ ! -f "eslint.config.cjs" ]; then
230+
echo "Creating default ESLint config..."
231+
cat <<EOL > eslint.config.cjs
232+
const js = require("@eslint/js");
233+
const globals = require("globals");
234+
235+
module.exports = [
236+
js.configs.recommended,
237+
{
238+
languageOptions: {
239+
ecmaVersion: "latest",
240+
sourceType: "module",
241+
globals: globals.node,
242+
},
243+
rules: {
244+
"no-unused-vars": "warn",
245+
"no-console": "off"
246+
}
247+
}
248+
];
249+
EOL
250+
fi
251+
252+
166253
# Remove unused imports and missing file references
167-
# echo "Running ESLint to remove unused imports..."
168-
# npm install eslint -g
169-
# eslint . --fix
254+
echo "Running ESLint to remove unused imports..."
255+
npm install eslint -g
256+
eslint . --fix
170257
171258
echo "Running autoflake to remove unused imports..."
172259
pip install autoflake
@@ -229,10 +316,37 @@ jobs:
229316
git clean -fdX # Remove untracked files and directories
230317
git gc --prune=now # Garbage collect and prune unreachable objects
231318
319+
echo "Installing ESLint dependencies..."
320+
npm install --save-dev eslint @eslint/js globals
321+
322+
if [ ! -f "eslint.config.cjs" ]; then
323+
echo "Creating default ESLint config..."
324+
cat <<EOL > eslint.config.cjs
325+
const js = require("@eslint/js");
326+
const globals = require("globals");
327+
328+
module.exports = [
329+
js.configs.recommended,
330+
{
331+
languageOptions: {
332+
ecmaVersion: "latest",
333+
sourceType: "module",
334+
globals: globals.node,
335+
},
336+
rules: {
337+
"no-unused-vars": "warn",
338+
"no-console": "off"
339+
}
340+
}
341+
];
342+
EOL
343+
fi
344+
345+
232346
# Remove unused imports and missing file references
233-
# echo "Running ESLint to remove unused imports..."
234-
# npm install eslint -g
235-
# eslint . --fix
347+
echo "Running ESLint to remove unused imports..."
348+
npm install eslint -g
349+
eslint . --fix
236350
237351
echo "Running autoflake to remove unused imports..."
238352
pip install autoflake

api/src/services/migration.service.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ const startTestMigration = async (req: Request): Promise<any> => {
230230
case CMS.SITECORE_V9:
231231
case CMS.SITECORE_V10: {
232232
if (packagePath) {
233-
await siteCoreService?.createEntry({ packagePath, contentTypes, master_locale: project?.stackDetails?.master_locale, destinationStackId: project?.current_test_stack_id, projectId, keyMapper: project?.mapperKeys });
234-
await siteCoreService?.createLocale(req, project?.current_test_stack_id, projectId);
233+
await siteCoreService?.createEntry({ packagePath, contentTypes, master_locale: project?.stackDetails?.master_locale, destinationStackId: project?.current_test_stack_id, projectId, keyMapper: project?.mapperKeys, project });
234+
await siteCoreService?.createLocale(req, project?.current_test_stack_id, projectId, project);
235235
await siteCoreService?.createVersionFile(project?.current_test_stack_id);
236236
}
237237
break;
@@ -306,8 +306,8 @@ const startMigration = async (req: Request): Promise<any> => {
306306
case CMS.SITECORE_V9:
307307
case CMS.SITECORE_V10: {
308308
if (packagePath) {
309-
await siteCoreService?.createEntry({ packagePath, contentTypes, master_locale: project?.stackDetails?.master_locale, destinationStackId: project?.destination_stack_id, projectId, keyMapper: project?.mapperKeys });
310-
await siteCoreService?.createLocale(req, project?.destination_stack_id, projectId);
309+
await siteCoreService?.createEntry({ packagePath, contentTypes, master_locale: project?.stackDetails?.master_locale, destinationStackId: project?.destination_stack_id, projectId, keyMapper: project?.mapperKeys, project });
310+
await siteCoreService?.createLocale(req, project?.destination_stack_id, projectId, project);
311311
await siteCoreService?.createVersionFile(project?.destination_stack_id);
312312
}
313313
break;
@@ -417,18 +417,18 @@ const getLogs = async (req: Request): Promise<any> => {
417417
*/
418418
export const createSourceLocales = async (req: Request) => {
419419

420-
const projectId = req.params.projectId;
421-
const locales = req.body.locale
420+
const projectId = req?.params?.projectId;
421+
const locales = req?.body?.locale;
422+
console.info("🚀 ~ createSourceLocales ~ locales:", locales);
422423

423424
try {
424425
// Find the project with the specified projectId
425426
await ProjectModelLowdb?.read?.();
426427
const index = ProjectModelLowdb?.chain?.get?.("projects")?.findIndex?.({ id: projectId })?.value?.();
427-
if (index > -1) {
428+
if (typeof index === "number" && index > -1) {
428429
ProjectModelLowdb?.update?.((data: any) => {
429430
data.projects[index].source_locales = locales;
430431
});
431-
// Write back the updated projects
432432
} else {
433433
logger.error(`Project with ID: ${projectId} not found`, {
434434
status: HTTP_CODES?.NOT_FOUND,

api/src/services/org.service.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import logger from "../utils/logger.js";
88
import { HTTP_TEXTS, HTTP_CODES } from "../constants/index.js";
99
import { ExceptionFunction } from "../utils/custom-errors.utils.js";
1010
import { BadRequestError } from "../utils/custom-errors.utils.js";
11+
import ProjectModelLowdb from "../models/project-lowdb.js";
1112

1213
/**
1314
* Retrieves all stacks based on the provided request.
@@ -38,7 +39,6 @@ const getAllStacks = async (req: Request): Promise<LoginServiceType> => {
3839
},
3940
})
4041
);
41-
// console.info(err, res);
4242
if (err) {
4343
logger.error(
4444
getLogMessage(
@@ -63,11 +63,20 @@ const getAllStacks = async (req: Request): Promise<LoginServiceType> => {
6363
);
6464
});
6565
}
66-
// const locale:any[]
67-
// const locale = await getStackLocal(token_payload, stacks);
66+
await ProjectModelLowdb?.read?.();
67+
const testStacks = ProjectModelLowdb?.chain?.get?.("projects")?.flatMap?.("test_stacks")?.value?.();
68+
if (testStacks?.length > 0) {
69+
const filterStacks = [];
70+
for (const stack of stacks ?? []) {
71+
const isPresent = testStacks?.find?.((testStack: any) => testStack?.stackUid === stack?.api_key);
72+
if (isPresent === undefined) {
73+
filterStacks?.push(stack);
74+
}
75+
}
76+
stacks = filterStacks;
77+
}
6878
return {
6979
data: {
70-
// stacks: locale,
7180
stacks,
7281
},
7382
status: res.status,

0 commit comments

Comments
 (0)